Why struct meta_page?
Posted Aug 3, 2007 14:35 UTC (Fri) by
i3839 (guest, #31386)
In reply to:
Why struct meta_page? by balbir_singh
Parent article:
Controlling memory use in containers
Thanks for the pointer, interesting paper. It explains a lot, but it didn't convince me yet.
You started with an unmodified struct page. Then it turned out adding a pointer back to the struct meta_page was really worth it, so you did. Now you end up with:
/*
* A meta page is associated with every page descriptor. The meta page
* helps us identify information about the container
*/
struct meta_page {
struct list_head lru; /* per container LRU list */
struct page *page;
struct mem_container *mem_container;
};
and a struct meta_page *meta_page; in struct page.
That are 5 pointers, of which two are used to link a meta_page and its corresponding page to each other, which is a very big overhead and probably also makes the code more complex.
So the current method uses (1 * nr_pages + 4 * A) * sizeof(pointer) memory, where 'A' is the number of pages associated with a meta page.
Getting rid of struct meta_page and embedding lru and *mem_container directly in struct page will use 3 * nr_pages * sizeof(pointer).
Using that we can calculate which method is under which circumstances more memory efficient:
1 * nr_pages + 4 * A < 3 * nr_pages
-> 4 * A < 2 * nr_pages
-> A < nr_pages/2
Assuming that 'A' equals the number of active pages, the conclusion is that a separate struct meta_page is only better when less than half of all memory is active. But:
1) That seems like an uncommon condition, so in general it's expected that it will be much more than that (e.g. on my system the ratio is 1/5 in favour of active pages, and the few other systems I checked also have much more active pages than inactive ones).
2) Optimizing memory usage makes only sense for when there is memory shortage, so to see what approach is most effective it should be compared under memory pressure conditions. If the number of active pages is low it can be expected that the memory pressure is low too.
What am I missing?
(
Log in to post comments)