From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] fs: use kmalloc() to allocate fdmem if possible Date: Mon, 03 May 2010 09:06:18 +0300 Message-ID: <4BDE67DA.4080004@redhat.com> References: <1272818776-7729-1-git-send-email-xiaosuo@gmail.com> <4BDDB6E9.4060703@redhat.com> <201005030915.FCD09385.FFHVOMJtSLOFQO@I-love.SAKURA.ne.jp> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: xiaosuo@gmail.com, jslaby@suse.cz, akpm@linux-foundation.org, paulmck@linux.vnet.ibm.com, adobriyan@gmail.com, mingo@elte.hu, peterz@infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org To: Tetsuo Handa Return-path: Received: from mx1.redhat.com ([209.132.183.28]:1586 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753211Ab0ECGHG (ORCPT ); Mon, 3 May 2010 02:07:06 -0400 In-Reply-To: <201005030915.FCD09385.FFHVOMJtSLOFQO@I-love.SAKURA.ne.jp> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On 05/03/2010 03:15 AM, Tetsuo Handa wrote: > Avi Kivity wrote: > >> On 05/02/2010 07:46 PM, Changli Gao wrote: >> >>> use kmalloc() to allocate fdmem if possible. >>> >>> vmalloc() is used as a fallback solution for fdmem allocation. Two members are >>> added into the hole of the structure fdtable to indicate if vmalloc() is used >>> or not. >>> >>> >>> diff --git a/fs/file.c b/fs/file.c >>> index 34bb7f7..f71dd85 100644 >>> --- a/fs/file.c >>> +++ b/fs/file.c >>> @@ -39,28 +39,34 @@ int sysctl_nr_open_max = 1024 * 1024; /* raised later */ >>> */ >>> static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); >>> >>> -static inline void * alloc_fdmem(unsigned int size) >>> +static inline void *alloc_fdmem(unsigned int size, unsigned short *use_vmalloc) >>> { >>> - if (size<= PAGE_SIZE) >>> - return kmalloc(size, GFP_KERNEL); >>> - else >>> - return vmalloc(size); >>> + void *data; >>> + >>> + data = kmalloc(size, GFP_KERNEL); >>> + if (data != NULL) { >>> + *use_vmalloc = 0; >>> + return data; >>> + } >>> + *use_vmalloc = 1; >>> + >>> + return vmalloc(size); >>> } >>> >>> >> Perhaps vmalloc() should do this by itself? vfree() can examine the >> pointer and call kfree() if it isn't within the vmalloc address range. >> > You can use is_vmalloc_addr(). > > if (is_vmalloc_addr(p)) > vfree(p); > else > kfree(p); > My point is, vmalloc() and vfree should do this, not their callers: vmalloc(size): if (size <= PAGE_SIZE) return kmalloc(size, GFP_KERNEL); ... vfree(p): if (!is_vmalloc_addr(p) { kfree(p); return; } ... -- Do not meddle in the internals of kernels, for they are subtle and quick to panic.