rename alloc_pages_exact()
Subsystems (6)
PATCH 1/3 rename alloc_pages_exact()
alloc_pages_exact() returns a virtual address. But, alloc_pages() returns a 'struct page *'. That makes for very confused kernel hackers.
__get_free_pages(), on the other hand, returns virtual addresses. That makes alloc_pages_exact() a much closer match to __get_free_pages(), so rename it to get_free_pages_exact(). Also change the arguments to have flags first, just like __get_free_pages().
Note that alloc_pages_exact()'s partner, free_pages_exact() already matches free_pages(), so we do not have to touch the free side of things.
---
linux-2.6.git-dave/drivers/video/fsl-diu-fb.c | 2 +- linux-2.6.git-dave/drivers/video/mxsfb.c | 2 +- linux-2.6.git-dave/drivers/video/pxafb.c | 6 +++--- linux-2.6.git-dave/drivers/virtio/virtio_pci.c | 2 +- linux-2.6.git-dave/include/linux/gfp.h | 2 +- linux-2.6.git-dave/kernel/profile.c | 4 ++-- linux-2.6.git-dave/mm/page_alloc.c | 18 +++++++++--------- linux-2.6.git-dave/mm/page_cgroup.c | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-)
drivers/video/fsl-diu-fb.c renamed from drivers/video/fsl-diu-fb.c~change-alloc_pages_exact-name +1 -1
@@ -294,7 +294,7 @@ static void *fsl_diu_alloc(size_t size,pr_debug ("size=%zu\n" , size); - virt =alloc_pages_exact (size,GFP_DMA | __GFP_ZERO); + virt =get_free_pages_exact (GFP_DMA | __GFP_ZERO, size);if (virt) { *phys =virt_to_phys (virt); pr_debug("virt=%p phys=%llx\n", virt,
drivers/video/mxsfb.c renamed from drivers/video/mxsfb.c~change-alloc_pages_exact-name +1 -1
@@ -718,7 +718,7 @@ static int __devinit mxsfb_init_fbinfo(s }else {if (!fb_size) fb_size =SZ_2M ;/* default */ - fb_virt =alloc_pages_exact (fb_size,GFP_DMA ); + fb_virt =get_free_pages_exact (GFP_DMA , fb_size);if (!fb_virt)return -ENOMEM ;
drivers/video/pxafb.c renamed from drivers/video/pxafb.c~change-alloc_pages_exact-name +3 -3
@@ -905,8 +905,8 @@ static int __devinit pxafb_overlay_map_v/* We assume that user will use at most video_mem_size for overlay fb, * anyway, it's useless to use 16bpp main plane and 24bpp overlay */ - ofb->video_mem =alloc_pages_exact (PAGE_ALIGN (pxafb->video_mem_size), -GFP_KERNEL | __GFP_ZERO); + ofb->video_mem =get_free_pages_exact (GFP_KERNEL | __GFP_ZERO, +PAGE_ALIGN (pxafb->video_mem_size));if (ofb->video_mem ==NULL )return -ENOMEM ;
@@ -1714,7 +1714,7 @@ static int __devinit pxafb_init_video_me {int size =PAGE_ALIGN (fbi->video_mem_size); - fbi->video_mem =alloc_pages_exact (size,GFP_KERNEL | __GFP_ZERO); + fbi->video_mem =get_free_pages_exact (GFP_KERNEL | __GFP_ZERO, size);if (fbi->video_mem ==NULL )return -ENOMEM ;
drivers/virtio/virtio_pci.c renamed from drivers/virtio/virtio_pci.c~change-alloc_pages_exact-name +1 -1
@@ -385,7 +385,7 @@ static struct virtqueue *setup_vq(struct info->msix_vector = msix_vec; size =PAGE_ALIGN (vring_size (num,VIRTIO_PCI_VRING_ALIGN )); - info->queue =alloc_pages_exact (size,GFP_KERNEL |__GFP_ZERO); + info->queue =get_free_pages_exact (GFP_KERNEL |__GFP_ZERO, size);if (info->queue ==NULL ) { err = -ENOMEM ; goto out_info;
include/linux/gfp.h renamed from include/linux/gfp.h~change-alloc_pages_exact-name +1 -1
@@ -351,7 +351,7 @@ extern struct page *alloc_pages_vma(gfp_extern unsigned long __get_free_pages (gfp_t gfp_mask,unsigned int order);extern unsigned long get_zeroed_page (gfp_t gfp_mask); -void *alloc_pages_exact (size_t size,gfp_t gfp_mask); +void *get_free_pages_exact (gfp_t gfp_mask,size_t size);void free_pages_exact (void *virt,size_t size);#define __get_free_page (gfp_mask) \
kernel/profile.c renamed from kernel/profile.c~change-alloc_pages_exact-name +2 -2
@@ -121,8 +121,8 @@ int __ref profile_init(void)if (prof_buffer)return 0 ; - prof_buffer =alloc_pages_exact (buffer_bytes, -GFP_KERNEL |__GFP_ZERO|__GFP_NOWARN); + prof_buffer =get_free_pages_exact (GFP_KERNEL |__GFP_ZERO|__GFP_NOWARN, + buffer_bytes);if (prof_buffer)return 0 ;
mm/page_alloc.c renamed from mm/page_alloc.c~change-alloc_pages_exact-name +9 -9
@@ -2318,7 +2318,7 @@ void free_pages(unsigned long addr, unsiEXPORT_SYMBOL (free_pages);/** -* alloc_pages_exact - allocate an exact number physically-contiguous pages. +* get_free_pages_exact - allocate an exact number physically-contiguous pages. * @size: the number of bytes to allocate * @gfp_mask: GFP flags for the allocation *
@@ -2330,7 +2330,7 @@ EXPORT_SYMBOL(free_pages);* * Memory allocated by this function must be released by free_pages_exact(). */ -void *alloc_pages_exact (size_t size,gfp_t gfp_mask) +void *get_free_pages_exact (gfp_t gfp_mask,size_t size) {unsigned int order =get_order (size);unsigned long addr;
@@ -2349,14 +2349,14 @@ void *alloc_pages_exact(size_t size, gfpreturn (void *)addr; } -EXPORT_SYMBOL (alloc_pages_exact); +EXPORT_SYMBOL (get_free_pages_exact);/** -* free_pages_exact - release memory allocated via alloc_pages_exact() -* @virt: the value returned by alloc_pages_exact. -* @size: size of allocation, same value as passed to alloc_pages_exact(). +* free_pages_exact - release memory allocated via get_free_pages_exact() +* @virt: the value returned by get_free_pages_exact. +* @size: size of allocation, same value as passed to get_free_pages_exact(). * -* Release the memory allocated by a previous call to alloc_pages_exact. +* Release the memory allocated by a previous call to get_free_pages_exact(). */ void free_pages_exact (void *virt,size_t size) {
@@ -5308,10 +5308,10 @@ void *__init alloc_large_system_hash(con/* * If bucketsize is not a power-of-two, we may free * some pages at the end of hash table which -* alloc_pages_exact() automatically does +* get_free_pages_exact() automatically does */ if (get_order (size) <MAX_ORDER ) { - table =alloc_pages_exact (size,GFP_ATOMIC ); + table =get_free_pages_exact (GFP_ATOMIC , size);kmemleak_alloc (table, size,1 ,GFP_ATOMIC ); } }
mm/page_cgroup.c renamed from mm/page_cgroup.c~change-alloc_pages_exact-name +1 -1
@@ -134,7 +134,7 @@ static void *__init_refok alloc_page_cgr {void *addr =NULL ; - addr =alloc_pages_exact (size,GFP_KERNEL | __GFP_NOWARN); + addr =get_free_pages_exact (GFP_KERNEL | __GFP_NOWARN, size);if (addr)return addr;
_
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/3 make new alloc_pages_exact()
What I really wanted in the end was a highmem-capable alloc_pages_exact(), so here it is. This function can be used to allocate unmapped (like highmem) non-power-of-two-sized areas of memory. This is in constast to get_free_pages_exact() which can only allocate from lowmem.
My plan is to use this in the virtio_balloon driver to allocate large, oddly-sized contiguous areas.
The new __alloc_pages_exact() now takes a size in numbers of pages, and returns a 'struct page', which means it can now address highmem. The (new) argument order mirrors alloc_pages() itself.
It's a bit unfortunate that this introduces __free_pages_exact() alongside free_pages_exact(). But that mess already exists with __free_pages() vs. free_pages_exact(). So, at worst, this mirrors the mess that we already have.
I'm also a bit worried that I've not put in something named alloc_pages_exact(), but that behaves differently than it did before this set. I got all of the in-tree cases, but I'm a bit worried about stragglers elsewhere. So, I'm calling this __alloc_pages_exact() for the moment. We can take out the __ some day if it bothers people.
Note that the __get_free_pages() has a !GFP_HIGHMEM check. Now that we are using alloc_pages_exact() instead of __get_free_pages() for get_free_pages_exact(), we had to add a new check in get_free_pages_exact().
This has been compile and boot tested, and I checked that
echo 2 > /sys/kernel/profiling
still works, since it uses get_free_pages_exact().
---
linux-2.6.git-dave/include/linux/gfp.h | 4 + linux-2.6.git-dave/mm/page_alloc.c | 85 ++++++++++++++++++++++++--------- 2 files changed, 68 insertions(+), 21 deletions(-)
include/linux/gfp.h renamed from include/linux/gfp.h~make_new_alloc_pages_exact +4 -0
@@ -352,6 +352,10 @@ extern struct page *alloc_pages_vma(gfp_extern unsigned long __get_free_pages (gfp_t gfp_mask,unsigned int order);extern unsigned long get_zeroed_page (gfp_t gfp_mask); +/* 'struct page' version */ +struct page *__alloc_pages_exact (gfp_t gfp_mask,unsigned long nr_pages); +void __free_pages_exact (struct page *page,unsigned long nr_pages); +/* virtual address version */ void *get_free_pages_exact (gfp_t gfp_mask,size_t size);void free_pages_exact (void *virt,size_t size);
mm/page_alloc.c renamed from mm/page_alloc.c~make_new_alloc_pages_exact +64 -21
115 lines not on this page · raw message
diff -puN mm/swap.c~make_new_alloc_pages_exact mm/swap.c
diff -puN tools/virtio/linux/virtio.h~make_new_alloc_pages_exact tools/virtio/linux/virtio.h diff -puN include/linux/types.h~make_new_alloc_pages_exact include/linux/types.h diff -puN Documentation/kbuild/kbuild.txt~make_new_alloc_pages_exact Documentation/kbuild/kbuild.txt diff -puN Documentation/sparse.txt~make_new_alloc_pages_exact Documentation/sparse.txt _
Re: [PATCH 2/3] make new alloc_pages_exact()
Quoted 30 lines · Dave Hansen
What I really wanted in the end was a highmem-capable
alloc_pages_exact(), so here it is. This function can be used to allocate unmapped (like highmem) non-power-of-two-sized areas of memory. This is in constast toget_free_pages_exact()which can only allocate from lowmem.My plan is to use this in the
virtio_balloondriver to allocate large, oddly-sized contiguous areas.The new
__alloc_pages_exact()now takes a size in numbers of pages, and returns a 'struct page', which means it can now address highmem. The (new) argument order mirrorsalloc_pages()itself.It's a bit unfortunate that this introduces
__free_pages_exact()alongsidefree_pages_exact(). But that mess already exists with__free_pages()vs.free_pages_exact(). So, at worst, this mirrors the mess that we already have.I'm also a bit worried that I've not put in something named
alloc_pages_exact(), but that behaves differently than it did before this set. I got all of the in-tree cases, but I'm a bit worried about stragglers elsewhere. So, I'm calling this__alloc_pages_exact()for the moment. We can take out the __ some day if it bothers people.Note that the
__get_free_pages()has a !GFP_HIGHMEM check. Now that we are usingalloc_pages_exact()instead of__get_free_pages()forget_free_pages_exact(), we had to add a new check inget_free_pages_exact().
Quoted 7 lines
This has been compile and boot tested, and I checked that
echo 2 >
/sys/kernel/profilingstill works, since it uses
get_free_pages_exact().Signed-off-by Dave Hansen <[email protected]>
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/3] make new alloc_pages_exact()
In reply to Dave HansenQuoted 6 lines · Dave Hansen
What I really wanted in the end was a highmem-capable
alloc_pages_exact(), so here it is. This function can be used to allocate unmapped (like highmem) non-power-of-two-sized areas of memory. This is in constast toget_free_pages_exact()which can only allocate from lowmem.
Is there an easy way to verify that alloc_pages_exact(5MB) really does allocate only 5MB and not 8MB? Is there some kind of function that returns the amount of unallocated memory, so I can do a diff?
Signature · 9 lines
Timur Tabi Linux kernel developer at Freescale -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/3] make new alloc_pages_exact()
Quoted 9 lines · Timur Tabi
Quoted 5 lines · Dave Hansen
What I really wanted in the end was a highmem-capable
alloc_pages_exact(), so here it is. This function can be used to allocate unmapped (like highmem) non-power-of-two-sized areas of memory. This is in constast toget_free_pages_exact()which can only allocate from lowmem.Is there an easy way to verify that
alloc_pages_exact(5MB)really does allocate only 5MB and not 8MB?
I'm not sure why you're asking. How do we know that the _normal_ allocator only gives us 4k when we ask for 4k? Well, that's just how it works. If alloc_pages_exact() returns success, you know it's got the amount of memory that you asked for, and only that plus a bit of masking for page alignment.
Have you seen alloc_pages_exact() behaving in some other way?
Quoted 2 lines
Is there some kind of function that returns the amount of unallocated memory, so I can do a diff?
Nope. Even if there was, it would be worthless. Calls to this might also cause the system to swap or reclaim memory, so you might end up with the same amount of free memory before and after the call.
-- Dave
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/3] make new alloc_pages_exact()
Quoted 10 lines · Dave Hansen
Quoted 2 lines
Is there an easy way to verify that
alloc_pages_exact(5MB)really does allocateQuoted 1 line
only 5MB and not 8MB?
I'm not sure why you're asking. How do we know that the _normal_ allocator only gives us 4k when we ask for 4k? Well, that's just how it works. If
alloc_pages_exact()returns success, you know it's got the amount of memory that you asked for, and only that plus a bit of masking for page alignment.Have you seen
alloc_pages_exact()behaving in some other way?
I've never tested this part of alloc_pages_exact(), even when I wrote (the first version of) it. I just took it on faith that it actually did what it was supposed to do.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Re: [PATCH 2/3] make new alloc_pages_exact()
Quoted 10 lines · Timur Tabi
Quoted 9 lines · Dave Hansen
Quoted 2 lines
Is there an easy way to verify that
alloc_pages_exact(5MB)really does allocateQuoted 1 line
only 5MB and not 8MB?
I'm not sure why you're asking. How do we know that the _normal_ allocator only gives us 4k when we ask for 4k? Well, that's just how it works. If
alloc_pages_exact()returns success, you know it's got the amount of memory that you asked for, and only that plus a bit of masking for page alignment.
Quoted 5 lines
Quoted 1 line
Have you seen
alloc_pages_exact()behaving in some other way?I've never tested this part of
alloc_pages_exact(), even when I wrote (the first version of) it. I just took it on faith that it actually did what it was supposed to do.
I did actually go add a bunch of printks to it at one point. It did seem to be working just fine and freeing the right amount of memory.
-- Dave
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/3 reuse __free_pages_exact() in __alloc_pages_exact()
In reply to Dave HansenMichal Nazarewicz noticed that __alloc_pages_exact()'s __free_page() loop was really close to something he was
using in one of his patches. That made me realize that
it was actually very similar to __free_pages_exact().
This uses __free_pages_exact() in place of the loop that we had in __alloc_pages_exact(). Since we had to change the temporary variables around anyway, I gave them some better names to hopefully address some other review comments.
---
linux-2.6.git-dave/mm/page_alloc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
mm/page_alloc.c renamed from mm/page_alloc.c~reuse-free-exact +3 -6
@@ -2338,14 +2338,11 @@ struct page *__alloc_pages_exact(gfp_t g page =alloc_pages (gfp_mask, order);if (page) { -struct page *alloc_end = page + (1 << order); -struct page *used = page + nr_pages; +struct page *unused_start = page + nr_pages; +unsigned long nr_unused = (1 << order) - nr_pages;split_page (page, order); -while (used < alloc_end) { -__free_page (used); - used++; - } +__free_pages_exact (unused_start, nr_unused); }return 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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 3/3] reuse __free_pages_exact() in __alloc_pages_exact()
Quoted 6 lines · Dave Hansen
Michal Nazarewicz noticed that __alloc_pages_exact()'s
__free_page()loop was really close to something he was
using in one of his patches. That made me realize that
it was actually very similar to__free_pages_exact().
Quoted 6 lines
This uses
__free_pages_exact()in place of the loop that we had in__alloc_pages_exact(). Since we had to change the temporary variables around anyway, I gave them some better names to hopefully address some other review comments.
No signed-off-by?
Re: [PATCH 3/3] reuse __free_pages_exact() in __alloc_pages_exact()
Quoted 6 lines · David Rientjes
Quoted 5 lines · Dave Hansen
Michal Nazarewicz noticed that __alloc_pages_exact()'s
__free_page()loop was really close to something he was
using in one of his patches. That made me realize that
it was actually very similar to__free_pages_exact().
Quoted 7 lines
Quoted 5 lines
This uses
__free_pages_exact()in place of the loop that we had in__alloc_pages_exact(). Since we had to change the temporary variables around anyway, I gave them some better names to hopefully address some other review comments.No signed-off-by?
Bah, sorry. I'll resend the whole sucker, with sob if anybody wants. Otherwise:
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 3/3] reuse __free_pages_exact() in __alloc_pages_exact()
Quoted 5 lines · Dave Hansen
Bah, sorry. I'll resend the whole sucker, with sob if anybody wants. Otherwise:
Signed-off-by Dave Hansen <[email protected]>
I think it's good to go into -mm as-is, unless anybody else has any objections to it. I'd also suggest adding a
for this patch even though it's explained in the changelog already.
Thanks, Dave!
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Dave Hansen
alloc_pages_exact()returns a virtual address. But,alloc_pages()returns a 'struct page *'. That makes for very confused kernel hackers.
__get_free_pages(), on the other hand, returns virtual addresses. That makesalloc_pages_exact()a much closer match to__get_free_pages(), so rename it toget_free_pages_exact(). Also change the arguments to have flags first, just like__get_free_pages().
Quoted 6 lines
Note that alloc_pages_exact()'s partner,
free_pages_exact()already matchesfree_pages(), so we do not have to touch the free side of things.Signed-off-by Dave Hansen <[email protected]>Acked-by Andi Kleen <[email protected]>Acked-by David Rientjes <[email protected]>
All three patches:
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale