Con Kolivas [interview] posted an updated version of his Swappiness Autoregulation patch [story], this time "done the right way (tm)". Instead of updating swappiness at every tick (which is either 100 or 1000 or 1024 times per second, depending on architecture) the swappiness is updated only when there is pressure to swap. This has the double benefit of avoiding a possible divide-by-zero error, and reduced overhead. It also makes swappiness read-only to user-space.
From: Con Kolivas [email blocked] To: linux-kernel Subject: [PATCH] Autoregulate vm swappiness cleanup Date: 2003-10-25 6:58:22 On Fri, 24 Oct 2003 01:03, Con Kolivas wrote: > On Friday 24 October 2003 00:42, Martin J. Bligh wrote: > > It seems that you don't need si_swapinfo here, do you? i.freeram, > > i.bufferram, and i.totalram all come from meminfo, as far as I can > > see? Maybe I'm missing a bit ... > > Well I did do it a while ago and it seems I got carried away adding and > subtracting info indeed. :-) Here's a simpler patch that does the same > thing. The off-list enthusiasm has been rather strong so here is a patch done the right way (tm). There is no need for the check of totalram being zero (the original version of this patch modified the swappiness every tick which was wasteful and had a divide by zero on init). Adjusting vm_swappiness only when there is pressure to swap means totalram shouldn't be ever be zero. The sysctl is made read only since writing to it would be ignored now. Con [patch can be found here]
No big deal
This isn't really big news. It works exactly the same as the posted version and is ever so slightly cheaper and complete. I was referring to the original design (which I never posted to lkml) that modified it every tick. The divide by zero issue was a possibility in that unposted design and some of the algorithm had to check for divide by zero. However you can link directly to my patches here.
Re: No big deal
So the only change is that it's now read-only?
Mostly
There is one compare removed in the code. Instead of (totalram ? totalram : 1) it is now just totalram. This is a tiny change but cmp is relatively expensive on the cpu. Realistically this is code hit infrequently and it would be so small a difference it would be impossible to measure. However there is no point having redundant code in anything no matter how small the performance hit is in real terms.