Fwd: Question about slab allocator

Maxim Dounin mdounin at mdounin.ru
Fri May 9 03:12:39 UTC 2014


Hello!

On Wed, May 07, 2014 at 12:42:39PM -0700, Shuxin Yang wrote:

>    I'm nginx newbie. I'm reading src/core/ngx_slab.c, and am confused
> as to
> the purpose of NGX_SLAB_PAGE_START.
> 
>    As far as I can understand, when allocating a block, the most
> significant
> bit (MSB) of first page's corresponding ngx_slab_page_s::slab is set "1".
> as we can see from :
> 
>    cat -n ngx_slab.c at pristine-1.7-release
>    644    page->slab = pages | NGX_SLAB_PAGE_START;
> 
>   However, the MSB of is cleared later on:
>     362         } else if (shift == ngx_slab_exact_shift) {
>     363
>     364             page->slab = 1;
> 
>   So, what is the purpose of NGX_SLAB_PAGE_START (i.e the MSB of the
> field slab)?

The NGX_SLAB_PAGE_START is only used for multi-page allocations 
(to mark a starting page of a multi-page allocation).  In other 
cases it's overwritten, and that's fine.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx-devel mailing list