1 |
On Thursday, July 21 at 20:07 (-0700), Grant said: |
2 |
|
3 |
> >> Then why not have a really big swap file? If swap is useful as a |
4 |
> >> second layer of caching behind RAM, why doesn't everyone with some |
5 |
> >> extra hard drive space have a 100GB swap file? |
6 |
> >> |
7 |
> > You've not understood what I said, I think. Swap is not useful as |
8 |
> > filesystem cache. Swap is as efficient (probably a little less) |
9 |
> than |
10 |
> > the files on the disk. It's RAM that's efficient as filesystem |
11 |
> cache. |
12 |
> > |
13 |
> > Where swap comes in is the kernel can swap out pages from "stale" |
14 |
> > processes, and reclaim the RAM as filesystem cache. |
15 |
> |
16 |
> That all makes perfect sense, but if a small swap is good and a large |
17 |
> swap is not any better, I'm missing something. Maybe the pages from |
18 |
> stale processes never total more than a small amount? I don't see how |
19 |
> that could be |
20 |
|
21 |
Because you're (likely) never going to be using 100GB of memory at one |
22 |
time for all your processes, let alone "idle" processes, so what's the |
23 |
point of allocating all that swap? |
24 |
|
25 |
Continuing the analogy, it's like getting a stadium-sized attic that's |
26 |
100x bigger than the house your building it on just to store a Christmas |
27 |
tree and a few other items. |
28 |
|
29 |
Here's another way of looking at it. The kernel wants to use *all* your |
30 |
RAM. RAM is fast (compared to disk). But it wants to use the RAM for |
31 |
stuff that's actually needed most at the present time. So say you have |
32 |
4G RAM. You're only using maybe 1.5G memory for applications. So the |
33 |
kernel is going to try to use the remaining 2.5G for cache when/if it |
34 |
needs to. But let's say you're hitting the disk a lot because you're |
35 |
compiling something, then the kernel might decide it would like to cache |
36 |
more files than the 2.5G. So it sees you have 300M of paged in process |
37 |
memory that hasn't been used in a long while. A better use of RAM may |
38 |
be to swap out those 300M and use it for more filesystem cache, causing |
39 |
your compilation to run faster. But if you have a 100G swap file and |
40 |
only 300M of "idle" pages then all that extra swap isn't going to be of |
41 |
any use. Similarly, you don't want to swap out all of the 1.5G RAM |
42 |
because some of it is actually being actively used (e.g. by the |
43 |
compiler). |