how to do page level mem alloc in freebsd kernel?

Kostik Belousov kostikbel at gmail.com
Thu Jul 15 15:04:25 UTC 2010


On Thu, Jul 15, 2010 at 08:24:53PM +0530, kalash nainwal wrote:
> On Thu, Jul 15, 2010 at 5:41 PM, John Baldwin <jhb at freebsd.org> 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. :)  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.
> >
> 
> 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
             ^^^^^^kernel_map.
> purpose fine.
> 
> Regards,
> -Kalash
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20100715/8de16f5e/attachment.pgp


More information about the freebsd-hackers mailing list