public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] vmalloc: introduce __vmalloc_area() function
@ 2005-03-06 18:56 Oleg Nesterov
  2005-03-22  9:52 ` Russell King
  0 siblings, 1 reply; 2+ messages in thread
From: Oleg Nesterov @ 2005-03-06 18:56 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andi Kleen, David S. Miller, Russell King, Rusty Russell,
	Andrew Morton

There are 3 copy-and-paste implementations of __vmalloc() in
arch/{arm,sparc64,x86_64}/kernel/module.c.

I believe the only reason is that __vmalloc() doesn't allow
to specify parameters of __get_vm_area().

This patch splits __vmalloc() into 2 functions. The new one,
__vmalloc_area(), can be used as follows:

	vm_struct *area = __get_vm_area(...);
	void *addr = __vmalloc_area(area, gfp, prot);

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- 2.6.11/include/linux/0_vmalloc.h	2005-01-12 15:07:10.000000000 +0300
+++ 2.6.11/include/linux/vmalloc.h	2005-03-06 19:39:05.000000000 +0300
@@ -27,6 +27,7 @@ extern void *vmalloc(unsigned long size)
 extern void *vmalloc_exec(unsigned long size);
 extern void *vmalloc_32(unsigned long size);
 extern void *__vmalloc(unsigned long size, int gfp_mask, pgprot_t prot);
+extern void *__vmalloc_area(struct vm_struct *area, int gfp_mask, pgprot_t prot);
 extern void vfree(void *addr);
 
 extern void *vmap(struct page **pages, unsigned int count,
--- 2.6.11/mm/0_vmalloc.c	2005-02-24 22:15:03.000000000 +0300
+++ 2.6.11/mm/vmalloc.c	2005-03-06 20:31:01.000000000 +0300
@@ -456,32 +456,12 @@ void *vmap(struct page **pages, unsigned
 
 EXPORT_SYMBOL(vmap);
 
-/**
- *	__vmalloc  -  allocate virtually contiguous memory
- *
- *	@size:		allocation size
- *	@gfp_mask:	flags for the page level allocator
- *	@prot:		protection mask for the allocated pages
- *
- *	Allocate enough pages to cover @size from the page level
- *	allocator with @gfp_mask flags.  Map them into contiguous
- *	kernel virtual space, using a pagetable protection of @prot.
- */
-void *__vmalloc(unsigned long size, int gfp_mask, pgprot_t prot)
+void *__vmalloc_area(struct vm_struct *area, int gfp_mask, pgprot_t prot)
 {
-	struct vm_struct *area;
 	struct page **pages;
 	unsigned int nr_pages, array_size, i;
 
-	size = PAGE_ALIGN(size);
-	if (!size || (size >> PAGE_SHIFT) > num_physpages)
-		return NULL;
-
-	area = get_vm_area(size, VM_ALLOC);
-	if (!area)
-		return NULL;
-
-	nr_pages = size >> PAGE_SHIFT;
+	nr_pages = (area->size - PAGE_SIZE) >> PAGE_SHIFT;
 	array_size = (nr_pages * sizeof(struct page *));
 
 	area->nr_pages = nr_pages;
@@ -506,7 +486,7 @@ void *__vmalloc(unsigned long size, int 
 			goto fail;
 		}
 	}
-	
+
 	if (map_vm_area(area, prot, &pages))
 		goto fail;
 	return area->addr;
@@ -516,6 +496,32 @@ fail:
 	return NULL;
 }
 
+/**
+ *	__vmalloc  -  allocate virtually contiguous memory
+ *
+ *	@size:		allocation size
+ *	@gfp_mask:	flags for the page level allocator
+ *	@prot:		protection mask for the allocated pages
+ *
+ *	Allocate enough pages to cover @size from the page level
+ *	allocator with @gfp_mask flags.  Map them into contiguous
+ *	kernel virtual space, using a pagetable protection of @prot.
+ */
+void *__vmalloc(unsigned long size, int gfp_mask, pgprot_t prot)
+{
+	struct vm_struct *area;
+
+	size = PAGE_ALIGN(size);
+	if (!size || (size >> PAGE_SHIFT) > num_physpages)
+		return NULL;
+
+	area = get_vm_area(size, VM_ALLOC);
+	if (!area)
+		return NULL;
+
+	return __vmalloc_area(area, gfp_mask, prot);
+}
+
 EXPORT_SYMBOL(__vmalloc);
 
 /**

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/5] vmalloc: introduce __vmalloc_area() function
  2005-03-06 18:56 [PATCH 1/5] vmalloc: introduce __vmalloc_area() function Oleg Nesterov
@ 2005-03-22  9:52 ` Russell King
  0 siblings, 0 replies; 2+ messages in thread
From: Russell King @ 2005-03-22  9:52 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: linux-kernel, Andi Kleen, David S. Miller, Rusty Russell,
	Andrew Morton

On Sun, Mar 06, 2005 at 09:56:35PM +0300, Oleg Nesterov wrote:
> There are 3 copy-and-paste implementations of __vmalloc() in
> arch/{arm,sparc64,x86_64}/kernel/module.c.

There is actually a similar copy in arch/arm/mm/consistent.c, but at the
time I cleaned it up to be something saner.  With some tweaks (such as
adding a struct vm_region_head which contains the spinlock, as well as
the start/end and list) we essentially end up with a generic memory
region allocator suitable for vmalloc, ioremap, module stuff, and so
forth.

If anyone's interested in that, I'll sort out those tweaks.

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-03-22  9:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-06 18:56 [PATCH 1/5] vmalloc: introduce __vmalloc_area() function Oleg Nesterov
2005-03-22  9:52 ` Russell King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox