* [PATCH 1/2] rename alloc_pages_exact()
@ 2011-04-07 17:21 Dave Hansen
2011-04-07 17:21 ` [PATCH 2/2] make new alloc_pages_exact() Dave Hansen
2011-04-07 21:40 ` [PATCH 1/2] rename alloc_pages_exact() David Rientjes
0 siblings, 2 replies; 10+ messages in thread
From: Dave Hansen @ 2011-04-07 17:21 UTC (permalink / raw)
To: linux-mm
Cc: linux-kernel, Timur Tabi, Andi Kleen, Mel Gorman, Andrew Morton,
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
makes alloc_pages_exact() a much closer match to __get_free_pages(), so
rename it to get_free_pages_exact().
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.
Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
---
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 | 4 ++--
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 | 2 +-
linux-2.6.git-dave/mm/page_alloc.c | 24 ++++++++++++------------
linux-2.6.git-dave/mm/page_cgroup.c | 2 +-
8 files changed, 20 insertions(+), 20 deletions(-)
diff -puN drivers/video/fsl-diu-fb.c~change-alloc_pages_exact-name drivers/video/fsl-diu-fb.c
--- linux-2.6.git/drivers/video/fsl-diu-fb.c~change-alloc_pages_exact-name 2011-04-07 08:37:58.074400957 -0700
+++ linux-2.6.git-dave/drivers/video/fsl-diu-fb.c 2011-04-07 08:37:58.186400949 -0700
@@ -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,
diff -puN drivers/video/pxafb.c~change-alloc_pages_exact-name drivers/video/pxafb.c
--- linux-2.6.git/drivers/video/pxafb.c~change-alloc_pages_exact-name 2011-04-07 08:37:58.078400957 -0700
+++ linux-2.6.git-dave/drivers/video/pxafb.c 2011-04-07 08:39:16.198395385 -0700
@@ -905,7 +905,7 @@ 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),
+ ofb->video_mem = get_free_pages_exact(PAGE_ALIGN(pxafb->video_mem_size),
GFP_KERNEL | __GFP_ZERO);
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;
diff -puN drivers/virtio/virtio_pci.c~change-alloc_pages_exact-name drivers/virtio/virtio_pci.c
--- linux-2.6.git/drivers/virtio/virtio_pci.c~change-alloc_pages_exact-name 2011-04-07 08:37:58.082400957 -0700
+++ linux-2.6.git-dave/drivers/virtio/virtio_pci.c 2011-04-07 08:37:58.190400949 -0700
@@ -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;
diff -puN include/linux/gfp.h~change-alloc_pages_exact-name include/linux/gfp.h
--- linux-2.6.git/include/linux/gfp.h~change-alloc_pages_exact-name 2011-04-07 08:37:58.086400956 -0700
+++ linux-2.6.git-dave/include/linux/gfp.h 2011-04-07 08:37:58.190400949 -0700
@@ -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) \
diff -puN kernel/profile.c~change-alloc_pages_exact-name kernel/profile.c
--- linux-2.6.git/kernel/profile.c~change-alloc_pages_exact-name 2011-04-07 08:37:58.090400955 -0700
+++ linux-2.6.git-dave/kernel/profile.c 2011-04-07 08:37:58.190400949 -0700
@@ -121,7 +121,7 @@ int __ref profile_init(void)
if (prof_buffer)
return 0;
- prof_buffer = alloc_pages_exact(buffer_bytes,
+ prof_buffer = get_free_pages_exact(buffer_bytes,
GFP_KERNEL|__GFP_ZERO|__GFP_NOWARN);
if (prof_buffer)
return 0;
diff -puN mm/page_alloc.c~change-alloc_pages_exact-name mm/page_alloc.c
--- linux-2.6.git/mm/page_alloc.c~change-alloc_pages_exact-name 2011-04-07 08:37:58.094400955 -0700
+++ linux-2.6.git-dave/mm/page_alloc.c 2011-04-07 08:37:58.194400949 -0700
@@ -2318,19 +2318,19 @@ void free_pages(unsigned long addr, unsi
EXPORT_SYMBOL(free_pages);
/**
- * alloc_pages_exact - allocate an exact number physically-contiguous pages.
- * @size: the number of bytes to allocate
+ * get_free_pages_exact - allocate an exact number physically-contiguous pages.
* @gfp_mask: GFP flags for the allocation
+ * @size: the number of bytes to allocate
*
- * This function is similar to alloc_pages(), except that it allocates the
- * minimum number of pages to satisfy the request. alloc_pages() can only
+ * This function is similar to __get_free_pages(), except that it allocates the
+ * minimum number of pages to satisfy the request. get_free_pages() can only
* allocate memory in power-of-two pages.
*
* This function is also limited by MAX_ORDER.
*
* 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, gfp
return (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);
}
}
diff -puN mm/page_cgroup.c~change-alloc_pages_exact-name mm/page_cgroup.c
--- linux-2.6.git/mm/page_cgroup.c~change-alloc_pages_exact-name 2011-04-07 08:37:58.098400955 -0700
+++ linux-2.6.git-dave/mm/page_cgroup.c 2011-04-07 08:37:58.198400948 -0700
@@ -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;
diff -puN drivers/video/mxsfb.c~change-alloc_pages_exact-name drivers/video/mxsfb.c
--- linux-2.6.git/drivers/video/mxsfb.c~change-alloc_pages_exact-name 2011-04-07 08:37:58.102400955 -0700
+++ linux-2.6.git-dave/drivers/video/mxsfb.c 2011-04-07 08:37:58.198400948 -0700
@@ -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;
_
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/2] make new alloc_pages_exact()
2011-04-07 17:21 [PATCH 1/2] rename alloc_pages_exact() Dave Hansen
@ 2011-04-07 17:21 ` Dave Hansen
2011-04-07 22:03 ` David Rientjes
2011-04-08 12:28 ` Michal Nazarewicz
2011-04-07 21:40 ` [PATCH 1/2] rename alloc_pages_exact() David Rientjes
1 sibling, 2 replies; 10+ messages in thread
From: Dave Hansen @ 2011-04-07 17:21 UTC (permalink / raw)
To: linux-mm
Cc: linux-kernel, Timur Tabi, Andi Kleen, Mel Gorman, Andrew Morton,
Dave Hansen
What I really wanted in the end was a highmem-capable alloc_pages_exact(),
so here it is.
It's a bit unfortunate that we have __free_pages_exact() and
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().
Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com>
---
linux-2.6.git-dave/drivers/video/pxafb.c | 4 -
linux-2.6.git-dave/include/linux/gfp.h | 4 +
linux-2.6.git-dave/kernel/profile.c | 4 -
linux-2.6.git-dave/mm/page_alloc.c | 81 +++++++++++++++++++++++--------
4 files changed, 69 insertions(+), 24 deletions(-)
diff -puN include/linux/gfp.h~make_new_alloc_pages_exact include/linux/gfp.h
--- linux-2.6.git/include/linux/gfp.h~make_new_alloc_pages_exact 2011-04-07 08:41:08.158387017 -0700
+++ linux-2.6.git-dave/include/linux/gfp.h 2011-04-07 08:41:08.174387016 -0700
@@ -351,6 +351,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, size_t);
+void __free_pages_exact(struct page *, size_t);
+/* virtual address version */
void *get_free_pages_exact(gfp_t gfp_mask, size_t size);
void free_pages_exact(void *virt, size_t size);
diff -puN mm/page_alloc.c~make_new_alloc_pages_exact mm/page_alloc.c
--- linux-2.6.git/mm/page_alloc.c~make_new_alloc_pages_exact 2011-04-07 08:41:08.162387016 -0700
+++ linux-2.6.git-dave/mm/page_alloc.c 2011-04-07 09:44:33.937537711 -0700
@@ -2318,36 +2318,83 @@ void free_pages(unsigned long addr, unsi
EXPORT_SYMBOL(free_pages);
/**
- * get_free_pages_exact - allocate an exact number physically-contiguous pages.
+ * __alloc_pages_exact - allocate an exact number physically-contiguous pages.
* @gfp_mask: GFP flags for the allocation
* @size: the number of bytes to allocate
+ * returns: struct page for allocated memory
*
- * This function is similar to __get_free_pages(), except that it allocates the
- * minimum number of pages to satisfy the request. get_free_pages() can only
+ * This function is similar to alloc_pages(), except that it allocates the
+ * minimum number of pages to satisfy the request. alloc_pages() can only
* allocate memory in power-of-two pages.
*
* This function is also limited by MAX_ORDER.
*
* Memory allocated by this function must be released by free_pages_exact().
*/
-void *get_free_pages_exact(gfp_t gfp_mask, size_t size)
+struct page *__alloc_pages_exact(gfp_t gfp_mask, size_t size)
{
unsigned int order = get_order(size);
- unsigned long addr;
+ struct page *page;
- addr = __get_free_pages(gfp_mask, order);
- if (addr) {
- unsigned long alloc_end = addr + (PAGE_SIZE << order);
- unsigned long used = addr + PAGE_ALIGN(size);
+ page = alloc_pages(gfp_mask, order);
+ if (page) {
+ struct page *alloc_end = page + (1 << order);
+ struct page *used = page + PAGE_ALIGN(size)/PAGE_SIZE;
- split_page(virt_to_page((void *)addr), order);
+ split_page(page, order);
while (used < alloc_end) {
- free_page(used);
- used += PAGE_SIZE;
+ __free_page(used);
+ used++;
}
}
- return (void *)addr;
+ return page;
+}
+EXPORT_SYMBOL(__alloc_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().
+ *
+ * Release the memory allocated by a previous call to __alloc_pages_exact().
+ */
+void __free_pages_exact(struct page *page, size_t size)
+{
+ struct page *end = page + PAGE_ALIGN(size)/PAGE_SIZE;
+
+ while (page < end) {
+ __free_page(page);
+ page++;
+ }
+}
+EXPORT_SYMBOL(__free_pages_exact);
+
+/**
+ * get_free_pages_exact - allocate an exact number physically-contiguous pages.
+ * @gfp_mask: GFP flags for the allocation
+ * @size: the number of bytes to allocate
+ * returns: virtual address of allocated memory
+ *
+ * This function is similar to __get_free_pages(), except that it allocates the
+ * minimum number of pages to satisfy the request. get_free_pages() can only
+ * allocate memory in power-of-two pages.
+ *
+ * This function is also limited by MAX_ORDER.
+ *
+ * Memory allocated by this function must be released by free_pages_exact().
+ */
+void *get_free_pages_exact(gfp_t gfp_mask, size_t size)
+{
+ struct page *page;
+
+ /* If we are using page_address(), we can not allow highmem */
+ VM_BUG_ON((gfp_mask & __GFP_HIGHMEM) != 0);
+
+ page = __alloc_pages_exact(gfp_mask, size);
+ if (page)
+ return (void *) page_address(page);
+ return NULL;
}
EXPORT_SYMBOL(get_free_pages_exact);
@@ -2360,13 +2407,7 @@ EXPORT_SYMBOL(get_free_pages_exact);
*/
void free_pages_exact(void *virt, size_t size)
{
- unsigned long addr = (unsigned long)virt;
- unsigned long end = addr + PAGE_ALIGN(size);
-
- while (addr < end) {
- free_page(addr);
- addr += PAGE_SIZE;
- }
+ __free_pages_exact(virt_to_page(virt), size);
}
EXPORT_SYMBOL(free_pages_exact);
diff -puN kernel/profile.c~make_new_alloc_pages_exact kernel/profile.c
--- linux-2.6.git/kernel/profile.c~make_new_alloc_pages_exact 2011-04-07 08:41:08.166387016 -0700
+++ linux-2.6.git-dave/kernel/profile.c 2011-04-07 09:42:16.393582339 -0700
@@ -121,8 +121,8 @@ int __ref profile_init(void)
if (prof_buffer)
return 0;
- prof_buffer = get_free_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;
diff -puN mm/swapfile.c~make_new_alloc_pages_exact mm/swapfile.c
diff -L git -puN /dev/null /dev/null
diff -puN include/linux/page-flags.h~make_new_alloc_pages_exact include/linux/page-flags.h
diff -puN drivers/video/pxafb.c~make_new_alloc_pages_exact drivers/video/pxafb.c
--- linux-2.6.git/drivers/video/pxafb.c~make_new_alloc_pages_exact 2011-04-07 09:42:40.805576050 -0700
+++ linux-2.6.git-dave/drivers/video/pxafb.c 2011-04-07 09:44:02.357555082 -0700
@@ -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 = get_free_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;
_
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] rename alloc_pages_exact()
2011-04-07 17:21 [PATCH 1/2] rename alloc_pages_exact() Dave Hansen
2011-04-07 17:21 ` [PATCH 2/2] make new alloc_pages_exact() Dave Hansen
@ 2011-04-07 21:40 ` David Rientjes
2011-04-07 21:58 ` Dave Hansen
1 sibling, 1 reply; 10+ messages in thread
From: David Rientjes @ 2011-04-07 21:40 UTC (permalink / raw)
To: Dave Hansen
Cc: linux-mm, linux-kernel, Timur Tabi, Andi Kleen, Mel Gorman,
Andrew Morton
On Thu, 7 Apr 2011, Dave Hansen wrote:
>
> 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().
>
The patch also reverses the arguments of the function in
include/linux/gfp.h, undoubtedly to resemble the (mask, order) appearance
of __get_free_pages():
-void *alloc_pages_exact(size_t size, gfp_t gfp_mask);
+void *get_free_pages_exact(gfp_t gfp_mask, size_t size);
> 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.
>
> Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com>
> Acked-by: Andi Kleen <ak@linux.intel.com>
> ---
>
> 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 | 4 ++--
> 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 | 2 +-
> linux-2.6.git-dave/mm/page_alloc.c | 24 ++++++++++++------------
> linux-2.6.git-dave/mm/page_cgroup.c | 2 +-
> 8 files changed, 20 insertions(+), 20 deletions(-)
>
> diff -puN drivers/video/fsl-diu-fb.c~change-alloc_pages_exact-name drivers/video/fsl-diu-fb.c
> --- linux-2.6.git/drivers/video/fsl-diu-fb.c~change-alloc_pages_exact-name 2011-04-07 08:37:58.074400957 -0700
> +++ linux-2.6.git-dave/drivers/video/fsl-diu-fb.c 2011-04-07 08:37:58.186400949 -0700
> @@ -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,
> diff -puN drivers/video/pxafb.c~change-alloc_pages_exact-name drivers/video/pxafb.c
> --- linux-2.6.git/drivers/video/pxafb.c~change-alloc_pages_exact-name 2011-04-07 08:37:58.078400957 -0700
> +++ linux-2.6.git-dave/drivers/video/pxafb.c 2011-04-07 08:39:16.198395385 -0700
> @@ -905,7 +905,7 @@ 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),
> + ofb->video_mem = get_free_pages_exact(PAGE_ALIGN(pxafb->video_mem_size),
> GFP_KERNEL | __GFP_ZERO);
> if (ofb->video_mem == NULL)
> return -ENOMEM;
Doesn't look like this is using the arguments in the newly changed order.
> @@ -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;
>
> diff -puN drivers/virtio/virtio_pci.c~change-alloc_pages_exact-name drivers/virtio/virtio_pci.c
> --- linux-2.6.git/drivers/virtio/virtio_pci.c~change-alloc_pages_exact-name 2011-04-07 08:37:58.082400957 -0700
> +++ linux-2.6.git-dave/drivers/virtio/virtio_pci.c 2011-04-07 08:37:58.190400949 -0700
> @@ -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;
> diff -puN include/linux/gfp.h~change-alloc_pages_exact-name include/linux/gfp.h
> --- linux-2.6.git/include/linux/gfp.h~change-alloc_pages_exact-name 2011-04-07 08:37:58.086400956 -0700
> +++ linux-2.6.git-dave/include/linux/gfp.h 2011-04-07 08:37:58.190400949 -0700
> @@ -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) \
> diff -puN kernel/profile.c~change-alloc_pages_exact-name kernel/profile.c
> --- linux-2.6.git/kernel/profile.c~change-alloc_pages_exact-name 2011-04-07 08:37:58.090400955 -0700
> +++ linux-2.6.git-dave/kernel/profile.c 2011-04-07 08:37:58.190400949 -0700
> @@ -121,7 +121,7 @@ int __ref profile_init(void)
> if (prof_buffer)
> return 0;
>
> - prof_buffer = alloc_pages_exact(buffer_bytes,
> + prof_buffer = get_free_pages_exact(buffer_bytes,
> GFP_KERNEL|__GFP_ZERO|__GFP_NOWARN);
> if (prof_buffer)
> return 0;
Here either.
Everything else looks good, so once these are corrected:
Acked-by: David Rientjes <rientjes@google.com>
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] rename alloc_pages_exact()
2011-04-07 21:40 ` [PATCH 1/2] rename alloc_pages_exact() David Rientjes
@ 2011-04-07 21:58 ` Dave Hansen
0 siblings, 0 replies; 10+ messages in thread
From: Dave Hansen @ 2011-04-07 21:58 UTC (permalink / raw)
To: David Rientjes
Cc: linux-mm, linux-kernel, Timur Tabi, Andi Kleen, Mel Gorman,
Andrew Morton
On Thu, 2011-04-07 at 14:40 -0700, David Rientjes wrote:
> > 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().
> >
>
> The patch also reverses the arguments of the function in
> include/linux/gfp.h, undoubtedly to resemble the (mask, order) appearance
> of __get_free_pages():
>
> -void *alloc_pages_exact(size_t size, gfp_t gfp_mask);
> +void *get_free_pages_exact(gfp_t gfp_mask, size_t size);
Thanks. I dumped the fixes for that in the second patch. Whoops. Will
repost.
-- Dave
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] make new alloc_pages_exact()
2011-04-07 17:21 ` [PATCH 2/2] make new alloc_pages_exact() Dave Hansen
@ 2011-04-07 22:03 ` David Rientjes
2011-04-07 22:17 ` Dave Hansen
2011-04-08 12:28 ` Michal Nazarewicz
1 sibling, 1 reply; 10+ messages in thread
From: David Rientjes @ 2011-04-07 22:03 UTC (permalink / raw)
To: Dave Hansen
Cc: linux-mm, linux-kernel, Timur Tabi, Andi Kleen, Mel Gorman,
Andrew Morton
On Thu, 7 Apr 2011, Dave Hansen wrote:
>
> What I really wanted in the end was a highmem-capable alloc_pages_exact(),
> so here it is.
>
Perhaps expand upon how the new alloc_pages_exact() works and what it will
be used for instead of only talking about how it's named?
> It's a bit unfortunate that we have __free_pages_exact() and
> 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().
>
> Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com>
> ---
>
> linux-2.6.git-dave/drivers/video/pxafb.c | 4 -
> linux-2.6.git-dave/include/linux/gfp.h | 4 +
> linux-2.6.git-dave/kernel/profile.c | 4 -
> linux-2.6.git-dave/mm/page_alloc.c | 81 +++++++++++++++++++++++--------
> 4 files changed, 69 insertions(+), 24 deletions(-)
>
> diff -puN include/linux/gfp.h~make_new_alloc_pages_exact include/linux/gfp.h
> --- linux-2.6.git/include/linux/gfp.h~make_new_alloc_pages_exact 2011-04-07 08:41:08.158387017 -0700
> +++ linux-2.6.git-dave/include/linux/gfp.h 2011-04-07 08:41:08.174387016 -0700
> @@ -351,6 +351,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, size_t);
> +void __free_pages_exact(struct page *, size_t);
They're not required, but these should have the names of the arguments
like the other prototypes in this file.
> +/* virtual address version */
> void *get_free_pages_exact(gfp_t gfp_mask, size_t size);
> void free_pages_exact(void *virt, size_t size);
>
> diff -puN mm/page_alloc.c~make_new_alloc_pages_exact mm/page_alloc.c
> --- linux-2.6.git/mm/page_alloc.c~make_new_alloc_pages_exact 2011-04-07 08:41:08.162387016 -0700
> +++ linux-2.6.git-dave/mm/page_alloc.c 2011-04-07 09:44:33.937537711 -0700
> @@ -2318,36 +2318,83 @@ void free_pages(unsigned long addr, unsi
> EXPORT_SYMBOL(free_pages);
>
> /**
> - * get_free_pages_exact - allocate an exact number physically-contiguous pages.
> + * __alloc_pages_exact - allocate an exact number physically-contiguous pages.
> * @gfp_mask: GFP flags for the allocation
> * @size: the number of bytes to allocate
> + * returns: struct page for allocated memory
> *
> - * This function is similar to __get_free_pages(), except that it allocates the
> - * minimum number of pages to satisfy the request. get_free_pages() can only
> + * This function is similar to alloc_pages(), except that it allocates the
> + * minimum number of pages to satisfy the request. alloc_pages() can only
> * allocate memory in power-of-two pages.
> *
> * This function is also limited by MAX_ORDER.
> *
> * Memory allocated by this function must be released by free_pages_exact().
> */
> -void *get_free_pages_exact(gfp_t gfp_mask, size_t size)
> +struct page *__alloc_pages_exact(gfp_t gfp_mask, size_t size)
> {
> unsigned int order = get_order(size);
> - unsigned long addr;
> + struct page *page;
>
> - addr = __get_free_pages(gfp_mask, order);
> - if (addr) {
> - unsigned long alloc_end = addr + (PAGE_SIZE << order);
> - unsigned long used = addr + PAGE_ALIGN(size);
> + page = alloc_pages(gfp_mask, order);
> + if (page) {
> + struct page *alloc_end = page + (1 << order);
> + struct page *used = page + PAGE_ALIGN(size)/PAGE_SIZE;
Wouldn't it better to call this "unused" rather than "used" since it
represents a cursor over pages that we want to free?
>
> - split_page(virt_to_page((void *)addr), order);
> + split_page(page, order);
> while (used < alloc_end) {
> - free_page(used);
> - used += PAGE_SIZE;
> + __free_page(used);
> + used++;
> }
> }
>
> - return (void *)addr;
> + return page;
> +}
> +EXPORT_SYMBOL(__alloc_pages_exact);
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] make new alloc_pages_exact()
2011-04-07 22:03 ` David Rientjes
@ 2011-04-07 22:17 ` Dave Hansen
0 siblings, 0 replies; 10+ messages in thread
From: Dave Hansen @ 2011-04-07 22:17 UTC (permalink / raw)
To: David Rientjes
Cc: linux-mm, linux-kernel, Timur Tabi, Andi Kleen, Mel Gorman,
Andrew Morton
On Thu, 2011-04-07 at 15:03 -0700, David Rientjes wrote:
> On Thu, 7 Apr 2011, Dave Hansen wrote:
> > What I really wanted in the end was a highmem-capable alloc_pages_exact(),
> > so here it is.
>
> Perhaps expand upon how the new alloc_pages_exact() works and what it will
> be used for instead of only talking about how it's named?
Will do.
> > +/* 'struct page' version */
> > +struct page *__alloc_pages_exact(gfp_t, size_t);
> > +void __free_pages_exact(struct page *, size_t);
>
> They're not required, but these should have the names of the arguments
> like the other prototypes in this file.
Fair enough.
> > - addr = __get_free_pages(gfp_mask, order);
> > - if (addr) {
> > - unsigned long alloc_end = addr + (PAGE_SIZE << order);
> > - unsigned long used = addr + PAGE_ALIGN(size);
> > + page = alloc_pages(gfp_mask, order);
> > + if (page) {
> > + struct page *alloc_end = page + (1 << order);
> > + struct page *used = page + PAGE_ALIGN(size)/PAGE_SIZE;
>
> Wouldn't it better to call this "unused" rather than "used" since it
> represents a cursor over pages that we want to free?
Yeah, agreed. I think I screwed this up once when coding this because I
misread it. I'll change it.
-- Dave
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] make new alloc_pages_exact()
2011-04-07 17:21 ` [PATCH 2/2] make new alloc_pages_exact() Dave Hansen
2011-04-07 22:03 ` David Rientjes
@ 2011-04-08 12:28 ` Michal Nazarewicz
2011-04-08 13:19 ` Dave Hansen
2011-04-08 22:06 ` Dave Hansen
1 sibling, 2 replies; 10+ messages in thread
From: Michal Nazarewicz @ 2011-04-08 12:28 UTC (permalink / raw)
To: linux-mm, Dave Hansen
Cc: linux-kernel, Timur Tabi, Andi Kleen, Mel Gorman, Andrew Morton
On Thu, 07 Apr 2011 19:21:05 +0200, Dave Hansen <dave@linux.vnet.ibm.com>
wrote:
> +struct page *__alloc_pages_exact(gfp_t gfp_mask, size_t size)
> {
> unsigned int order = get_order(size);
> - unsigned long addr;
> + struct page *page;
> - addr = __get_free_pages(gfp_mask, order);
> - if (addr) {
> - unsigned long alloc_end = addr + (PAGE_SIZE << order);
> - unsigned long used = addr + PAGE_ALIGN(size);
> + page = alloc_pages(gfp_mask, order);
> + if (page) {
> + struct page *alloc_end = page + (1 << order);
> + struct page *used = page + PAGE_ALIGN(size)/PAGE_SIZE;
> - split_page(virt_to_page((void *)addr), order);
> + split_page(page, order);
> while (used < alloc_end) {
> - free_page(used);
> - used += PAGE_SIZE;
> + __free_page(used);
> + used++;
> }
Have you thought about moving this loop to a separate function, ie.
_free_page_range(start, end)? I'm asking because this loop appears
in two places and my CMA would also benefit from such a function.
> }
> - return (void *)addr;
> + return page;
> +}
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +-----<email/xmpp: mnazarewicz@google.com>-----ooO--(_)--Ooo--
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] make new alloc_pages_exact()
2011-04-08 12:28 ` Michal Nazarewicz
@ 2011-04-08 13:19 ` Dave Hansen
2011-04-08 13:23 ` Michal Nazarewicz
2011-04-08 22:06 ` Dave Hansen
1 sibling, 1 reply; 10+ messages in thread
From: Dave Hansen @ 2011-04-08 13:19 UTC (permalink / raw)
To: Michal Nazarewicz
Cc: linux-mm, linux-kernel, Timur Tabi, Andi Kleen, Mel Gorman,
Andrew Morton
On Fri, 2011-04-08 at 14:28 +0200, Michal Nazarewicz wrote:
> On Thu, 07 Apr 2011 19:21:05 +0200, Dave Hansen <dave@linux.vnet.ibm.com>
> wrote:
> > +struct page *__alloc_pages_exact(gfp_t gfp_mask, size_t size)
> > {
> > unsigned int order = get_order(size);
> > - unsigned long addr;
> > + struct page *page;
> > - addr = __get_free_pages(gfp_mask, order);
> > - if (addr) {
> > - unsigned long alloc_end = addr + (PAGE_SIZE << order);
> > - unsigned long used = addr + PAGE_ALIGN(size);
> > + page = alloc_pages(gfp_mask, order);
> > + if (page) {
> > + struct page *alloc_end = page + (1 << order);
> > + struct page *used = page + PAGE_ALIGN(size)/PAGE_SIZE;
> > - split_page(virt_to_page((void *)addr), order);
> > + split_page(page, order);
> > while (used < alloc_end) {
> > - free_page(used);
> > - used += PAGE_SIZE;
> > + __free_page(used);
> > + used++;
> > }
>
> Have you thought about moving this loop to a separate function, ie.
> _free_page_range(start, end)? I'm asking because this loop appears
> in two places and my CMA would also benefit from such a function.
Sounds like a good idea to me. Were you thinking start/end 'struct
page's as arguments?
-- Dave
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] make new alloc_pages_exact()
2011-04-08 13:19 ` Dave Hansen
@ 2011-04-08 13:23 ` Michal Nazarewicz
0 siblings, 0 replies; 10+ messages in thread
From: Michal Nazarewicz @ 2011-04-08 13:23 UTC (permalink / raw)
To: Dave Hansen
Cc: linux-mm, linux-kernel, Timur Tabi, Andi Kleen, Mel Gorman,
Andrew Morton
>> On Thu, 07 Apr 2011 19:21:05 +0200, Dave Hansen wrote:
>>> while (used < alloc_end) {
>>> - free_page(used);
>>> - used += PAGE_SIZE;
>>> + __free_page(used);
>>> + used++;
>>> }
> On Fri, 2011-04-08 at 14:28 +0200, Michal Nazarewicz wrote:
>> Have you thought about moving this loop to a separate function, ie.
>> _free_page_range(start, end)? I'm asking because this loop appears
>> in two places and my CMA would also benefit from such a function.
On Fri, 08 Apr 2011 15:19:46 +0200, Dave Hansen wrote:
> Sounds like a good idea to me. Were you thinking start/end 'struct
> page's as arguments?
Either that or (struct page *start, unsigned nr_pages).
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +-----<email/xmpp: mnazarewicz@google.com>-----ooO--(_)--Ooo--
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] make new alloc_pages_exact()
2011-04-08 12:28 ` Michal Nazarewicz
2011-04-08 13:19 ` Dave Hansen
@ 2011-04-08 22:06 ` Dave Hansen
1 sibling, 0 replies; 10+ messages in thread
From: Dave Hansen @ 2011-04-08 22:06 UTC (permalink / raw)
To: Michal Nazarewicz
Cc: linux-mm, linux-kernel, Timur Tabi, Andi Kleen, Mel Gorman,
Andrew Morton
On Fri, 2011-04-08 at 14:28 +0200, Michal Nazarewicz wrote:
> On Thu, 07 Apr 2011 19:21:05 +0200, Dave Hansen <dave@linux.vnet.ibm.com>
> > + struct page *alloc_end = page + (1 << order);
> > + struct page *used = page + PAGE_ALIGN(size)/PAGE_SIZE;
> > - split_page(virt_to_page((void *)addr), order);
> > + split_page(page, order);
> > while (used < alloc_end) {
> > - free_page(used);
> > - used += PAGE_SIZE;
> > + __free_page(used);
> > + used++;
> > }
>
> Have you thought about moving this loop to a separate function, ie.
> _free_page_range(start, end)? I'm asking because this loop appears
> in two places and my CMA would also benefit from such a function.
It's actually perilously close to free_pages_exact(). I'll try to make
it usable for this case as well.
-- Dave
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-04-08 22:07 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-07 17:21 [PATCH 1/2] rename alloc_pages_exact() Dave Hansen
2011-04-07 17:21 ` [PATCH 2/2] make new alloc_pages_exact() Dave Hansen
2011-04-07 22:03 ` David Rientjes
2011-04-07 22:17 ` Dave Hansen
2011-04-08 12:28 ` Michal Nazarewicz
2011-04-08 13:19 ` Dave Hansen
2011-04-08 13:23 ` Michal Nazarewicz
2011-04-08 22:06 ` Dave Hansen
2011-04-07 21:40 ` [PATCH 1/2] rename alloc_pages_exact() David Rientjes
2011-04-07 21:58 ` Dave Hansen
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).