From owner-freebsd-hackers@FreeBSD.ORG Thu Jul 15 15:34:16 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 B296F1065675; Thu, 15 Jul 2010 15:34:16 +0000 (UTC) (envelope-from kalash.nainwal@gmail.com) Received: from mail-vw0-f54.google.com (mail-vw0-f54.google.com [209.85.212.54]) by mx1.freebsd.org (Postfix) with ESMTP id 4A0D88FC15; Thu, 15 Jul 2010 15:34:15 +0000 (UTC) Received: by vws19 with SMTP id 19so1603591vws.13 for ; Thu, 15 Jul 2010 08:34:15 -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=xB1ny3muNcjQRLxTp5RJF9PLFJDtl3edvRShR33bgGw=; b=UJBdgNM+2hC0bA2rHjPLQuH+xMz8+PDepC9xifmSq8oBKr+axedhYqtvnysfMmm0X3 wvSKni9E3su5K6Xiw5pmnIc77FqsgSfcHkv9oKXZsY3sKjDymgY74VeTkojn1kmC94DM jJwmvecTsBFUJtVEmK3bML389PIbOQfMa8bUY= 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=swu/RvUkr3eNTA3OSwDwu1/krJQjRgPAlXuANlUFydg30wn7xPeodN5sgH5t1aca4n w4dHPhBbNfTv/eEbo8FLKts/vTli3t7dQW/x08Mh8qbV1AoKsECuvyHe2/OyRZLis2g0 lrC+N9mOQbmA7N6OiIsBRlzY6AtHpQs7Kb6tk= MIME-Version: 1.0 Received: by 10.220.96.4 with SMTP id f4mr4391786vcn.127.1279208055172; Thu, 15 Jul 2010 08:34:15 -0700 (PDT) Received: by 10.220.192.8 with HTTP; Thu, 15 Jul 2010 08:34:15 -0700 (PDT) In-Reply-To: <20100715150411.GV2381@deviant.kiev.zoral.com.ua> References: <201007150811.11721.jhb@freebsd.org> <20100715150411.GV2381@deviant.kiev.zoral.com.ua> Date: Thu, 15 Jul 2010 21:04:15 +0530 Message-ID: From: kalash nainwal To: Kostik Belousov 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 15:34:16 -0000 2010/7/15 Kostik Belousov : > On Thu, Jul 15, 2010 at 08:24:53PM +0530, kalash nainwal wrote: >> 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= (4096) >> > will be aligned on a 4096-byte boundary if PAGE_SIZE is >=3D 4096. =A0= My >> > understanding is that objects returned from malloc() are aligned to th= e >> > smallest power-of-2 value >=3D the requested size up to a page. =A0All= ocations >> > larger than a page are page aligned. =A0So a malloc of 24 bytes or 32 = bytes 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 > =A0 =A0 =A0 =A0 =A0 =A0 ^^^^^^kernel_map. oops. my bad. thanks for correcting.