Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Jul 2010 08:11:11 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-hackers@freebsd.org
Cc:        kalash nainwal <kalash.nainwal@gmail.com>
Subject:   Re: how to do page level mem alloc in freebsd kernel?
Message-ID:  <201007150811.11721.jhb@freebsd.org>
In-Reply-To: <AANLkTikg2K95ffSL_dAnYIri_NnqUGarViVETjrew8EB@mail.gmail.com>
References:  <AANLkTikg2K95ffSL_dAnYIri_NnqUGarViVETjrew8EB@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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. :)  malloc(4096) 
will be aligned on a 4096-byte boundary if PAGE_SIZE is >= 4096.  My 
understanding is that objects returned from malloc() are aligned to the 
smallest power-of-2 value >= the requested size up to a page.  Allocations 
larger than a page are page aligned.  So a malloc of 24 bytes or 32 bytes is 
32-byte aligned for example.

-- 
John Baldwin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007150811.11721.jhb>