From: Christoph Lameter <clameter@sgi.com>
To: akpm@linux-foundation.org
Cc: linux-mm@kvack.org
Subject: [patch 08/14] vunmap: return page array passed on vmap()
Date: Tue, 25 Sep 2007 16:25:51 -0700 [thread overview]
Message-ID: <20070925233007.302199268@sgi.com> (raw)
In-Reply-To: 20070925232543.036615409@sgi.com
[-- Attachment #1: vcompound_vunmap_returns_pages --]
[-- Type: text/plain, Size: 4607 bytes --]
Make vunmap return the page array that was used at vmap. This is useful
if one has no structures to track the page array but simply stores the
virtual address somewhere. The disposition of the page array can be
decided upon after vunmap. vfree() may now also be used instead of
vunmap which will release the page array after vunmap'ping it.
As noted by Kamezawa: The same subsystem that provides the page array
to vmap must must use its own method to dispose of the page array.
If vfree() is called to free the page array passed to vmap() [We currently
do not do that] then the page array must either be
1. Allocated via the slab allocator
2. Allocated via vmalloc but then VM_VPAGES must have been passed at
vunmap to specify that a vfree is needed.
RFC->v1:
- Add comment explaining how to use vfree() to dispose of the page
array passed on vmap().
Signed-off-by: Christoph Lameter <clameter@sgi.com>
---
include/linux/vmalloc.h | 2 +-
mm/vmalloc.c | 33 +++++++++++++++++++++++----------
2 files changed, 24 insertions(+), 11 deletions(-)
Index: linux-2.6.23-rc8-mm1/include/linux/vmalloc.h
===================================================================
--- linux-2.6.23-rc8-mm1.orig/include/linux/vmalloc.h 2007-09-25 15:02:59.000000000 -0700
+++ linux-2.6.23-rc8-mm1/include/linux/vmalloc.h 2007-09-25 15:03:06.000000000 -0700
@@ -49,7 +49,7 @@ extern void vfree(const void *addr);
extern void *vmap(struct page **pages, unsigned int count,
unsigned long flags, pgprot_t prot);
-extern void vunmap(const void *addr);
+extern struct page **vunmap(const void *addr);
extern int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
unsigned long pgoff);
Index: linux-2.6.23-rc8-mm1/mm/vmalloc.c
===================================================================
--- linux-2.6.23-rc8-mm1.orig/mm/vmalloc.c 2007-09-25 15:03:05.000000000 -0700
+++ linux-2.6.23-rc8-mm1/mm/vmalloc.c 2007-09-25 15:03:06.000000000 -0700
@@ -357,17 +357,18 @@ struct vm_struct *remove_vm_area(const v
return v;
}
-static void __vunmap(const void *addr, int deallocate_pages)
+static struct page **__vunmap(const void *addr, int deallocate_pages)
{
struct vm_struct *area;
+ struct page **pages;
if (!addr)
- return;
+ return NULL;
if ((PAGE_SIZE-1) & (unsigned long)addr) {
printk(KERN_ERR "Trying to vfree() bad address (%p)\n", addr);
WARN_ON(1);
- return;
+ return NULL;
}
area = remove_vm_area(addr);
@@ -375,29 +376,30 @@ static void __vunmap(const void *addr, i
printk(KERN_ERR "Trying to vfree() nonexistent vm area (%p)\n",
addr);
WARN_ON(1);
- return;
+ return NULL;
}
+ pages = area->pages;
debug_check_no_locks_freed(addr, area->size);
if (deallocate_pages) {
int i;
for (i = 0; i < area->nr_pages; i++) {
- struct page *page = area->pages[i];
+ struct page *page = pages[i];
BUG_ON(!page);
__free_page(page);
}
if (area->flags & VM_VPAGES)
- vfree(area->pages);
+ vfree(pages);
else
- kfree(area->pages);
+ kfree(pages);
}
kfree(area);
- return;
+ return pages;
}
/**
@@ -425,11 +427,13 @@ EXPORT_SYMBOL(vfree);
* which was created from the page array passed to vmap().
*
* Must not be called in interrupt context.
+ *
+ * Returns a pointer to the array of pointers to page structs
*/
-void vunmap(const void *addr)
+struct page **vunmap(const void *addr)
{
BUG_ON(in_interrupt());
- __vunmap(addr, 0);
+ return __vunmap(addr, 0);
}
EXPORT_SYMBOL(vunmap);
@@ -442,6 +446,13 @@ EXPORT_SYMBOL(vunmap);
*
* Maps @count pages from @pages into contiguous kernel virtual
* space.
+ *
+ * The page array may be freed via vfree() with the virtual address
+ * returned from vmap. In that case the page array must be allocated via
+ * the slab allocator. If the page array was allocated via
+ * vmalloc then VM_VPAGES must be specified in the flags. There is
+ * no support for vfree() freeing pages allocated via the
+ * page allocator.
*/
void *vmap(struct page **pages, unsigned int count,
unsigned long flags, pgprot_t prot)
@@ -454,6 +465,8 @@ void *vmap(struct page **pages, unsigned
area = get_vm_area((count << PAGE_SHIFT), flags);
if (!area)
return NULL;
+ area->pages = pages;
+ area->nr_pages = count;
if (map_vm_area(area, prot, &pages)) {
vunmap(area->addr);
return NULL;
--
--
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>
next prev parent reply other threads:[~2007-09-25 23:25 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-25 23:25 [patch 00/14] Misc cleanups / fixes Christoph Lameter
2007-09-25 23:25 ` [patch 01/14] Pagecache zeroing: zero_user_segment, zero_user_segments and zero_user Christoph Lameter
2007-09-25 23:25 ` [patch 02/14] Reiser4 portion of zero_user cleanup patch Christoph Lameter
2007-09-25 23:25 ` [patch 03/14] Move vmalloc_to_page() to mm/vmalloc Christoph Lameter
2007-09-25 23:25 ` [patch 04/14] vmalloc: add const to void ..tmp_kallsyms1.o.cmd ..tmp_kallsyms2.o.cmd ..tmp_vmlinux1.cmd ..tmp_vmlinux2.cmd .cf .cf1 .cf2 .cf3 .cfnet .config .config.old .gitignore .mailmap .missing-syscalls.d .pc .tmp_System.map .tmp_kallsyms1.S .tmp_kallsyms1.o .tmp_kallsyms2.S .tmp_kallsyms2.o .tmp_versions .tmp_vmlinux1 .tmp_vmlinux2 .version .vmlinux.cmd .vmlinux.o.cmd COPYING CREDITS Documentation Kbuild MAINTAINERS Makefile Module.symvers README REPORTING-BUGS System.map arch b block crypto drivers fs include init ipc kernel lib linux-2.6.23-rc8-mm1.tar.gz mips mm net patches scripts security sound tar-install test test_out usr vmlinux vmlinux.gz vmlinux.o vmlinux.sym xx parameters Christoph Lameter
2007-09-25 23:25 ` [patch 05/14] i386: Resolve dependency of asm-i386/pgtable.h on highmem.h Christoph Lameter
2007-09-25 23:25 ` [patch 06/14] is_vmalloc_addr(): Check if an address is within the vmalloc boundaries Christoph Lameter
2007-09-25 23:25 ` [patch 07/14] vmalloc: Clean up page array indexing Christoph Lameter
2007-09-25 23:25 ` Christoph Lameter [this message]
2007-09-25 23:25 ` [patch 09/14] SLUB: Move count_partial() Christoph Lameter
2007-09-25 23:25 ` [patch 10/14] SLUB: Rename NUMA defrag_ratio to remote_node_defrag_ratio Christoph Lameter
2007-09-25 23:25 ` [patch 11/14] SLUB: Consolidate add_partial() and add_partial_tail() to one function Christoph Lameter
2007-09-25 23:25 ` [patch 12/14] VM: Allow get_page_unless_zero on compound pages Christoph Lameter
2007-09-25 23:25 ` [patch 13/14] dentries: Extract common code to remove dentry from lru Christoph Lameter
2007-10-22 21:29 ` Andrew Morton
2007-10-25 2:23 ` Christoph Lameter
2007-10-25 2:34 ` Andrew Morton
2007-10-25 2:50 ` Christoph Lameter
2007-10-25 3:03 ` Andrew Morton
2007-09-25 23:25 ` [patch 14/14] bufferhead: Revert constructor removal Christoph Lameter
2007-10-22 21:31 ` Andrew Morton
2007-10-25 2:25 ` Christoph Lameter
2007-09-27 20:25 ` [patch 00/14] Misc cleanups / fixes Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070925233007.302199268@sgi.com \
--to=clameter@sgi.com \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).