I was thinking about something like this, but more along the lines of a "soft reserved area". If we assume that there are classes of memory that can always be discarded then an area can be reserved for contiguous memory allocation, but it will also allow memory to be allocated for pages that can definitely be safely discarded. When a contiguous memory allocation is required, then there is a block of memory available that can be freed quickly at low cost.
The difficulty for me, as someone unfamiliar with the kernel, is whether sufficient such pages would be available and identifiable? I wondered about I/O buffers, but clearly if the file is writeable then the pages could not always be discarded. If the kernel "knows" whether a file has been opened read only or read/write, that might simplify the question. Also there is a risk of a performance hit from having to dump a large number of buffers.
I'm guessing that such a scheme has already been considered by people that know more than I do about the issues and has been deemed impractical?
Posted Jul 22, 2010 13:53 UTC (Thu) by nix (subscriber, #2304)
[Link]
Well, the defragmentation code obviously knows which regions can be defragmented: so there could be a memory zone that contains only allocations that defragmentation could move out of the way, plus regions that could be freed without writeout. I don't think this exists yet, though, and memory zones are single contiguous lumps, not a bunch of individually-contiguous regions like CMA produces. So I suppose 'is in a CMA region' would have to be another page flag or something. But we're perennially short of those...
Contiguous memory allocation for drivers
Posted Jul 25, 2010 11:16 UTC (Sun) by mina86 (subscriber, #68442)
[Link]
What you are describing is exactly what I've put as a future work. I believe that centralising contiguous-memory allocation will help implement a scheme where a free area of the CMA regions can be used for buffers, page cache, etc. Obviously, read-only pages would be preferred as they are trivial to discard but even dirty pages could stay in CMA managed regions of memory.
As I've said, this is, however, a future work. Hopefully, we'll get there some day. :)