[MODULE] Swap Torpedo - run faster and more reliably

Search This thread

EarlyMon

Senior Member
Jun 23, 2010
1,685
1,291
Using compressed RAM for swap on a phone with enough RAM in the first place sucks.

Let's take a look using RAM Truth from the Play Store -

Screenshot_20180317-044913.jpg Screenshot_20180317-045022.jpg

It makes no sense to use 500 MB of swap with 3 GB RAM free!

If yours already looks like the second picture, 0 swap, you're done, you don't need this module.

(Note - we're going to update RAM Truth - the swap type used on the honor is zram.)

But if you need to get rid of swap, here you go -

Swap Torpedo - A Magisk Module

Universal compressed-memory swap (zram, etc etc) destroyer - run faster and more reliably!

By EarlyMon - version 1.1

Swap is a way to expand your RAM using clever software and some unused storage space. You see it a lot in Android as zram or vmswap, that is, compressed-memory swap. Storage-based swap is fine, compressed-memory swap - not so much.

Swap is a fine thing for desktops with sufficient resources and for Android devices really hampered with too little ram.

On Android it was originally intended for devices with less than 1 GB RAM.

If you have an Android One or another small-memory device, this is NOT the module for you.

But if you have 2 GB of RAM or more, you want this.

Do you suffer from lag, random UI pauses, apps not running correctly and consistently, and background apps failing even when you have them marked for protection? Do you have to reboot every day or so to restore speed?

All of that is almost always caused by having swap implemented and the Swap Torpedo fixes it.

Manufacturers, including Google, have fallen in love with compressed-memory swap because it allows your Android to synthetically appear better at multitasking. In reality, it ruins multitasking.

Why? For large memory devices you want the swap space to be at minimum the square root of your RAM size and ideally the same size as, or up to double the size of, your RAM.

The problem is that they don't use enough space because they can't - they're basically using a compressed RAM disk as a swap partition.

If you think about that, it will raise the right questions.

Does it make sense to use RAM for something other than apps and the operating system? Does it make sense to constantly have the operating system pause while it shuffles and reorganizes your RAM? Does it make sense for you to wait on everything while various pieces of RAM are getting zipped and unzipped to support this scheme? Does it make sense to do all of that incorrectly in the first place because you can't get enough swap space to properly support multitasking, by design?

No. No it does not.

Swap Torpedo is the answer.

I designed it to be universal for any Android that Magisk version 15 and above supports. If you're not using swap, or if you installed your own swap solution that writes to a special file in storage, Swap Torpedo harmlessly does nothing.

Verify your swap situation with RAM Truth available on the Play Store. It's free and it will never spy on you or ask for special permissions.

Donations are humbly and gratefully received at [email protected] but not expected. My personal reward is knowing that I helped and you are having a better day now.

This module was developed entirely on an honor View 10.


Notes -

Some phones may need a few minutes after boot to clean up swap/zram - not all, just some - and that's completely normal

May not work on all devices but will probably work for you - ask here for help


Changelog -

(early change) 2018 April 27

Increased initial maximum wait time to 60 seconds. Your additional boot time will be about 3 seconds or so, usually less.

v1.1 - 2018 April 1 - functional improvement

Detached background processing, added Pixel and similar support.
Expanded zram command sequence for devices requiring stricter adherence to the rtfm.
Waits up to 45 seconds for swap to activate, expands support for non-flagship phones.

v1.0 - 2018 March 17 - initial release


Download -
 

Attachments

  • Swap_Torpedo-v1.1.zip
    11.2 KB · Views: 40,992
Last edited:

EarlyMon

Senior Member
Jun 23, 2010
1,685
1,291
Beta versions are exactly that so you may have trouble with Magisk 16.4 for example (or you may be ok) - please let me know, thanks!

Check out the v1.1 release at bottom of the first post above

Open Source -

https://github.com/Magisk-Modules-Repo/swap-torpedo

Just because it's open source does not mean that you ought to avoid giving me a few million dollars if you happen to be a billionaire. Let's face it, Swap Torpedo just made your life a lot better than the last guy you gave serious money to, and plus you'll have me in your corner verifying that regular billionaires such as yourself do too root and use Magisk. Trust me, the other billionaires will be so jealous they won't know whether to die or go bowling.

I hope that this clarifies the importance of open source software once and for all.

Thanks and Credits -

Nitin Gupta because real information comes in Courier, plain text or it didn't happen

@topjohnwu because in my mind I was totally going to invent Magisk first... OK don't be insane, I'm just kidding - Doctor Wu by Steely Dan is a great song and I'm not sure but I don't think it has anything to do with Magisk, no one really knows for sure - Magisk is great, mmmkay, thanks John

Special thanks to all of the heroes named by @topjohnwu and the unnamed ones as well. My people have an ancient saying that applies here - Without you, we'd be screwed!

Thanks to everyone in the thread who worked with me to help make Swap Torpedo better

Thanks to every one of you using the Swap Torpedo - I get that you get it

Finally, I thank my wife - she had nothing to do with Swap Torpedo but probably someday she'll say that I'm not grateful and I'm going to show her this special credit - I'm sure that will go really well for me, how about you?

Other Stuff -

Official module, 2018-3-26.

There's a shortcoming in RAM Truth that throws off the illustration in the first post - it misidentifies the swap type on Oreo and when vmswap is used. We're looking into that. If it says that your Android is using swap and you didn't put it there, Swap Torpedo is for you.

Secrets About Swap Torpedo -

Runs swapoff on every /dev entry in /proc/swap(s) during late boot. Making it universal may be harder than you think. Or not, I couldn't say.

That's it. Nothing else is left running from Swap Torpedo once the payload is delivered, nothing else is changed.

Your Android runs fewer processes and is slimmer and trimmer if you needed it (and you probably do) thanks to Swap Torpedo.

Uninstall the module and it will be as if it was never there. Swap Torpedo targets each boot session.

No more, no less.

A Quote -

Use whatever works!

Swap Torpedo has no pixie dust nor do I expect it to ever get any.

I've had to redevelop this solution for years, every time I or a friend got a new phone saddled with swap.

I made this module so I could stop reinventing the wheel and so that it would be easier for others to enjoy the benefits.

If you have something already that gets rid of swap, or if the Swap Torpedo doesn't work for you, definitely use the other instead.

Check out "EX Kernel Manager"

https://play.google.com/store/apps/details?id=flar2.exkernelmanager

Check out "Kernel Adiutor (ROOT)"

https://play.google.com/store/apps/details?id=com.grarak.kerneladiutor
 
Last edited:
M

Megan

Guest
Do I need this if I have Adaptive LMK and ZRAM disabled?

Sent from my HTC 10 using XDA Labs
 

problemathic

Senior Member
Jan 14, 2018
301
101
Naval
hoping this project grows. will watch this till end :)

---------- Post added at 03:29 PM ---------- Previous post was at 03:23 PM ----------

i got another phone with 500mb ram. This module will work as it says originally intended for 1gb ram below.
 

lanserffnt

Member
Mar 8, 2011
23
2
It runing ??

How to check this module is works.
 

Attachments

  • Screenshot_20180322-184203.jpg
    Screenshot_20180322-184203.jpg
    175.3 KB · Views: 7,825

Top Liked Posts

  • There are no posts matching your filters.
  • 125
    Using compressed RAM for swap on a phone with enough RAM in the first place sucks.

    Let's take a look using RAM Truth from the Play Store -

    Screenshot_20180317-044913.jpg Screenshot_20180317-045022.jpg

    It makes no sense to use 500 MB of swap with 3 GB RAM free!

    If yours already looks like the second picture, 0 swap, you're done, you don't need this module.

    (Note - we're going to update RAM Truth - the swap type used on the honor is zram.)

    But if you need to get rid of swap, here you go -

    Swap Torpedo - A Magisk Module

    Universal compressed-memory swap (zram, etc etc) destroyer - run faster and more reliably!

    By EarlyMon - version 1.1

    Swap is a way to expand your RAM using clever software and some unused storage space. You see it a lot in Android as zram or vmswap, that is, compressed-memory swap. Storage-based swap is fine, compressed-memory swap - not so much.

    Swap is a fine thing for desktops with sufficient resources and for Android devices really hampered with too little ram.

    On Android it was originally intended for devices with less than 1 GB RAM.

    If you have an Android One or another small-memory device, this is NOT the module for you.

    But if you have 2 GB of RAM or more, you want this.

    Do you suffer from lag, random UI pauses, apps not running correctly and consistently, and background apps failing even when you have them marked for protection? Do you have to reboot every day or so to restore speed?

    All of that is almost always caused by having swap implemented and the Swap Torpedo fixes it.

    Manufacturers, including Google, have fallen in love with compressed-memory swap because it allows your Android to synthetically appear better at multitasking. In reality, it ruins multitasking.

    Why? For large memory devices you want the swap space to be at minimum the square root of your RAM size and ideally the same size as, or up to double the size of, your RAM.

    The problem is that they don't use enough space because they can't - they're basically using a compressed RAM disk as a swap partition.

    If you think about that, it will raise the right questions.

    Does it make sense to use RAM for something other than apps and the operating system? Does it make sense to constantly have the operating system pause while it shuffles and reorganizes your RAM? Does it make sense for you to wait on everything while various pieces of RAM are getting zipped and unzipped to support this scheme? Does it make sense to do all of that incorrectly in the first place because you can't get enough swap space to properly support multitasking, by design?

    No. No it does not.

    Swap Torpedo is the answer.

    I designed it to be universal for any Android that Magisk version 15 and above supports. If you're not using swap, or if you installed your own swap solution that writes to a special file in storage, Swap Torpedo harmlessly does nothing.

    Verify your swap situation with RAM Truth available on the Play Store. It's free and it will never spy on you or ask for special permissions.

    Donations are humbly and gratefully received at [email protected] but not expected. My personal reward is knowing that I helped and you are having a better day now.

    This module was developed entirely on an honor View 10.


    Notes -

    Some phones may need a few minutes after boot to clean up swap/zram - not all, just some - and that's completely normal

    May not work on all devices but will probably work for you - ask here for help


    Changelog -

    (early change) 2018 April 27

    Increased initial maximum wait time to 60 seconds. Your additional boot time will be about 3 seconds or so, usually less.

    v1.1 - 2018 April 1 - functional improvement

    Detached background processing, added Pixel and similar support.
    Expanded zram command sequence for devices requiring stricter adherence to the rtfm.
    Waits up to 45 seconds for swap to activate, expands support for non-flagship phones.

    v1.0 - 2018 March 17 - initial release


    Download -
    24
    Beta versions are exactly that so you may have trouble with Magisk 16.4 for example (or you may be ok) - please let me know, thanks!

    Check out the v1.1 release at bottom of the first post above

    Open Source -

    https://github.com/Magisk-Modules-Repo/swap-torpedo

    Just because it's open source does not mean that you ought to avoid giving me a few million dollars if you happen to be a billionaire. Let's face it, Swap Torpedo just made your life a lot better than the last guy you gave serious money to, and plus you'll have me in your corner verifying that regular billionaires such as yourself do too root and use Magisk. Trust me, the other billionaires will be so jealous they won't know whether to die or go bowling.

    I hope that this clarifies the importance of open source software once and for all.

    Thanks and Credits -

    Nitin Gupta because real information comes in Courier, plain text or it didn't happen

    @topjohnwu because in my mind I was totally going to invent Magisk first... OK don't be insane, I'm just kidding - Doctor Wu by Steely Dan is a great song and I'm not sure but I don't think it has anything to do with Magisk, no one really knows for sure - Magisk is great, mmmkay, thanks John

    Special thanks to all of the heroes named by @topjohnwu and the unnamed ones as well. My people have an ancient saying that applies here - Without you, we'd be screwed!

    Thanks to everyone in the thread who worked with me to help make Swap Torpedo better

    Thanks to every one of you using the Swap Torpedo - I get that you get it

    Finally, I thank my wife - she had nothing to do with Swap Torpedo but probably someday she'll say that I'm not grateful and I'm going to show her this special credit - I'm sure that will go really well for me, how about you?

    Other Stuff -

    Official module, 2018-3-26.

    There's a shortcoming in RAM Truth that throws off the illustration in the first post - it misidentifies the swap type on Oreo and when vmswap is used. We're looking into that. If it says that your Android is using swap and you didn't put it there, Swap Torpedo is for you.

    Secrets About Swap Torpedo -

    Runs swapoff on every /dev entry in /proc/swap(s) during late boot. Making it universal may be harder than you think. Or not, I couldn't say.

    That's it. Nothing else is left running from Swap Torpedo once the payload is delivered, nothing else is changed.

    Your Android runs fewer processes and is slimmer and trimmer if you needed it (and you probably do) thanks to Swap Torpedo.

    Uninstall the module and it will be as if it was never there. Swap Torpedo targets each boot session.

    No more, no less.

    A Quote -

    Use whatever works!

    Swap Torpedo has no pixie dust nor do I expect it to ever get any.

    I've had to redevelop this solution for years, every time I or a friend got a new phone saddled with swap.

    I made this module so I could stop reinventing the wheel and so that it would be easier for others to enjoy the benefits.

    If you have something already that gets rid of swap, or if the Swap Torpedo doesn't work for you, definitely use the other instead.

    Check out "EX Kernel Manager"

    https://play.google.com/store/apps/details?id=flar2.exkernelmanager

    Check out "Kernel Adiutor (ROOT)"

    https://play.google.com/store/apps/details?id=com.grarak.kerneladiutor
    23
    Swap Torpedo don't seem to be working even after 3 days of installation after fresh rom flash.. Device is a Moto G3 Codename Osprey..

    The module has been updated long-long time ago and never been officially updated to the latest module format (v20.3 at the moment) to comply with the developer guide.

    So - since there are ppl. still want to use it (and I do, too) - I modified the module to comply with the latest developer guide available at this moment.
    The script itself is untouched.
    Works for me correctly.
    Please try and let me know whether it works for you, too.


    PS: basically the script itself can work as a simple init.d script if you don't want to use the module.
    Grab the zip, unzip the service.sh from the zip and put it to your phone somewhere, give it a name that reflects what it does (like swaptorpedo.sh or zram_disabler.sh or something) and install an init.d script manager app and run it with root at every boot or if your ROM is actually supporting init.d scripts just put it to the right directory. Some kernel manager apps like Franco Kernel Manager, EX Kernel Manager or Kernel Adiutor (or forks of them) have boot time script running capabilities, too. If you have Magisk but don't want to use the module (for whatever reason..) put the script to /data/adb/post-fs-data.d and|or /data/adb/service.d directory and give it a permission like 777 (read+write+execute..) and Magisk will run it at every boot. There are tons of possibilities. Have fun.
    16
    @EarlyMon sorry but i still don't understand even after read first post.So you are saying that swap/zram in device that had more than 512 mb ram is useless?Say i have kenzo 2gb variant so swap/zram is bad for my phone?

    Quote from the op: "But if you have 2 GB of RAM or more, you want this." I think if you have less than 2 GB you need swap, else your system might run unstable or even unusuable. But that's just my guess.

    I'm going to give the technical answer and then I'm going to give the easy answer. It's OK if you want to skip down to the easy answer. I'm not going to give a test on the technical part. ;) :)

    Technical Answer

    Running out of memory is not desirable but it is unavoidable - no one has an infinite amount of RAM. Operating systems deal with that by what we call memory management. Android inherits Linux memory management and even improves on it. Memory management is too sophisticated to explain in a post but we can cover the important part - what does "not enough memory" mean and what happens when there is not enough memory?

    On Android, all you really need is to be happy running the app you're looking at at the time (right now, it's to read this) and essential apps running in the background, behind the scenes, under the hood. While you are reading this, your music player should still work and you should still be able to get messages and receive phone calls. That implies a whole lot of technical details like hardware and network management but let's just lump it all together and say that's part of our "app point of view." It's true enough and not wrong. Let's add some other expectations - maybe you want to also download a movie for later right now while you are reading this. That's through an app in the background. Maybe something else you find critical.

    That's multitasking. Anything beyond the essential is a luxury and often desirable if you can afford a phone with more RAM to get it.

    What happens when you run out of memory? Something has to go. And essential services cannot just up and disappear so memory management software kicks in. It winds things down in the background in stages. If higher priority it can keep the last known state recorded in storage so that you can pick up where you left off when you return to it.

    Android has been doing that since the beginning.

    In KitKat, Google introduced zram support. It was intended as a safety net for phones with little RAM. Remember, 2 GB was a deluxe feature in those days. The purpose of zram was to carve out some of the RAM and use it like a FAST storage disk to extend part of the working area just for memory management. And it's possible because it uses compression and it is perfectly OK for you to think about that just like using WinZip for every bit you put in or take out of that area. (It uses something better for the job than WinZip but for the purpose of understanding, don't worry about the small details. The WinZip analogy is perfectly fine.)

    With computers as with so many things, we have a good rule called TANSTAAFL - there ain't no such thing as a free lunch.

    The TANSTAAFL with zram is that at minimum, it will slow everything down - that constant zipping and unzipping doesn't do itself. There's no dispute about this and I can provide references to Google saying so too (along with everyone else in the operating system industry about zram).

    And my experience, shared with many others over the years, is that the other part of the zram TANSTAAFL is that you can and will get other performance degradations as I described in the first post.

    To those who would argue that Google knows more about this than me - OK. To a small extent I accept that is true, at least I hope so. But let's also remember that this is the same company who adds stickers instead of fixing messaging and who can't figure out why most everyone hates the basic changes they put into Wear 2.0, and I have a long list of other examples.

    Zram on Android is a last resort when you really don't have enough memory and (according to Google) you've done everything else like adjust your out of memory limits (if you must).

    There is NO excuse for it on a phone with enough memory.

    But Google went and put it on the 4 GB Pixel! So it is too good and how small is small must have changed?

    That's what the other manufacturers insist on and I know it for a fact because I've spoken to R&D with several of them - Google does it, shut up, it's good!

    Except no it's not. A proportionally small zram will get sucked up and used by the kernel to speed boot up and after that, you're on your own. Everyone with a high end phone who reboots it every day or two to restore speed, and that's a lot of people, including Nexus and Pixel owners, are simply clearing up the fragmented zram that is running slower and slower.

    As a last resort, on a small memory device, try zram and see if you like it.

    Personally I have not been able to stand it on anything with 2 GB or above.

    Easy Answer

    I didn't forget, here's the easy answer. :)

    I can go on for pages with my technical opinion but I'm not perfect and every once in a GREAT while, someone comes along with a use case that says, ok, this time zram is ok.

    And the easy answer is this module.

    It costs nothing to try and it will not damage anything.

    If you have any doubt, try it. If you do not notice a difference, try it for a few days without rebooting.

    Go back and forth if you want. That's harmless.

    I predict that you will see a positive difference.

    And some of you may notice no difference. Leave it in place. Your CPUs will be silently thanking you for lowering the workload.

    If it seems better with zram then stop and do what Google recommends - try adjusting your out of memory (OOM) limits first. There are many apps that can help you with that.

    And only if that doesn't help and you're sure that you are not the victim of a bad app - then go ahead and uninstall the module.

    Use zram as a last resort, just like it was intended to be.

    And no matter what, do NOT use task killers or RAM cleaners.

    Android knows what to do. That crap just confuses it.
    10
    wow...feels like using a bunch of booster tweaks , very2 smooth n fast .
    only first 5 minute i've had random fc when open apk...after that it start working flawlessly...very good job dev, thx a lot :laugh::cowboy:
    Leave zram enabled, set swappiness to 10; get same responsiveness benefits without occational FCs and other side effects. Best of both worlds. :)