Gentoo Archives: gentoo-user

From: Bill Kenworthy <billk@×××××××××.au>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Questions re swap and hibernate interaction on 8 gig machine
Date: Tue, 22 Jun 2010 01:03:51
Message-Id: 1277167526.19740.25.camel@troll
In Reply to: Re: [gentoo-user] Questions re swap and hibernate interaction on 8 gig machine by Alex Schuster
1 On Tue, 2010-06-22 at 00:27 +0200, Alex Schuster wrote:
2 > Walter Dnes writes:
3 >
4 > > I just got a brand new custom-built 8 gig machine. There's an outfit
5 > > in north Toronto that has MSI motherboards with PS/2 ports, so I can
6 > > keep my genuine IBM PS/2 clickety-clack-keyboard; wooooohooooo. And the
7 > > integrated Intel graphics chip has *BOTH VGA AND DIGITAL OUTPUTS*!
8 >
9 > Hooray!
10 >
11 > > Anyhow, I have 8 gigs of ram on the sytem (will obviously be 64-bit
12 > > Gentoo) and I want to know how much swap I need. The general rule of
13 > > thumb is twice the ram. In this case, it would be 16 gigs. I think
14 > > that it may not need swap when up, unless I do some heavy duty stuff.
15 >
16 > I think this rule does not scale with todays amounts of system ram. If
17 > your system would need a similar amount of swap, swapping such a lot
18 > would make things really really slow. You could probably live without
19 > any swap, except for the purpose of hibernating to disk.
20 >
21 > > My main concern about a swap partition is how much I need for
22 > > hibernate-to-disk to work. Is there a rule about this, or should I
23 > > simply allocate 16 gigs out of my terabyte drive, and play it safe?
24 >
25 > The amount of swap needed is the amount RAM actually being used on your
26 > system, compressed. Add the values of the 'used' fields of Mem and Swap
27 > in your free -m output, divide by two, and that should be somewhere near
28 > the amount you need. Maybe even less if tuxonice frees caches and
29 > buffers. 4GB should be more than enough, I'd think.
30 >
31 > But hibernation also works with swap files, so there is no need to set
32 > the exact size already. And I suggest the usage of LVM, this way you can
33 > freely and very easily change the swap size as you like. I never install
34 > Linux without LVM these days, this flexibility makes things so much
35 > easier, and I do not have to care much about partition sizes.
36 >
37 > Wonko
38 >
39
40 google has lots on this - this is one with a few ideas.
41 http://www.cyberciti.biz/tips/linux-swap-space.html
42
43 Generally hibernate (I use TuxOnIce with compression) uses around half
44 the occupied ram size - but you cant guarantee it, and if swap itself is
45 heavily loaded it gets critical.
46
47 In my case the most swap Ive ever used is 34Gb of a 145Gb swap partition
48 (5G ram, number crunching :) but graphics editing will sometimes require
49 up to 6gb swap in addition to ram. Keep in mind that the maximum swap
50 available varies depending on physical architecture (I think!, cant find
51 the original reference now, but its recapped here:
52 http://ubuntuforums.org/showthread.php?t=606837) My experience is you
53 can create as much swap as you want - but the cpu will only use as much
54 as its capable of - wastage! Note that i386 can only address 2Gb swap
55 in one partition, but you can have up to 32 swap partitions.
56
57 So its a 'how long is a piece of string' type question.
58
59 My 'algorithm' is something like:
60 1. swap is bad, get as much ram as possible
61
62 2. use a swap of 2xram 'just in case' that ram is not enough - better
63 that than a crash or oom event - disk space is cheap! Added benefit is
64 almost always enough space for hibernate.
65
66 3. use multiple swap partitions with each one on a different physical
67 disk mounted with equal priority to allow striping for performance
68 benefits. The more disks, the more swap partitions! Create them at the
69 start of the disk as thats apparently the fastest place to put them -
70 http://lissot.net/partition/partition-04.html
71
72 3. if swap/hibernate space looks like being a problem, hibernate to a
73 file instead (see tuxonice, not sure if the flakey in-kernal hibernate
74 works with a file)
75
76 4. on systems expected to occasionally need extra swap keep a swapfile
77 around for instant use, or a script to create one on the fly
78
79 5. Tune the kernel swappable parameter to either force most everything
80 to swap to keep ram free or the other way to make it less likely to swap
81 if thats whats needed. The current parameter is a compromise that works
82 in most cases, but there are uses that benefit one way or the other.
83
84 Lastly, to reiterate, disk space is cheap and putting aside 16Gb for
85 swap is a small price to pay for stability - you may only need it
86 occasionally, but then you will REALLY need it!
87
88 Have fun!
89
90 BillK

Replies