lkml.org 
[lkml]   [2010]   [May]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] fs: use kmalloc() to allocate fdmem if possible
From
Date
Le lundi 03 mai 2010 à 11:49 +0300, Avi Kivity a écrit :

> A kmalloc()ed page is virtually contiguous, satisfying your requirement.
>

Still, a different function pair is needed, at least for documentation
reasons.

Changli, _many_ patches like yours were suggested and refused in the
past for the reason it should be generic. Maybe its time...

So first introduce a pair of funtions, then we can use them.

At free time we can use is_vmalloc_addr() so that no extra bit is needed
to tell if a zone was vmalloced() or kmalloced()


One remark :

+ data = kmalloc(size, GFP_KERNEL);

If allocation fails (because of fragmentation), we would have a kernel
log.
Still, vmalloc() might be OK.
So you should add a __GFP_NOWARN flag.




/*
* 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);
}

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-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: 2010-05-03 11:17    [W:0.074 / U:1.224 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site