From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755861AbYKPEhP (ORCPT ); Sat, 15 Nov 2008 23:37:15 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751989AbYKPEg7 (ORCPT ); Sat, 15 Nov 2008 23:36:59 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:57311 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751951AbYKPEg6 (ORCPT ); Sat, 15 Nov 2008 23:36:58 -0500 Message-ID: <491FA28B.2070003@cn.fujitsu.com> Date: Sun, 16 Nov 2008 12:33:15 +0800 From: Lai Jiangshan User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: Andrew Morton CC: Paul Menage , kamezawa.hiroyu@jp.fujitsu.com, Balbir Singh , Jens Axboe , "David S. Miller" , Jan Kara , Jes Sorensen , Linux Kernel Mailing List Subject: [PATCH 1/7] mm: introduce simple_malloc()/simple_free() Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org some subsystem needs vmalloc() when required memory is large. but current kernel has not APIs for this requirement. this patch introduces simple_malloc() and simple_free(). Signed-off-by: Lai Jiangshan --- diff --git a/include/linux/mm.h b/include/linux/mm.h index ffee2f7..e9c11f7 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -13,6 +13,7 @@ #include #include #include +#include struct mempolicy; struct anon_vma; @@ -278,6 +279,36 @@ static inline int is_vmalloc_addr(const void *x) #endif } +static inline void *__simple_malloc(unsigned long size, int pages_hint) +{ + if (size <= PAGE_SIZE * pages_hint) + return kmalloc(size, GFP_KERNEL); + else + return vmalloc(size); +} + +/** + * simple_malloc - allocate memory by kmalloc() or vmalloc() + * + * if @size <= PAGE_SIZE, memory is allocated by kmalloc(), + * otherwise by vmalloc() + */ +static inline void *simple_malloc(unsigned long size) +{ + return __simple_malloc(size, 1); +} + +/** + * simple_free - free the memory by kfree(), or vfree() if it is vmalloc addr + */ +static inline void simple_free(void *ptr) +{ + if (is_vmalloc_addr(ptr)) + vfree(ptr); + else + kfree(ptr); +} + static inline struct page *compound_head(struct page *page) { if (unlikely(PageTail(page)))