Comments on: How Much Swap? https://pthree.org/2012/10/18/how-much-swap/ Linux. GNU. Freedom. Tue, 31 Oct 2017 18:00:46 +0000 hourly 1 https://wordpress.org/?v=5.0-alpha-42127 By: John https://pthree.org/2012/10/18/how-much-swap/#comment-117070 Tue, 23 Oct 2012 10:14:05 +0000 http://pthree.org/?p=2547#comment-117070 For desktops 1-2GB swap is fine, for laptops I do RAM + 10% to allow for hibernation and its overheads.

As for general partitioning, I always strongly recommend a separate /home so that you can do a full OS reinstall without worrying about backup/restore of your user data, stops you filling / with user data and running out of system space, and it makes backing up just the home partition easier. I also do a separate /tmp as I have seen rouge processes fill up /tmp and I want to limit the damage that causes by not filling up /. For /tmp I set it to 5GB as DVD burning software tends to create temporary iso files in /tmp, but others may prefer to just reconfigure the burning software. Another reason for a separate /tmp is to make it a ram drive to improve speed if you have sufficient memory, but you can do that later without creating a partition first. That means you need to decide on a size for /, which I set to 30GB for my personal machines as I have a lot of dev files installed, but your average desktop probably only needs 10GB, or 20GB for future-proof.

]]>
By: analogtek https://pthree.org/2012/10/18/how-much-swap/#comment-117067 Sat, 20 Oct 2012 23:03:24 +0000 http://pthree.org/?p=2547#comment-117067 This is a very good paper. But what of the "swappiness" factor and how it should be set.

]]>
By: einheit https://pthree.org/2012/10/18/how-much-swap/#comment-117058 Fri, 19 Oct 2012 21:17:02 +0000 http://pthree.org/?p=2547#comment-117058 I agree the old school rules about swap no longer apply. The real requirement for swap is the size of your working set minus the amount of physical memory, if the difference is > 0

These days I tend to put a 4 GB swap partition on servers regardless of the amount of RAM. In the worst case, swap files could be added, but it's best to have enough RAM.

]]>
By: Pedro https://pthree.org/2012/10/18/how-much-swap/#comment-117052 Thu, 18 Oct 2012 20:27:26 +0000 http://pthree.org/?p=2547#comment-117052 Well, today is almost impossible to say how much swap a user must separate. I agree that for simple users, I mean, users that do not use the computer for heavy things, 1-2 GB of swap is more than enough
for today's computers/laptops.

However, some situations really needs more swap. I have a laptop with 8GB RAM (max possible) and 32 GB of swap and some times
I have to use a usb flash drive to increse it.

I work with numerical simulation and it is very demanding.

]]>
By: Fitzcarraldo https://pthree.org/2012/10/18/how-much-swap/#comment-117051 Thu, 18 Oct 2012 19:53:21 +0000 http://pthree.org/?p=2547#comment-117051 Back in 2010 I did a little experiment to see what TuxOnIce does.

Here were my RAM and swap sizes in bytes:

# free -bt
total used free shared buffers cached
Mem: 4142669824 2399014912 1743654912 0 175312896 1153126400
-/+ buffers/cache: 1070575616 3072094208
Swap: 4293558272 0 4293558272
Total: 8436228096 2399014912 6037213184

My (2.6.36) kernel config was as follows w.r.t. LZO compression:

$ cat /usr/src/linux/.config | grep LZO
CONFIG_HAVE_KERNEL_LZO=y
# CONFIG_KERNEL_LZO is not set <---- Kernel Compression Mode was selected to be LZMA rather than LZO
CONFIG_RD_LZO=y
CONFIG_JFFS2_LZO=y
# CONFIG_JFFS2_CMODE_FAVOURLZO is not set
CONFIG_UBIFS_FS_LZO=y
CONFIG_SQUASHFS_LZO=y
CONFIG_CRYPTO_LZO=m
CONFIG_LZO_COMPRESS=m
CONFIG_LZO_DECOMPRESS=y
CONFIG_DECOMPRESS_LZO=y

and TuxOnIce did not work when I tried to hibernate my laptop:

Dec 29 12:01:06 meshedgedx kernel: [ 272.829994] TuxOnIce: Failed to initialise the lzo compression transform.
Dec 29 12:01:06 meshedgedx kernel: [ 272.829995] Failed to initialise compression algorithm.
Dec 29 12:01:06 meshedgedx kernel: [ 272.829996] Continuing without compressing the image.
.
.
.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908327] TuxOnIce debugging info:
Dec 29 12:01:06 meshedgedx kernel: [ 316.908330] - TuxOnIce core : 3.2-rc2
Dec 29 12:01:06 meshedgedx kernel: [ 316.908331] - Kernel Version : 2.6.36-sabayon
Dec 29 12:01:06 meshedgedx kernel: [ 316.908333] - Compiler vers. : 4.4
Dec 29 12:01:06 meshedgedx kernel: [ 316.908335] - Attempt number : 1
Dec 29 12:01:06 meshedgedx kernel: [ 316.908336] - Parameters : 32777 667648 0 0 0 5
Dec 29 12:01:06 meshedgedx kernel: [ 316.908338] - Overall expected compression percentage: 0.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908340] - Checksum method is 'md4'.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908344] 0 pages resaved in atomic copy.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908345] - Block I/O active.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908346] Used 0 pages from swap on /dev/sda5.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908347] - Max outstanding reads 1052. Max writes 20353.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908348] Memory_needed: 1024 x (4096 + 344 + 112) = 4661248 bytes.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908349] Free mem throttle point reached 0.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908350] - Swap Allocator enabled.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908351] Swap available for image: 1048232 pages.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908352] - File Allocator active.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908352] Storage available for image: 0 pages.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908353] - I/O speed: Write 54180 KB/s.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908354] - Extra pages : 5179 used/500.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908355] - Result : Hibernation was aborted.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908356] : Insufficient storage was available.
Dec 29 12:01:06 meshedgedx kernel: [ 316.908357] : I/O errors were encountered.

As you can see above, with LZO compression configured to be a module instead of in-kernel, TuxOnIce did not compress RAM, and the 4293558272 bytes of swap was insufficient for hibernation when I have 4142669824 bytes RAM (of which 2399014912 was in use). So I used the kernel configuration options specified in the Gentoo Wiki article on TuxOnIce, and rebuilt my kernel to perform in-kernel LZO compression:

$ cat /usr/src/linux/.config | grep LZO
CONFIG_HAVE_KERNEL_LZO=y
# CONFIG_KERNEL_LZO is not set <---- I left Kernel Compression Mode as LZMA rather than LZO
CONFIG_RD_LZO=y
CONFIG_JFFS2_LZO=y
# CONFIG_JFFS2_CMODE_FAVOURLZO is not set
CONFIG_UBIFS_FS_LZO=y
CONFIG_SQUASHFS_LZO=y
CONFIG_CRYPTO_LZO=y
CONFIG_LZO_COMPRESS=y
CONFIG_LZO_DECOMPRESS=y
CONFIG_DECOMPRESS_LZO=y

and then the laptop hibernates successfully:

Dec 29 15:22:45 meshedgedx kernel: [ 1205.711101] TuxOnIce debugging info:
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711102] - TuxOnIce core : 3.2-rc2
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711103] - Kernel Version : 2.6.36-sabayon
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711103] - Compiler vers. : 4.4
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711104] - Attempt number : 1
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711104] - Parameters : 0 667648 0 0 0 5
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711105] - Overall expected compression percentage: 0.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711105] - Checksum method is 'md4'.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711106] 0 pages resaved in atomic copy.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711107] - Compressor is 'lzo'.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711107] Compressed 2180071424 bytes into 914681193 (58 percent compression).
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711108] - Block I/O active.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711108] Used 225238 pages from swap on /dev/sda5.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711109] - Max outstanding reads 1338. Max writes 10377.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711110] Memory_needed: 1024 x (4096 + 344 + 112) = 4661248 bytes.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711110] Free mem throttle point reached 0.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711111] - Swap Allocator enabled.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711112] Swap available for image: 1048232 pages.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711112] - File Allocator active.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711113] Storage available for image: 0 pages.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711113] - I/O speed: Write 130 MB/s, Read 153 MB/s.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711114] - Extra pages : 5214 used/500.
Dec 29 15:22:45 meshedgedx kernel: [ 1205.711115] - Result : Succeeded.

With in-kernel LZO compression enabled my hibernating laptop with 3950 KB RAM occupied 225238/1048232 pages of swap = 22 per cent of my laptop's 4094 KB swap. The amount of swap used for hibernation was 225238x4096/4142669824 = 23 per cent of my laptop's RAM.

So, making the swap size the same as the RAM size is more than enough. There is certainly no need to make the swap size larger than the RAM size, and one could get away with making the swap size smaller than the RAM size.

]]>
By: Aaron Toponce https://pthree.org/2012/10/18/how-much-swap/#comment-117050 Thu, 18 Oct 2012 16:54:22 +0000 http://pthree.org/?p=2547#comment-117050 For a desktop machine, I have no need to contain data in separate partitions. It's not multiuser, and I don't dual boot, so I don't need to contain /boot and /home. I'm not running busy servers on my machine, so I don't need to contain logging in /var. I have yet to see /tmp use more than 2MB on average. So, for myself, on a desktop or laptop, I throw everything in /, and that's it. I don't need contained partitions personally. I don't use LVM either. One large encrypted / that has everything.

]]>
By: John Massaglia https://pthree.org/2012/10/18/how-much-swap/#comment-117049 Thu, 18 Oct 2012 16:42:03 +0000 http://pthree.org/?p=2547#comment-117049 Are there any guides for partition sizes for a desktop machine? I am in the habit of setting up /, /boot, /tmp, /var, and /home to be seperate volumes but I haven't seen any good guides for sizing these volumes for over a decade.

]]>
By: Joseph Scott https://pthree.org/2012/10/18/how-much-swap/#comment-117048 Thu, 18 Oct 2012 15:54:10 +0000 http://pthree.org/?p=2547#comment-117048 In additional to some special use cases you mentioned, the other thing I ran into was some Linux kernels that would do odd things if there was no swap set. Setting just a simple 1GB swap segment was sufficient to make it happy again. It has been a few years since I've tested that so newer kernels may deal with that setup in a more graceful way now.

]]>
By: Aaron Toponce https://pthree.org/2012/10/18/how-much-swap/#comment-117047 Thu, 18 Oct 2012 15:52:11 +0000 http://pthree.org/?p=2547#comment-117047 Tim- Thanks for the link. I still find the recommendation silly, IMO. If you need it, use it. If you don't need it, don't use it. Setting hard numbers larger than 1-2 GB is a waste of disk. Take a 96 GB RAM KVM hypervisor. I don't have a spare 98 GB of disk lying around that I can use for swap, and if managed correctly, I haven't seen KVM actively use more than 2 GB. These astronomical sizes blow my mind.

]]>
By: ssam https://pthree.org/2012/10/18/how-much-swap/#comment-117046 Thu, 18 Oct 2012 15:51:24 +0000 http://pthree.org/?p=2547#comment-117046 we have probably moved from an era when people commonly had not enough RAM, to one where most people do have enough RAM.

for hibernating, you actually only need as much space as the RAM you are using. so if your typical workload uses 2GB of RAM, then you will need 2GB of swap to hibernate (even if you have 8GB of actual RAM).

however if you have 2GB RAM and 2GB swap, and you are currently have 3GB of allocated RAM (not including disk caches), then you wont be able to hibernate.

a sensible recommendation for a 'normal' user might be 2*RAM, unless thats bigger than 1% of hard disk, unless that's less than 2GB.

]]>
By: Tim Gelter https://pthree.org/2012/10/18/how-much-swap/#comment-117044 Thu, 18 Oct 2012 14:59:09 +0000 http://pthree.org/?p=2547#comment-117044 I don't mean to disprove anything you are saying, just leaving a link to the reference documentation I always use in case it's useful to anyone.

]]>
By: Tim Gelter https://pthree.org/2012/10/18/how-much-swap/#comment-117043 Thu, 18 Oct 2012 14:57:36 +0000 http://pthree.org/?p=2547#comment-117043 https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Storage_Administration_Guide/ch-swapspace.html

]]>