lkml.org 
[lkml]   [2008]   [Nov]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH V2 1/1] mm: introduce kvmalloc()/kvfree()
On Mon, Nov 17, 2008 at 2:26 PM, Lai Jiangshan <laijs@cn.fujitsu.com> wrote:
> @@ -163,6 +165,38 @@ char *strndup_user(const char __user *s, long n)
> }
> EXPORT_SYMBOL(strndup_user);
>
> +/**
> + * kvmalloc - allocate memory by kmalloc() or vmalloc()
> + *
> + * if @size <= PAGE_SIZE, memory is allocated by kmalloc(),
> + * otherwise by vmalloc().
> + *
> + * NOTICE: Generally, you should use kmalloc() or vmalloc() directly.
> + * kvmalloc() is provided for some special condition.

You might as well explicitly state what those special conditions are here.

> + */
> +void *kvmalloc(unsigned long size, gfp_t flags)
> +{
> + if (size <= PAGE_SIZE)
> + return kmalloc(size, flags & ~__GFP_HIGH);
> + else
> + return __vmalloc(size, flags | __GFP_HIGHMEM, PAGE_KERNEL);
> +}
> +EXPORT_SYMBOL(kvmalloc);
> +
> +/**
> + * kvfree - free the memory by kfree(), or vfree() if it is vmalloc addr
> + */
> +void kvfree(void *ptr)
> +{
> + BUG_ON(in_interrupt());

I wonder if this should be a WARN_ON() to let the machine limp along
for a while if it can. At least in the kfree() case people can catch
the oops trace more easily that way.

> +
> + if (is_vmalloc_addr(ptr))
> + vfree(ptr);
> + else
> + kfree(ptr);
> +}
> +EXPORT_SYMBOL(kvfree);
> +
> #ifndef HAVE_ARCH_PICK_MMAP_LAYOUT
> void arch_pick_mmap_layout(struct mm_struct *mm)
> {
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>


\
 
 \ /
  Last update: 2008-11-18 07:59    [W:0.071 / U:22.716 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site