pte_chain_mempool-2.5.27-1
Subsystems (5)
This patch, in order to achieve more reliable and efficient allocation, converts the pte_chain freelist to use mempool, which in turn uses the slab allocator as a front-end. This includes a cleanup of the obsoleted statistics, which are now slab-maintained, and a replacement of them with the ReverseMaps: statistics which reports the number of reverse mappings performed.
$ diffstat ~/patches/pte_chain_mempool-1 fs/proc/proc_misc.c | 6 -- include/linux/page-flags.h | 3 - init/main.c | 4 - mm/page_alloc.c | 3 - mm/rmap.c | 99 ++++++++++++++++----------------------------- 5 files changed, 43 insertions(+), 72 deletions(-)
Cheers,
Bill
===== fs/proc/proc_misc.c 1.31 vs edited =====
fs/proc/proc_misc.c +2 -4
@@ -161,8 +161,7 @@"Dirty: %8lu kB\n" "Writeback: %8lu kB\n" "PageTables: %8lu kB\n" -"PteChainTot: %8lu kB\n" -"PteChainUsed: %8lu kB\n" , +"ReverseMaps: %8lu\n" ,K (i.totalram),K (i.freeram), K(i.sharedram),
@@ -179,8 +178,7 @@K (ps.nr_dirty),K (ps.nr_writeback),K (ps.nr_page_table_pages), -K (ps.nr_pte_chain_pages), - ps.used_pte_chains_bytes >>10 +K (ps.nr_reverse_maps) );return proc_calc_metrics (page, start, off, count, eof, len);
===== include/linux/page-flags.h 1.12 vs edited =====
include/linux/page-flags.h +1 -2
@@ -79,8 +79,7 @@unsigned long nr_active;/* on active_list LRU */ unsigned long nr_inactive;/* on inactive_list LRU */ unsigned long nr_page_table_pages; -unsigned long nr_pte_chain_pages; -unsigned long used_pte_chains_bytes; +unsigned long nr_reverse_maps; }____cacheline_aligned_in_smp page_states[NR_CPUS ];extern void get_page_state (struct page_state *ret);
===== init/main.c 1.51 vs edited =====
init/main.c +2 -2
@@ -70,7 +70,7 @@extern void sysctl_init (void );extern void signals_init (void );extern void buffer_init (void ); - +extern void pte_chain_init (void );extern void radix_tree_init (void );extern void free_initmem (void );
@@ -386,7 +386,7 @@mem_init ();kmem_cache_sizes_init ();pgtable_cache_init (); - +pte_chain_init (); mempages = num_physpages;fork_init (mempages);
===== mm/page_alloc.c 1.82 vs edited =====
mm/page_alloc.c +1 -2
@@ -566,8 +566,7 @@ ret->nr_active += ps->nr_active; ret->nr_inactive += ps->nr_inactive; ret->nr_page_table_pages += ps->nr_page_table_pages; - ret->nr_pte_chain_pages += ps->nr_pte_chain_pages; - ret->used_pte_chains_bytes += ps->used_pte_chains_bytes; + ret->nr_reverse_maps += ps->nr_reverse_maps; } }
===== mm/rmap.c 1.3 vs edited =====
mm/rmap.c +37 -62
155 lines not on this page · raw message
Quoted 4 lines · William Lee Irwin III
This patch, in order to achieve more reliable and efficient allocation, converts the
pte_chainfreelist to use mempool, which in turn uses the slab allocator as a front-end.
Using slab seems like a good idea to me. It gives us the per-cpu freelists and GC for free.
mempool? Guess so.
mempool is really designed for things like IO request structures. BIOs, etc. Things which are guaranteed to have short lifecycles. Things which make the "wait for some objects to be freed" loop in mempool_alloc() reliable.
However when mempool went in, a bunch of developers (including myself) went "oh goody" and reused mempool to add some buffering to things like radix tree nodes, buffer_heads, pte_chains, etc.
This is inappropriate, because those objects have a very different lifecycle.
For example, back when swap was using buffer_heads, I was getting tasks locked up in mempool_alloc(GFP_NOIO), waiting for buffer_heads to come free. But no buffer_heads were being freed because there was no memory pressure any more - somebody had just done a truncate() or an exit(), there was plenty of free memory, nobody was calling try_to_free_buffers() and the mempool_alloc caller was in indefinite sleep. Waiting for someone to free up a buffer_head.
We could fix this problem by changing the schedule() in mempool_alloc() into a schedule_timeout(not much), but Ingo didn't seem to like that. Perhaps because we're using mempool in ways for which it was not designed.
mm/rmap.c line 427
Quoted 5 lines
mm/rmap.c +5
-0+ pte_chain_pool =mempool_create (16 *1024 , + pte_chain_pool_alloc, + pte_chain_pool_free, +NULL ); +
Be aware that mempool kmallocs a contiguous chunk of element pointers. This statement is asking for a kmalloc(16384 * sizeof(void *)), which is 128k. It will work, but only just.
How did you engineer the size of this pool, btw? In the radix_tree code, we made the pool enormous. It was effectively halved in size when the ratnodes went to 64 slots, but I still have the fun task of working out what the pool size should really be. In retrospect it would have been smarter to make it really small and then increase it later in response to tester feedback. Suggest you do that here.
-
Quoted 5 lines · Andrew Morton
mempool? Guess so.
mempool is really designed for things like IO request structures. BIOs, etc. Things which are guaranteed to have short lifecycles. Things which make the "wait for some objects to be freed" loop inmempool_alloc()reliable.
My usage of it was incorrect. Slab allocation alone will have to do.
Quoted 11 lines · Andrew Morton
Be aware that mempool kmallocs a contiguous chunk of element pointers. This statement is asking for a
kmalloc(16384 * sizeof(void *)), which is 128k. It will work, but only just.
How did you engineer the size of this pool, btw? In theradix_treecode, we made the pool enormous. It was effectively halved in size when the ratnodes went to 64 slots, but I still have the fun task of working out what the pool size should really be. In retrospect it would have been smarter to make it really small and then increase it later in response to tester feedback. Suggest you do that here.
Any contiguous allocation that large is a bug. There was no engineering. It was a "conservative guess", and hence even worse than the radix tree node pool sizing early on. Removing mempool from it entirely is the best option. pte_chains aren't transient enough to work with this, and my misreading of mempool led me to believe it had the logic to deal with the cases you described above.
OOM handling is on the way soon anyway, so mempool for "extra reliability" will be a non-issue then.
Cheers,
Bill