Linus曾经在一个关于Swap的mail讨论中指出:
In the course of discussion, it became clear that Linux 2.4.x required more swap than previous versions. Rik van Riel mentioned, “2.4 keeps dirty pages in the swap cache, so you will need more swap to run the same programs…” He asked Linus Torvalds, “is this something we want to keep or should we give the user the option to run in a mode where swap space is freed when we swap in something non-shared ?” Linus replied:
I’d prefer just documenting it and keeping it. I’d hate to have two fairly different modes of behaviour. It’s always been the suggested “twice the amount of RAM”, although there’s historically been the “Linux doesn’t really need that much” that we just killed with 2.4.x.
If you have 512MB of RAM, you can probably afford another 40GB or so of harddisk. They are disgustingly cheap these days.
Zlatko Calusic worried that more data in swap would degrade performance because the disk head would need more seek time to find data. He asked if Linus was sure this would be okay, and Linus replied, “I’m not _sure_, obviously. However, one thing I _am_ sure of is that the sticky page-cache simplifies some things enormously, and make some things possible that simply weren’t possible before.” . But in a nearby post he admitted, “the sticky allocation _might_ make the IO we do be more spread out.” He felt it was important to consider these kinds of potential downsides, though he felt that in this case the benefits outweighed the drawbacks; and at one point Eric W. Biederman explained succinctly, “The tradeoff when implemented correctly is that writes will tend to be more spread out and reads should be better clustered together.”
Zlatko ran some tests, and could not find any problems with the 2.4.0 memory management logic, though he added, “I have found that new kernel allocates 4 times more swap space under some circumstances. That may or may not be alarming, it remains to be seen.” At one point, Linus gave his overall take on 2.2/2.4 performance issues. He said:
I personally think 2.4.x is going to be as fast or faster at just about anything. We do have some MM issues still to hash out, and tuning to do, but I’m absolutely convinced that 2.4.x is going to be a _lot_ easier to tune than 2.2.x ever was. The “scan the page tables without doing any IO” thing just makes the 2.4.x memory management several orders of magnitude more flexible than 2.2.x ever was.
(This is why I worked so hard at getting the PageDirty semantics right in the last two months or so – and why I released 2.4.0 when I did. Getting PageDirty right was the big step to make all of the VM stuff possible in the first place. Even if it probably looked a bit foolhardy to change the semantics of “writepage()” quite radically just before 2.4 was released).
Elsewhere, he considered the case of swapless or low-swap machines:
If you don’t have any swap, or if you run out of swap, the major difference between 2.2.x and 2.4.x is probably going to be the oom handling: I suspect that 2.4.x might be more likely to kill things off sooner (but it tries to be graceful about which processes to kill).
Not having any swap is going to be a performance issue for both 2.2.x and 2.4.x – Linux likes to push inactive dirty pages out to swap where they can lie around without bothering anybody, even if there is no _major_ memory crunch going on.
If you do have swap, but it’s smaller than your available physical RAM, I suspect that the Linux-2.4 swap pre-allocate may cause that kind of performance degradation earlier than 2.2.x would have. Another way of putting this: in 2.2.x you could use a fairly small swap partition to pick up some of the slack, and in 2.4.x a really small swap-partition doesn’t really buy you much anything.
很有意思,值得看。