From mboxrd@z Thu Jan 1 00:00:00 1970 From: Changli Gao Subject: Re: [RFC] mm: generic adaptive large memory allocation APIs Date: Thu, 6 May 2010 09:25:38 +0800 Message-ID: References: <1273105838-4441-1-git-send-email-xiaosuo@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Eric Dumazet , Jiri Slaby , Changli Gao , Alexander Viro , "Paul E. McKenney" , Alexey Dobriyan , Ingo Molnar , Peter Zijlstra , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Avi Kivity , Tetsuo Handa To: akpm@linux-foundation.org Return-path: In-Reply-To: <1273105838-4441-1-git-send-email-xiaosuo@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On Thu, May 6, 2010 at 8:30 AM, Changli Gao wrote: > kvmalloc() will try to allocate physically contiguous memory first, a= nd try > vmalloc to allocate virtually contiguous memory when the former alloc= ation > fails. > > kvfree() is used to free the memory allocated by kvmalloc(). It can't= be used > in atomic context. If the callers are in atomic contex, they can use > kvfree_inatomic() instead. > > There is much duplicate code to do such things in kernel, so I genera= te the > above APIs. > > Thank Eric Dumazet for the "kv" prefix. :) > > #include > #include > #include > #include > #include > #include > #include > > void *kvmalloc(size_t size) > { > =C2=A0 =C2=A0 =C2=A0 =C2=A0void *ptr; > > =C2=A0 =C2=A0 =C2=A0 =C2=A0if (size < PAGE_SIZE) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return kmalloc= (PAGE_SIZE, GFP_KERNEL); typo mistake, should be kmalloc(size, GFP_KERNEL), thank Tetsuo Handa . --=20 Regards=EF=BC=8C Changli Gao(xiaosuo@gmail.com)