Author Topic: Swappiness value change to reduce wearing of the flash memory  (Read 3760 times)

Varti

  • Administrator
  • Hero Member
  • *****
  • Posts: 1269
    • View Profile
Swappiness value change to reduce wearing of the flash memory
« on: February 12, 2018, 04:49:42 am »
I'd like to share this interesting hint on how to reduce the use of the swap memory. Since this partition will be stored either on the internal flash or on a MicroSD card, reducing the number of writes to the memory will make it to last longer, and the OS should become more responsive too, though a lot of this depends on how often you'll use memory-intensive applications on your G:

https://www.howtoforge.com/tutorial/linux-swappiness/

I have reduced the value to 10 on my low-end laptop with 2GB of RAM, and I can confirm that it has become more responsive ever since. I know, I should buy some RAM for it anyway...

Varti
Planet Gemini PDA WiFi/LTE with Mediatek x27
SL-C1000 running Arch Linux ARM May2017, K30225 Wi-Fi CF Card, 64GB SDXC card
and many other Zauruses!

Murple2

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Swappiness value change to reduce wearing of the flash memory
« Reply #1 on: February 12, 2018, 08:02:28 am »
Great howto! Swap on flash is a really bad idea, less so on microsd but still bad. If you have your root and swap partition on the same microsd that could be very painful, even with some tuning.

My solution - don't use a swap partition. Seriously. I haven't used one since I last used a spinning HDD which was probably almost a decade ago. I haven't used one on any device, even ones with small amounts of ram (e.g. rpi). In that time I have only had to create a swap file once for a specific situation and I deleted it straight away afterwards.  Its very easy to bring up some swap on fly (sudo swapon <filename or partition>). Fair enough with 2gb on a lappy you may prefer to have one, but with 4gb on the Gemini I won't be bothering.

I know that this may be a controversial view, even in 2018, but if anyone is in doubt - try it.

Varti

  • Administrator
  • Hero Member
  • *****
  • Posts: 1269
    • View Profile
Swappiness value change to reduce wearing of the flash memory
« Reply #2 on: February 12, 2018, 10:36:23 am »
Quote from: Murple2
My solution - don't use a swap partition. Seriously. I haven't used one since I last used a spinning HDD which was probably almost a decade ago. I haven't used one on any device, even ones with small amounts of ram (e.g. rpi). In that time I have only had to create a swap file once for a specific situation and I deleted it straight away afterwards.  Its very easy to bring up some swap on fly (sudo swapon <filename or partition>). Fair enough with 2gb on a lappy you may prefer to have one, but with 4gb on the Gemini I won't be bothering.

I know that this may be a controversial view, even in 2018, but if anyone is in doubt - try it.
Interesting idea... my fear is that while e.g. browsing the web, you'd not know how much RAM  the website you're opening on a new tab will require, and you risk having the entire browser to be closed down due to lack of memory, together with all the tabs you have been working on. It might be interesting to set swappiness to 1, so that you'd usually not use the swap at all, but if you need it, you won't risk to have your application to be closed. The howto mentions freezes with such an extreme setting, though.

Varti
Planet Gemini PDA WiFi/LTE with Mediatek x27
SL-C1000 running Arch Linux ARM May2017, K30225 Wi-Fi CF Card, 64GB SDXC card
and many other Zauruses!

Murple2

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Swappiness value change to reduce wearing of the flash memory
« Reply #3 on: February 12, 2018, 12:05:53 pm »
Quote from: Varti
Quote from: Murple2
My solution - don't use a swap partition. Seriously. I haven't used one since I last used a spinning HDD which was probably almost a decade ago. I haven't used one on any device, even ones with small amounts of ram (e.g. rpi). In that time I have only had to create a swap file once for a specific situation and I deleted it straight away afterwards.  Its very easy to bring up some swap on fly (sudo swapon <filename or partition>). Fair enough with 2gb on a lappy you may prefer to have one, but with 4gb on the Gemini I won't be bothering.

I know that this may be a controversial view, even in 2018, but if anyone is in doubt - try it.
Interesting idea... my fear is that while e.g. browsing the web, you'd not know how much RAM  the website you're opening on a new tab will require, and you risk having the entire browser to be closed down due to lack of memory, together with all the tabs you have been working on. It might be interesting to set swappiness to 1, so that you'd usually not use the swap at all, but if you need it, you won't risk to have your application to be closed. The howto mentions freezes with such an extreme setting, though.

Varti

I did have this problem a while ago running chromium on an arm Chromebook (running Linux) with only 2gb ram but this was caused by a software bug where the pagesize was set incorrectly. Since this was fixed I've not had any problem with tabs crashing. But its up to you if you want loads of tabs open then perhaps you do want some swap. Or if you want to run a few virtual machines. Personally I would just spin up some swap when I need it but turns out I hardly ever do. Just please don't put it on the NAND. I will also say that if you plan to hibernate your PC you will need swap space as the contents of the RAM is written to it and read back when you switch back on. Suffice to say I never hibernate my computers, either switched off or suspended is enough for me.

PS modern browsers will kill individual tabs until you have enough ram again, the entire browser won't crash.

vader

  • Sr. Member
  • ****
  • Posts: 296
    • View Profile
Swappiness value change to reduce wearing of the flash memory
« Reply #4 on: February 12, 2018, 08:50:43 pm »
On any system with flash memory, I always turn swap off. If you really need extra ram, then create a compressed ram drive and use that as swap. It sound silly, but it can give you significantly more space, and it is very fast. If you have a 3G ram/1G compressed split, you may get 2-3G in swap, meaning 5-6G overall. It is a standard trick used in embedded systems.

Murple2

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Swappiness value change to reduce wearing of the flash memory
« Reply #5 on: February 13, 2018, 08:39:40 am »
Quote from: vader
On any system with flash memory, I always turn swap off. If you really need extra ram, then create a compressed ram drive and use that as swap. It sound silly, but it can give you significantly more space, and it is very fast. If you have a 3G ram/1G compressed split, you may get 2-3G in swap, meaning 5-6G overall. It is a standard trick used in embedded systems.

That's a great tip, I've not come across that before

Varti

  • Administrator
  • Hero Member
  • *****
  • Posts: 1269
    • View Profile
Swappiness value change to reduce wearing of the flash memory
« Reply #6 on: February 14, 2018, 03:22:40 am »
Quote from: Murple2
Quote from: vader
On any system with flash memory, I always turn swap off. If you really need extra ram, then create a compressed ram drive and use that as swap. It sound silly, but it can give you significantly more space, and it is very fast. If you have a 3G ram/1G compressed split, you may get 2-3G in swap, meaning 5-6G overall. It is a standard trick used in embedded systems.

That's a great tip, I've not come across that before
I second that, never though that the benefit of the increase in speed (RAM vs. flash memory) would be greater than the load introduced by the compression/decompression. Are you BTW using zram?
http://www.webupd8.org/2011/10/increased-p...linux-with.html

I guess that, in case there won't be Heterogeneous Multi-Processing support under Linux, zram (or similar) could be manually assigned to one of the X27 slower cores, as it would need to run all the time:
http://xmodulo.com/run-program-process-spe...ores-linux.html

See also:
https://www.oesf.org/forum/index.php?showtopic=34644

Varti
« Last Edit: February 14, 2018, 03:23:12 am by Varti »
Planet Gemini PDA WiFi/LTE with Mediatek x27
SL-C1000 running Arch Linux ARM May2017, K30225 Wi-Fi CF Card, 64GB SDXC card
and many other Zauruses!

Murple2

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Swappiness value change to reduce wearing of the flash memory
« Reply #7 on: February 14, 2018, 06:11:01 am »
Quote from: Varti
Quote from: Murple2
Quote from: vader
On any system with flash memory, I always turn swap off. If you really need extra ram, then create a compressed ram drive and use that as swap. It sound silly, but it can give you significantly more space, and it is very fast. If you have a 3G ram/1G compressed split, you may get 2-3G in swap, meaning 5-6G overall. It is a standard trick used in embedded systems.

That's a great tip, I've not come across that before
I second that, never though that the benefit of the increase in speed (RAM vs. flash memory) would be greater than the load introduced by the compression/decompression. Are you BTW using zram?
http://www.webupd8.org/2011/10/increased-p...linux-with.html

I guess that, in case there won't be Heterogeneous Multi-Processing support under Linux, zram (or similar) could be manually assigned to one of the X27 slower cores, as it would need to run all the time:
http://xmodulo.com/run-program-process-spe...ores-linux.html

See also:
https://www.oesf.org/forum/index.php?showtopic=34644

Varti

In regards to the HMP thing - in theory big.LITTLE support has been in the kernel since 3.10 (we are now at 4.15) and there is a scheduler called Global Task Scheduler that dealt with assigning stuff to the right core-clusters. I had one of the early devices around 2013 and the kernel support was shocking, but it now runs mainline kernel and utilises the cores as expected - but the power management isn't as good as it could be. These days it is a much more solid technology found on many ARM devices, with decent support in the kernel. I will say for the umpteenth time - this is precisely why kernel development needs to be focussed upstream.

Mediatek kernel stuck at whatever version they've chosen (maybe 4.4?) = possibly hacky kernel that just about delivers all the features of the SOC. This kernel then has to have all security updates and new features backported from now until the day that's its just such a mess and so antiquated that we can only run legacy software, if at all. It slowly breaks until most features don't work no more.

Mainline kernel = ongoing development and constantly improving support. All new security patches and feature developments are added automatically. Someone comes up with an awesome new scheduler that makes better use of big.LITTLE cores - does it need to he back ported onto a buggy kernel with hacky code that some mediatek developer thought was "good enough" in 2015? No, its just there and it will just work. Hurray our devices literally kick more ass every day they get older!

A lot, and I mean a lot, or work has gone into creating a multi-platform arm kernel over the past 10ish years and we now are at the stage where I can use the same kernel of any* of my arm devices, just like you can use a x86_64 kernel on live disk and boot on pretty much any Intel or amd machine.
*OK so armv7 kernel on arm7 devices, aarch64 kernel on aarch64 devices etc etc
« Last Edit: February 14, 2018, 09:10:25 am by Murple2 »

speculatrix

  • Administrator
  • Hero Member
  • *****
  • Posts: 3706
    • View Profile
Swappiness value change to reduce wearing of the flash memory
« Reply #8 on: February 14, 2018, 06:31:11 am »
Most of the time swapping is pointless, it's just too slow. If you need it, then you might have a memory leak, so that the idle/unused memory gradually gets written to disk since it won't be needed again.

On servers with large amounts of memory, I rarely give them more than 1GB of swap, and then it's only as a "cushion" so that I can see if free memory ever gets really low, low enough to cause swapping, and then I can do something about it.

On a laptop I've generally allocated as much swap as physical RAM for hibernation. I've always assumed that if you want to hibernate (suspend to disk) you needed a swap partition, but it seems you don't:

https://wiki.debian.org/Hibernation/Hiberna..._Swap_Partition
Gemini 4G/Wi-Fi owner, formerly zaurus C3100 and 860 owner; also owner of an HTC Doubleshot, a Zaurus-like phone.

Murple2

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Swappiness value change to reduce wearing of the flash memory
« Reply #9 on: February 14, 2018, 09:08:29 am »
Quote from: speculatrix
Most of the time swapping is pointless, it's just too slow. If you need it, then you might have a memory leak, so that the idle/unused memory gradually gets written to disk since it won't be needed again.

On servers with large amounts of memory, I rarely give them more than 1GB of swap, and then it's only as a "cushion" so that I can see if free memory ever gets really low, low enough to cause swapping, and then I can do something about it.

On a laptop I've generally allocated as much swap as physical RAM for hibernation. I've always assumed that if you want to hibernate (suspend to disk) you needed a swap partition, but it seems you don't:

https://wiki.debian.org/Hibernation/Hiberna..._Swap_Partition

For hibernation you don't need a swap partition, but you still need some form of swap space (in the case of the link you posted they use a swap file)