From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds) Subject: 0.97 (and pl1) memory use Date: 10 Aug 1992 07:38:41 GMT
[ I already sent this out to the mailing-list, but here goes... ]
[ And yes, this is a /really/ silly bug, and I'm only glad nobody else
found it first :-]
There is a very silly bug in 0.97 (and pl1) which results in the dynamic
buffer cache being badly used: when the buffers are grown, only half of
the actual space reserved for them is used. The offending code is in
linux/fs/buffer.c, in the function grow_buffers():
There is a for-loop something like this:
for (i = 0 ; i+size <= 4096 ; i += size) {
.....
bh->b_size = size;
- i += size;
}
Note that i is updated twice (both at the end of the for-statement and
in the for-block) which results in only every other buffer-area being
actually used - half the available memory is simply ignored. The easy
bug-fix is to remove either of the "i += size" statements, and I'd
suggest you remove the latter one (marked with a "-" above).
So if somebody wondered why there were only 3000 buffers although "free"
reported that over 6MB was used, this is the reason. I didn't really
look at the values that free returned until today, so I never noticed
(Lars Wirzenius can tell about the time I "lost" 4MB or my 8MB memory
for a week due to a programming thinko like the above. I didn't notice
anything until I had to make him a 4MB version of the kernel :-)
Linus