* [PATCH] slab: cleanup kmem_getpages
@ 2006-04-14 18:36 Christoph Hellwig
2006-04-18 23:20 ` David Chinner
0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2006-04-14 18:36 UTC (permalink / raw)
To: akpm; +Cc: linux-mm
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
Signed-off-by: Christoph Hellwig <hch@lst.de>
Index: linux-2.6/mm/slab.c
===================================================================
--- linux-2.6.orig/mm/slab.c 2006-04-13 16:22:12.000000000 +0200
+++ linux-2.6/mm/slab.c 2006-04-13 16:53:15.000000000 +0200
@@ -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 majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] slab: cleanup kmem_getpages
2006-04-14 18:36 [PATCH] slab: cleanup kmem_getpages Christoph Hellwig
@ 2006-04-18 23:20 ` David Chinner
2006-04-18 23:24 ` Christoph Hellwig
0 siblings, 1 reply; 4+ messages in thread
From: David Chinner @ 2006-04-18 23:20 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: akpm, linux-mm
On Fri, Apr 14, 2006 at 08:36:18PM +0200, Christoph Hellwig wrote:
> 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
....
> + page = alloc_pages_node(nodeid, flags, cachep->gfporder);
> if (!page)
> return NULL;
> - addr = page_address(page);
.....
> + 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.
--
Dave Chinner
R&D Software Enginner
SGI Australian Software Group
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] slab: cleanup kmem_getpages
2006-04-18 23:20 ` David Chinner
@ 2006-04-18 23:24 ` Christoph Hellwig
2006-04-18 23:38 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2006-04-18 23:24 UTC (permalink / raw)
To: David Chinner; +Cc: Christoph Hellwig, akpm, linux-mm
On Wed, Apr 19, 2006 at 09:20:00AM +1000, David Chinner wrote:
> On Fri, Apr 14, 2006 at 08:36:18PM +0200, Christoph Hellwig wrote:
> > 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
> ....
> > + page = alloc_pages_node(nodeid, flags, cachep->gfporder);
> > if (!page)
> > return NULL;
> > - addr = page_address(page);
> .....
> > + 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 majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] slab: cleanup kmem_getpages
2006-04-18 23:24 ` Christoph Hellwig
@ 2006-04-18 23:38 ` Andrew Morton
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2006-04-18 23:38 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: dgc, linux-mm
Christoph Hellwig <hch@lst.de> wrote:
>
> > > + page = alloc_pages_node(nodeid, flags, cachep->gfporder);
> > > if (!page)
> > > return NULL;
> > > - addr = page_address(page);
> > .....
> > > + 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.
I already fixed it - it was giving me instantaneous oopses.
--- devel/mm/slab.c~slab-cleanup-kmem_getpages-fix 2006-04-15 01:00:53.000000000 -0700
+++ devel-akpm/mm/slab.c 2006-04-15 01:01:49.000000000 -0700
@@ -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_c
if (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 majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-04-18 23:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-14 18:36 [PATCH] slab: cleanup kmem_getpages Christoph Hellwig
2006-04-18 23:20 ` David Chinner
2006-04-18 23:24 ` Christoph Hellwig
2006-04-18 23:38 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).