From patchwork Tue Oct 19 13:55:12 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Young X-Patchwork-Id: 265811 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9JDvkqf017055 for ; Tue, 19 Oct 2010 13:57:46 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752033Ab0JSNzN (ORCPT ); Tue, 19 Oct 2010 09:55:13 -0400 Received: from mail-px0-f174.google.com ([209.85.212.174]:45458 "EHLO mail-px0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751803Ab0JSNzK (ORCPT ); Tue, 19 Oct 2010 09:55:10 -0400 Received: by pxi16 with SMTP id 16so449017pxi.19 for ; Tue, 19 Oct 2010 06:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=MA03xa1/xpeRAunQFJS8mNhkNa4ddRTPEouef/bx9/E=; b=vFgeAMYIF6owWTI4GAg8eUZuHi7AiV0L05ltZ92yg5hxaZVVswUURxWbfDZtYVSQLL kZfg5XRDp4PiS+NbwQAsV7/Yl9TmnusMF2MK7ZxZjTBVT72ZpG5ffulgewHqLl3TWe8Q L0P/dsV8cx2Mg0W/+Nok5dFTfA2K311YVYPn0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=qtuY7F4Sr/2LNed6rsnVxj8njWgY0Zcn2USQRpKUhLw0rFvVVPtg0UBbNahwf48flf TrQPUBOYixwlJhmInkKnN95d88JqS9cBY/9QI7OxobyZGRlM4UwT3n5nJVYpRKJhUJGb CCXSITruUA+Th47IjcFvOqp8gz+y+nfO/ZNzI= Received: by 10.142.204.4 with SMTP id b4mr4672383wfg.45.1287496509465; Tue, 19 Oct 2010 06:55:09 -0700 (PDT) Received: from darkstar ([221.221.203.91]) by mx.google.com with ESMTPS id x18sm14622749wfa.11.2010.10.19.06.55.02 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 19 Oct 2010 06:55:07 -0700 (PDT) Date: Tue, 19 Oct 2010 21:55:12 +0800 From: Dave Young To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org Subject: Re: [PATCH 1/2] Add vzalloc shortcut Message-ID: <20101019135512.GA31193@darkstar> References: <20101016043331.GA3177@darkstar> <20101018164647.bc928c78.akpm@linux-foundation.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20101018164647.bc928c78.akpm@linux-foundation.org> User-Agent: Mutt/1.5.20 (2009-06-14) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 19 Oct 2010 13:57:47 +0000 (UTC) --- linux-2.6.orig/include/linux/vmalloc.h 2010-10-19 20:44:20.383333459 +0800 +++ linux-2.6/include/linux/vmalloc.h 2010-10-19 20:45:07.366666782 +0800 @@ -53,8 +53,10 @@ static inline void vmalloc_init(void) #endif extern void *vmalloc(unsigned long size); +extern void *vzalloc(unsigned long size); extern void *vmalloc_user(unsigned long size); extern void *vmalloc_node(unsigned long size, int node); +extern void *vzalloc_node(unsigned long size, int node); extern void *vmalloc_exec(unsigned long size); extern void *vmalloc_32(unsigned long size); extern void *vmalloc_32_user(unsigned long size); --- linux-2.6.orig/mm/vmalloc.c 2010-10-19 20:44:20.383333459 +0800 +++ linux-2.6/mm/vmalloc.c 2010-10-19 20:53:01.296666793 +0800 @@ -1587,6 +1587,13 @@ void *__vmalloc(unsigned long size, gfp_ } EXPORT_SYMBOL(__vmalloc); +static inline void *__vmalloc_node_flags(unsigned long size, + int node, gfp_t flags) +{ + return __vmalloc_node(size, 1, flags, PAGE_KERNEL, + node, __builtin_return_address(0)); +} + /** * vmalloc - allocate virtually contiguous memory * @size: allocation size @@ -1598,12 +1605,28 @@ EXPORT_SYMBOL(__vmalloc); */ void *vmalloc(unsigned long size) { - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL, - -1, __builtin_return_address(0)); + return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM); } EXPORT_SYMBOL(vmalloc); /** + * vzalloc - allocate virtually contiguous memory with zero fill + * @size: allocation size + * Allocate enough pages to cover @size from the page level + * allocator and map them into contiguous kernel virtual space. + * The memory allocated is set to zero. + * + * For tight control over page level allocator and protection flags + * use __vmalloc() instead. + */ +void *vzalloc(unsigned long size) +{ + return __vmalloc_node_flags(size, -1, + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO); +} +EXPORT_SYMBOL(vzalloc); + +/** * vmalloc_user - allocate zeroed virtually contiguous memory for userspace * @size: allocation size * @@ -1644,6 +1667,25 @@ void *vmalloc_node(unsigned long size, i } EXPORT_SYMBOL(vmalloc_node); +/** + * vzalloc_node - allocate memory on a specific node with zero fill + * @size: allocation size + * @node: numa node + * + * Allocate enough pages to cover @size from the page level + * allocator and map them into contiguous kernel virtual space. + * The memory allocated is set to zero. + * + * For tight control over page level allocator and protection flags + * use __vmalloc_node() instead. + */ +void *vzalloc_node(unsigned long size, int node) +{ + return __vmalloc_node_flags(size, node, + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO); +} +EXPORT_SYMBOL(vzalloc_node); + #ifndef PAGE_KERNEL_EXEC # define PAGE_KERNEL_EXEC PAGE_KERNEL #endif --- linux-2.6.orig/mm/nommu.c 2010-10-19 20:44:20.383333459 +0800 +++ linux-2.6/mm/nommu.c 2010-10-19 20:45:07.370000115 +0800 @@ -293,11 +293,58 @@ void *vmalloc(unsigned long size) } EXPORT_SYMBOL(vmalloc); +/* + * vzalloc - allocate virtually continguos memory with zero fill + * + * @size: allocation size + * + * Allocate enough pages to cover @size from the page level + * allocator and map them into continguos kernel virtual space. + * The memory allocated is set to zero. + * + * For tight control over page level allocator and protection flags + * use __vmalloc() instead. + */ +void *vzalloc(unsigned long size) +{ + return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, + PAGE_KERNEL); +} +EXPORT_SYMBOL(vzalloc); + +/** + * vmalloc_node - allocate memory on a specific node + * @size: allocation size + * @node: numa node + * + * Allocate enough pages to cover @size from the page level + * allocator and map them into contiguous kernel virtual space. + * + * For tight control over page level allocator and protection flags + * use __vmalloc() instead. + */ void *vmalloc_node(unsigned long size, int node) { return vmalloc(size); } -EXPORT_SYMBOL(vmalloc_node); + +/** + * vzalloc_node - allocate memory on a specific node with zero fill + * @size: allocation size + * @node: numa node + * + * Allocate enough pages to cover @size from the page level + * allocator and map them into contiguous kernel virtual space. + * The memory allocated is set to zero. + * + * For tight control over page level allocator and protection flags + * use __vmalloc() instead. + */ +void *vzalloc_node(unsigned long size, int node) +{ + return vzalloc(size); +} +EXPORT_SYMBOL(vzalloc_node); #ifndef PAGE_KERNEL_EXEC # define PAGE_KERNEL_EXEC PAGE_KERNEL