slab: cleanup kmem_getpages
PATCH 1/1 slab: cleanup kmem_getpages
The last ifdef addition hit the ugliness treshold on this functions, so:
- rename the varibale i to nr_pages so it's somewhat descriptive
- remove the addr variable and do the page_address call at the very end
- instead of ifdef'ing the whole alloc_pages_node call just make the __GFP_COMP addition to flags conditional
- rewrite the __GFP_COMP comment to make sense
mm/slab.c +13 -14
@@ -1452,31 +1452,30 @@static void *kmem_getpages (struct kmem_cache *cachep,gfp_t flags,int nodeid) {struct page *page; -void *addr; -int i; +int nr_pages; - flags |= cachep->gfpflags;#ifndef CONFIG_MMU -/* nommu uses slab's for process anonymous memory allocations, so -* requires __GFP_COMP to properly refcount higher order allocations" +/* +* Nommu uses slab's for process anonymous memory allocations, and thus +* requires __GFP_COMP to properly refcount higher order allocations */ - page =alloc_pages_node (nodeid, (flags | __GFP_COMP), cachep->gfporder); -#else - page =alloc_pages_node (nodeid, flags, cachep->gfporder); + flags |= __GFP_COMP;#endif + flags |= cachep->gfpflags; + + page =alloc_pages_node (nodeid, flags, cachep->gfporder);if (!page)return NULL ; - addr =page_address (page); - i = (1 << cachep->gfporder); + nr_pages = (1 << cachep->gfporder);if (cachep->flags &SLAB_RECLAIM_ACCOUNT ) -atomic_add (i, &slab_reclaim_pages); -add_page_state (nr_slab, i); -while (i--) { +atomic_add (nr_pages, &slab_reclaim_pages); +add_page_state (nr_slab, nr_pages); +while (nr_pages--) {__SetPageSlab (page); page++; } -return addr; +return page_address (page); }/*
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Christoph Hellwig
The last ifdef addition hit the ugliness treshold on this functions, so:
- rename the varibale i to
nr_pagesso it's somewhat descriptive
- remove the addr variable and do thepage_addresscall at the very end
- instead of ifdef'ing the wholealloc_pages_nodecall just make the__GFP_COMPaddition to flags conditional
- rewrite the__GFP_COMPcomment to make sense
....
Quoted 4 lines
mm/slab.c +1
-1+ page =alloc_pages_node (nodeid, flags, cachep->gfporder);if (!page)return NULL ; - addr =page_address (page);
.....
mm/slab.c line 1478
Quoted 6 lines
mm/slab.c +2
-1+while (nr_pages--) {__SetPageSlab (page); page++; } -return addr; +return page_address (page);
I think that's a bug - you return the address of the page after the allocation, not the first page of the allocation.
Cheers,
Dave.
Signature · 9 lines
Dave Chinner R&D Software Enginner SGI Australian Software Group -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 14 lines · David Chinner
Quoted 7 lines · Christoph Hellwig
The last ifdef addition hit the ugliness treshold on this functions, so:
- rename the varibale i to
nr_pagesso it's somewhat descriptive
- remove the addr variable and do thepage_addresscall at the very end
- instead of ifdef'ing the wholealloc_pages_nodecall just make the__GFP_COMPaddition to flags conditional
- rewrite the__GFP_COMPcomment to make sense....
Quoted 4 lines
mm/slab.c +1
-1+ page =alloc_pages_node (nodeid, flags, cachep->gfporder);if (!page)return NULL ; - addr =page_address (page);.....
Quoted 9 lines
mm/slab.c line 1478
Quoted 6 lines
mm/slab.c +2
-1+while (nr_pages--) {__SetPageSlab (page); page++; } -return addr; +return page_address (page);I think that's a bug - you return the address of the page after the allocation, not the first page of the allocation.
You're right. I wonder why this didn't show up in my testing. Looks like slab will never allocate any high-order pages if your page size is big enough..
Andrew, please drop this for now. I'll redo it without that bit once I'll get some time.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 16 lines · Christoph Hellwig
Quoted 6 lines
Quoted 5 lines
(quoted diff) +1
-1+ page = alloc_pages_node(nodeid, flags, cachep->gfporder); if (!page) return NULL; - addr = page_address(page);.....
Quoted 9 lines
Review
Quoted 6 lines
(quoted diff) +2
-1+ while (nr_pages--) { __SetPageSlab(page); page++; } - return addr; + return page_address(page);I think that's a bug - you return the address of the page after the allocation, not the first page of the allocation.
Quoted 6 lines
You're right. I wonder why this didn't show up in my testing. Looks like slab will never allocate any high-order pages if your page size is big enough..
Andrew, please drop this for now. I'll redo it without that bit once I'll get some time.
I already fixed it - it was giving me instantaneous oopses.
mm/slab.c renamed from mm/slab.c~slab-cleanup-kmem_getpages-fix +3 -4
@@ -1492,6 +1492,7 @@ static void *kmem_getpages(struct kmem_c {struct page *page;int nr_pages; +int i;#ifndef CONFIG_MMU /*
@@ -1510,10 +1511,8 @@ static void *kmem_getpages(struct kmem_cif (cachep->flags &SLAB_RECLAIM_ACCOUNT )atomic_add (nr_pages, &slab_reclaim_pages);add_page_state (nr_slab, nr_pages); -while (nr_pages--) { -__SetPageSlab (page); - page++; - } +for (i =0 ; i < nr_pages; i++) +__SetPageSlab (page + i);return page_address (page); }
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>