Re: [PATCH V2 1/1] mm: introduce kvmalloc()/kvfree()

From: Pekka Enberg
Date: Tue Nov 18 2008 - 01:57:19 EST


On Mon, Nov 17, 2008 at 2:26 PM, Lai Jiangshan <laijs@xxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxxx
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/