Advertisement
Guest User

Untitled

a guest
Nov 4th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.91 KB | None | 0 0
  1.  
  2. Leszek Lesner
  3. 26 Oct (9 days ago)
  4.  
  5. to lubuntu-users, lubuntu-qa
  6. As some of you know there were some discussions on this mailinglist
  7. regarding zram and vm.swappiness.
  8. In this mail I want to write down all I know and learned about zram,
  9. vm.swappiness and its cooperation.
  10. This is intend as a help and a starting point for discussions for the
  11. next release of Lubuntu which will be an LTS.
  12.  
  13. I have to thank Mélodie for the discussions about vm.swappiness which
  14. made me dig deeper and deeper into it.
  15. And I have to say I was wrong at least partly :P
  16.  
  17. So before talking about ZRAM a small comprehensive introduction what it is.
  18. ZRAM is a compressed virtual swap device that lives in RAM. With this it
  19. is possible to use and store more memory
  20. that is physically available. It is used by Lubuntu in 13.10 by default.
  21.  
  22. What is vm.swappiness ? That is a far more complicated thing to explain.
  23. Simply speaking it controls the balance between swapping out runtime
  24. memory,
  25. as opposed to dropping pages from the system page cache. It can have a
  26. value from 0 to 100.
  27. A lower value means that it will try not to swap out page cache but keep
  28. it in memory.
  29. A high value means try to more aggressively swap out unused page memory.
  30.  
  31. A discussion was started if Lubuntu should lower down the vm.swappiness
  32. value or even set it down to 0
  33. to improve system performance and responsiveness.
  34. In my initial thought that I could give a universal answer on this topic
  35. but I was wrong.
  36. There a several scenarios we need to take a look at to see that there is
  37. not an universal answer on this.
  38.  
  39. == The classical situation (before 13.10): ==
  40. * RAM + SWAP (on HDD)
  41.  
  42. The RAM is backed up by a SWAP partition or SWAP file which is stored on
  43. a harddrive or ssd.
  44. As we all know disk i/o is a lot slower than RAM. On older machines and
  45. slower disks this could lead to noticable
  46. lags while swapping. But also on normal machines it is noticable. So for
  47. this scenario it would be nice to tell the
  48. kernel to avoid swapping as much as possible to avoid this bottleneck.
  49. A low vm.swappiness or even 0 is a good setting here as the kernel keeps
  50. filling the ram until it is almost full and then
  51. starts swapping out which could make the system laggy for a few seconds
  52. and while writing data to swap. So there is an unavoidable
  53. bottleneck here but there is also the possibility that with enough ram
  54. and a low memory footprint of the apps and desktop that
  55. the user will not reach the point of swapping.
  56.  
  57. == The new modern situation (with 13.10¹): ==
  58. * RAM + ZRAM
  59.  
  60. The RAM is backed up by a SWAP partition which is stored on a virtual
  61. compressed ram device. Under Lubuntu
  62. 13.10 this device can use half of the physically available memory.
  63. Writing and reading to and from RAM is a hell lot faster than to disk
  64. (even to an SSD). This means there is no bootlneck
  65. when the system swaps out to ZRAM with its default swappiness settings.
  66. Setting the swappiness lower here would make a change but
  67. a very minor only (noticable only via benchmarks). And lowering it here
  68. might lead to a faster reaching of the second
  69. bottleneck. So avoiding swapping and letting the RAM be filled and
  70. swapping late especially when RAM is very full will slow down the
  71. system and produces noticable lags. Those lags might be even harder in
  72. this case because the pages need to be compressed into RAM and
  73. when new pages need to be placed into RAM at the same time this might
  74. lead to a long cpu 100% compressing decompressing moving loop.
  75. Letting the swappiness at default (60) or even set it higher to 100
  76. would help avoid this bottleneck as swapping early would avoid
  77. RAM running full too fast.
  78. Whats the downside ?
  79. The CPU has to compress and decompress more often (don't worry even a
  80. Pentium 3 is very fast at it) and this causes more wake up times
  81. for the CPU. (perhaps a downside for those who want to save every little
  82. watt of there notebook battery)
  83.  
  84. == The combination of both situations : ==
  85. * RAM + ZRAM + SWAP (on HDD)
  86.  
  87. The RAM is backed up by ZRAM and a SWAP partition/file. This is an usual
  88. setting if you have very low RAM (like 256/512MB or 1 GB).
  89. By default ZRAM is as Swap device has a higher priority than the swap
  90. partition/file on hd. The swapping mechanism now works very clevely
  91. and swaps out first and by default early to zram first until its full.
  92. Then it will start swapping to hdd.
  93. This will lead us to our bottleneck nr.1 again but in contrast to the
  94. classical situation (scenario 1) it will get there a lot later :)
  95. So is there a possibility to avoid this bottleneck by changing the
  96. swappiness ? No not really.
  97. Swappiness low would lead too faster filling in memory which will lead
  98. (especially on low memory systems) lead to bootlneck 2 which tends
  99. to make the system a lot laggier than bottleneck 1.
  100. Setting swappiness higher here would be also only work until ZRAM is
  101. filled and than would lead to bottleneck 1 again.
  102. So overall I would recommend the default swappiness value here which
  103. tends to keep the system in a good balance between bottleneck 1 and 2.
  104.  
  105. So all in all when you see this scenarios I have to say that the default
  106. value of swappiness 60 makes the most sense as the default value
  107. of lubuntu. Changing it for the next release is something I would not
  108. recommend.
  109.  
  110. Seeing this one could ask wouldn't it be good to directly compress any
  111. data written to RAM ?
  112. And yes this is a possibility in the future with zcache (which is
  113. basically a backend for cleancache which is a whole framework around it).
  114. Zcache compresses every page cache written to RAM which will lead to
  115. more available free memory.
  116. And yes it is even possible to combine ZCache (Page Cache[Disk Cache and
  117. so on]) and ZRAM (Application memory) which
  118. could lead to even more available free RAM and might even make it
  119. possible to completely get rid of SWAP partitions/files on hdd.
  120. In the making is also frontswap which is basically speaking zram but
  121. without the necessity to give it a fixed size. So it can dynamically
  122. grow.
  123.  
  124. So the future looks very promising when it comes to low ram management
  125. and we are on a good way.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement