Re: [PATCH] fs: use kmalloc() to allocate fdmem if possible

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 3, 2010 at 5:13 PM, Eric Dumazet <eric.dumazet@xxxxxxxxx> wrote:
>
> /*
>  * Warning: if size is not a power of two, kmalloc() might
>  * waste memory because of its requirements.
>  */
> void *kvmalloc(size_t size)
> {
>        void *ptr = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
>
>        if (ptr)
>                return ptr;
>        return vmalloc(size);
> }

we can use alloc_pages_exact()/free_pages_exact() when size is larger
than PAGE_SIZE, then size isn't needed to be a power of two.

void *kvmalloc(size_t size)
{
      void *ptr;

      if (size < PAGE_SIZE)
          return kmalloc(size, GFP_KERNEL);
      ptr = alloc_pages_exact(size, GFP_KERNEL | __GFP_NOWARN);
      if (ptr)
          return ptr;
      return vmalloc(size);
}

void *kvfree(void *ptr, size_t size)
{
       BUG_ON(in_interrupt());
       if (size < PAGE_SIZE)
            kfree(ptr);
       else if (is_vmalloc_addr(ptr))
            vfree(ptr);
       else
            free_pages_exact(ptr, size);
}

>
> void kvfree(void *ptr)
> {
>        BUG_ON(in_interrupt());
>        if (is_vmalloc_addr(ptr))
>                vfree(ptr);
>        else
>                kfree(ptr);
> }
>
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux