From owner-freebsd-hackers@FreeBSD.ORG Thu Jul 15 14:54:56 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 00383106566B for ; Thu, 15 Jul 2010 14:54:55 +0000 (UTC) (envelope-from kalash.nainwal@gmail.com) Received: from mail-gx0-f182.google.com (mail-gx0-f182.google.com [209.85.161.182]) by mx1.freebsd.org (Postfix) with ESMTP id 8C4B08FC29 for ; Thu, 15 Jul 2010 14:54:55 +0000 (UTC) Received: by gxk24 with SMTP id 24so799072gxk.13 for ; Thu, 15 Jul 2010 07:54:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=9Wv380OYlz/ymblggoAruk/j66x2TRI3b1AAMPB2+PI=; b=fxnuF+sP6fNoCE8XmF5dhqBqmNwxfxckOzfq+i21deq9LmB0/28yNCunS9YzY6GdCN +KOQs5mhhlVl5KGttuCyO2y9UgcvDRwzeqyQVCYX5S4TTuw0zU2z7AArDhXbN1gnKsNC ey0Fo4QlrwXXTcDIG51WDNH/9C/llGJdWwp8A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=XWiLLH8mmhLLQ2+u2iotrDiSAjo2bYhLXW3MRTqLP8G3bQrn/5SgcDc8VtQb3kmUqm dW3owRuKp++O9ThmbkjZL4Fjg1qUVADMYIpLKN1Igeji+C7ELSGvntL4WTV5MHex6ApJ 9ljgARQbAl61MyWk0JRQsb9cS9y0IpdapC0yU= MIME-Version: 1.0 Received: by 10.103.177.3 with SMTP id e3mr1183189mup.126.1279205693890; Thu, 15 Jul 2010 07:54:53 -0700 (PDT) Received: by 10.220.192.8 with HTTP; Thu, 15 Jul 2010 07:54:53 -0700 (PDT) In-Reply-To: <201007150811.11721.jhb@freebsd.org> References: <201007150811.11721.jhb@freebsd.org> Date: Thu, 15 Jul 2010 20:24:53 +0530 Message-ID: From: kalash nainwal To: John Baldwin Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org Subject: Re: how to do page level mem alloc in freebsd kernel? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Jul 2010 14:54:56 -0000 On Thu, Jul 15, 2010 at 5:41 PM, John Baldwin wrote: > On Thursday, July 15, 2010 6:28:53 am kalash nainwal wrote: >> Hi, >> >> I want to allocate one (or more) pages in kernel space. >> I'm not sure what is the api in freebsd (something which >> is similar to __get_free_pages() of linux). >> >> Would malloc(4096, ...) guarantee that the returned >> address is aligned on page boundary? > > Well, malloc(PAGE_SIZE) will align it on a page boundary. :) =A0malloc(40= 96) > will be aligned on a 4096-byte boundary if PAGE_SIZE is >=3D 4096. =A0My > understanding is that objects returned from malloc() are aligned to the > smallest power-of-2 value >=3D the requested size up to a page. =A0Alloca= tions > larger than a page are page aligned. =A0So a malloc of 24 bytes or 32 byt= es is > 32-byte aligned for example. > Thanks John for explaining. After going through the kernel src I was not sure about malloc, as the code is little hard to follow. However I figured kmem_alloc(kernel_pmap, PAGE_SIZE) would serve my purpose fine. Regards, -Kalash