Gentoo Archives: gentoo-user

From: nunojsilva@ist.utl.pt (Nuno J. Silva)
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: Near freezes during large emerges
Date: Tue, 18 Jan 2011 11:07:55
Message-Id: 87ei8axypn.fsf@ist.utl.pt
In Reply to: Re: [gentoo-user] Near freezes during large emerges by William Kenworthy
1 William Kenworthy <billk@×××××××××.au> writes:
2
3 > On Mon, 2011-01-17 at 16:23 -0800, Grant wrote:
4 >> > I think the idea is never use swap if possible, but in a case where
5 >> > you don't have swap space or run out of swap space I think it's still
6 >> > possible to lose data.
7 >>
8 >> Isn't swap just an extension of system memory? Isn't adding 4GB of
9 >> memory just as effective at preventing out-of-memory as dedicating 4GB
10 >> of HD space to swap? I can understand enabling swap on a laptop or
11 >> other system with constrained memory capacity, but doesn't it make
12 >> sense to disable swap and add memory on a 24GB server?
13 >>
14 >> Is swap basically a way to save money on RAM?
15 >
16 > No swap contains pages from memory that have not been accessed for
17 > awhile so they can be stored elsewhere freeing ram for actual active
18 > pages. When they need to be accessed, they have to be swapped back in,
19 > and often something swapped back out to make room for it.
20
21 Like BillK said, it's not, whatever gets there must be swapped back in
22 to be used again.
23
24 For example, let's say you have a program that needs to open a really
25 really big file, an 8GiB file (no FAT jokes, please), and you have 4GiB
26 of RAM and 6GiB on swapfiles/partitions.
27
28 The system will not be able to put the entire file on the physical
29 memory (and it may not even be able to do so on virtual memory (memory
30 as the process sees it), if you're on 32 bits, IIRC).
31
32 This means, although the program can access the file data, and from its
33 own point-of-view, all data is on memory, the system will have to do
34 some swap-in-swap-out gymnastics every time the program wants a chunk of
35 the file that's not on RAM.
36
37 OTOH if you actually add 6GiB of RAM, you'll probably be able to do it
38 all from RAM (8GiB for the file, and the other 2GiB for whatever else is
39 running).
40
41 It is better to see it as BillK describes - not a way to extend your
42 memory, but a way to store not-that-frequently-used pages when you need
43 to load something else.
44
45 It saves money, but it's still expensive - on time.
46
47 --
48 Nuno J. Silva
49 gopher://sdf-eu.org/1/users/njsg