Gentoo Archives: gentoo-user

From: Albert Hopkins <marduk@×××××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] mysqld invoked oom-killer
Date: Thu, 21 Jul 2011 22:28:27
Message-Id: 1311287245.5379.15.camel@localhost.localdomain
In Reply to: Re: [gentoo-user] mysqld invoked oom-killer by Grant
1 On Thursday, July 21 at 10:27 (-0700), Grant said:
2
3 > It sounds like adding physical RAM is better than enabling swap in
4 > every way. I'll stay in the anti-swap camp.
5
6 I don't see why it has to be one way *or* the other...
7
8 Yes more RAM is always going to be better than more swap, RAM is just
9 way faster than disk, however byte-per-byte, disk is cheaper.
10
11 The whole reason why we have swap.. back in the olden days, some
12 programs needed more RAM than perhaps the system provided. Some of
13 these program were written with this in mind, and actually handled this
14 by manually writing some of it's data to disk, then freeing that data
15 from RAM, doing something, then when it needed the disk data, reading it
16 back into RAM (after having freed the previous data). This is of course
17 cumbersome. Enter virtual memory operating systems, which basically
18 treat fast memory (RAM) and slow memory (disk) as one flat memory pool.
19 Then the program it all looks like memory, and the OS does the paging in
20 and out to disk.
21
22 By now you would think "oh, but if I just had one system that had a more
23 RAM than i would ever use simultaneously, then I don't need swap, right?
24 Well, not exactly, because modern operationg systems also do something
25 called filesystem caching. What this does is, recently, and often used
26 (parts of) files on the filesystem are kept into fast RAM, so when a
27 program needs that data it can be fetched from cached RAM instead of
28 hitting slower disk. Ok, that's nice, but what does that have to do
29 with swap? Well, not only does Linux keep track of wIt sounds like
30 adding physical RAM is better than enabling swap in
31 every way. I'll stay in the anti-swap camp.hat files are used often, it
32 also keeps track of what pages of virtual memory are *not* used often.
33 Say you started some program a long time ago, or some program launches
34 at boot time, but that program sleeps and doesn't do anything for a long
35 time. Now ordinarily that program would just sit there taking up RAM.
36 Now you are running some other programs, and these programs are very
37 actively hitting the disk. Now Linux would love to use more RAM for
38 caching those disk hits, but that program you haven't touched in hours
39 is taking up RAM doing nothing.
40
41 That's where swap comes in. Linux would like to take that sleeping
42 process and swap some of its pages out to disk, so it can use the freed
43 RAM for more cache, and therefore speed up the programs that are
44 actually being used. Then, if the barely used process ever does wake
45 up, Linux can expire some cache and put it back into RAM.
46
47 In this case swap *is* good because it's making more efficient use of
48 RAM by swapping out seldom-used processes and using that RAM to cache
49 often-accessed files.
50
51 So a healthy combination of swap and RAM *can* be a good thing. If,
52 however, you have so much RAM that you can run every program you'd ever
53 run simultaneously with every file you'd ever access cached in RAM then
54 I wouldn't worry about swap ;)
55
56 -a

Replies

Subject Author
Re: [gentoo-user] mysqld invoked oom-killer Grant <emailgrant@×××××.com>