[MODULE] Swap Torpedo - run faster and more reliably

Search This thread

EarlyMon

Senior Member
Jun 23, 2010
1,685
1,281
What should it show in terminal?
I am using it on LG G4 v29 (Nougat beta) and it doesn't show anything when I write "cat /proc/swap*". :/

If RAM Truth shows more than zero swap total, and you issued the command as root, it should be similar to the picture in post number 10.

If RAM Truth shows zero swap total, you don't need this module.
 

Telperion

Senior Member
Feb 20, 2011
652
328
That's unusual. May I ask what other modules you are using and what other modifications, if any? And you used the one in the first post?
Correct. Adblock, Greenify, Busybox, MagiskHide Props Config. My zram device is at /dev/block/zram0.

Update: I turned swap off from a root shell, it took a minute per 100MB of data being held in swap. So if all 500MB were filled, it would take 5 minutes. I can't speak to whether that's why it's hanging my boot or not. I tried echoing 1 to /sys/block/zram0/reset but it didn't empty the block device.
 
Last edited:
  • Like
Reactions: EarlyMon

theduke7

Senior Member
Apr 8, 2011
1,604
1,109
Cairo
It seems either not working or not needed on OnePlus 3, I attached a screen, it shows the same thing either the module is installed or not
 

Attachments

  • Screenshot_20180322-221640.png
    Screenshot_20180322-221640.png
    42 KB · Views: 1,555
  • Like
Reactions: EarlyMon

EarlyMon

Senior Member
Jun 23, 2010
1,685
1,281
Correct. Adblock, Greenify, Busybox, MagiskHide Props Config. My zram device is at /dev/block/zram0.

Update: I turned swap off from a root shell, it took a minute per 100MB of data being held in swap. So if all 500MB were filled, it would take 5 minutes. I can't speak to whether that's why it's hanging my boot or not. I tried echoing 1 to /sys/block/zram0/reset but it didn't empty the block device.
You have a phone that treats the timing of using zram just like a desktop. :)

If zram had filled completely, it could have taken hours to clean up.

Magisk has places for scripts to run right after the file systems are mounted and data is available, and even later than that in the boot up sequence.

I expected to use the first one but during development I discovered that my device and others needed the second one.

Yours needs it earlier.

I've modified the Swap Torpedo to attempt both. If the first one succeeds quickly, the second one will see that there's nothing to do and not waste your time. Others won't notice a difference because the first one will exit gracefully if the system isn't ready for it yet.

Please let me know if it works for you.

(redacted)

If this does not work then you will need a custom modification for your phone, we're at the limits of what Magisk can do.

Let me know if that's required and if you are interested and I can give you pointers for that.

It seems either not working or not needed on OnePlus 3, I attached a screen, it shows the same thing either the module is installed or not
Congratulations, you don't need it.

Somebody ought to mention RAM Truth up in here. ;) :D
 
Last edited:

EarlyMon

Senior Member
Jun 23, 2010
1,685
1,281
This is what I get on lineage 14.1.
Please show me what it says in a terminal when you do the following, thanks -
Code:
ls -l /system/bin/swapoff
In each case those are lowercase Ls and there's a space after the s and before the dash.

And as root -
Code:
cat /proc/swap*
 
Last edited:

frenzyboi

Senior Member
May 11, 2012
870
764
Before installation, Ram truth shows 500mb swap total.
After installation, it changes to 0mb swap total. Am I doing something wrong? May I know the expected output?

On Mi 5 LOS 14.1
 
  • Like
Reactions: EarlyMon

EarlyMon

Senior Member
Jun 23, 2010
1,685
1,281
Before installation, Ram truth shows 500mb swap total.
After installation, it changes to 0mb swap total. Am I doing something wrong? May I know the expected output?

On Mi 5 LOS 14.1

That's exactly the expected change.

You ought to experience better responsiveness and no degradation in performance.

If you don't like it, uninstall it and it will be as if it was never there - Swap Torpedo does NOT make any permanent changes to your system.

I think that you'll want to keep it. ;) :)
 

EarlyMon

Senior Member
Jun 23, 2010
1,685
1,281
So that's two cases of LOS 14.1 - one worked, one didn't.

If there's a kernel deficiency keeping it from working, I don't know if there's much I'll be able to do. :(
 

Telperion

Senior Member
Feb 20, 2011
652
328
If this does not work then you will need a custom modification for your phone, we're at the limits of what Magisk can do. Let me know if that's required and if you are interested and I can give you pointers for that.
Phone boots now with that zip, but zram0 block device still exists. I can try anything, just let me know what to do.
 
  • Like
Reactions: EarlyMon
P

PixelChris95

Guest
It's working for me on lineageos 15.1.
 

Attachments

  • Screenshot_RAM_Truth_20180323-151105.png
    Screenshot_RAM_Truth_20180323-151105.png
    183.6 KB · Views: 981
  • Screenshot_RAM_Truth_20180323-151612.png
    Screenshot_RAM_Truth_20180323-151612.png
    177.8 KB · Views: 983

EarlyMon

Senior Member
Jun 23, 2010
1,685
1,281
Phone boots now with that zip, but zram0 block device still exists. I can try anything, just let me know what to do.
Ok - Magisk is a systemless mod, it doesn't affect the actual system.

This mod DOES affect the system.

Make a nandroid backup in TWRP first.

Find where your dot-rc init scripts are - mine are in /system/etc/init as shown below -

Screenshot_20180323-101300.jpg

Unzip the following file, you will get a text file named noswap.sh and that's it.

View attachment noswap.zip *** NOT A MAGISK ZIP FILE

Use a file manager and copy noswap.sh to the dot-rc init files location.

Note the location of the dot-rc init files and substitute it below, in a terminal as root -

Code:
cd dot-rc-init-files-location
chown root:root noswap.sh
chmod 755 noswap.sh

You're going to lose Google Pay and anything else that insists on a clean system image.

War could break out on Mars and you may need to restore your nandroid backup. I'm not responsible for any of that or anything else that goes wrong.

If that doesn't work then the only option will be to prevent swap from ever getting turned on in the first place. In that case, send me a private message if you seriously want to proceed with that. ;)

PS - Pixels have the whole A/B partition mirror going on - I just remembered that. You may have to repeat this for each partition. I can't help with that.

Do verify that you booted the modified /system by looking for the noswap.sh file.
 
Last edited:
  • Like
Reactions: Wiciaki

Top Liked Posts

  • There are no posts matching your filters.
  • 117
    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 -
    23
    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
    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.
    13
    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.
    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. :)
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone