[uClinux-dev] Reclaiming Memory
Gavin Lambert
gavinl at compacsort.com
Fri Nov 2 00:29:44 EST 2007
Quoth Harry Gunnarsson:
> Hm, you are saying one thing that gets me thinking. I assumed,
> perhaps incorrectly, that the 'chunks' of memory in the
> power-of-two scheme were pre-allocated at kernel start.
> That is, n * 128k, m * 256k, y * 512k etc And I thought that
> the big chunks of 2M and 4M were also pre-allocated at startup
> and never used for small allocations.
>
> I thought that this was the point of the SLAB allocator, i.e.
> avoiding fragmentations with fixed size pre-allocated blocks.
Well, I'm not entirely certain how the SLAB allocator operates, since I
haven't really looked at its code at all. But I do know (from testing) that
larger blocks can be chosen and sliced to create smaller blocks. I don't
know what its criteria is for choosing blocks; my *assumption* is that it
walks up the chain (ie. if it needs a 256k block, it'll look in the 256k
free list, and only if there aren't any will it go up to the 512k free list,
and so on until it finds a block it can slice up and distribute). But I
really don't know. Maybe it tries to do something clever instead.
> So there is no 'guaranteed' way of making sure the system can
> deliver reliably a 4M chunk of memory over the time of execution, right?
If you want to absolutely guarantee it, then don't let Linux have the RAM in
the first place :) (Either by lying to it about how much RAM is there or by
using something like the bootmem interface.) Usually you don't need to go
that far, though.
More information about the uClinux-dev
mailing list