A confusion about `slab allocator` 's initialization

Hungpo DU alecdu at gmail.com
Wed Jul 17 15:04:35 UTC 2013


I find a couple of lines confusing while reading the slab allocator's code.

         96     p = (u_char *) pool + sizeof(ngx_slab_pool_t);
         97     size = pool->end - p;
        ...
        110     p += n * sizeof(ngx_slab_page_t);
        111
        112     pages = (ngx_uint_t) (size / (ngx_pagesize +
sizeof(ngx_slab_page_t)));
        113
        114     ngx_memzero(p, pages * sizeof(ngx_slab_page_t));
        115
        ...
        125     pool->start = (u_char *)
        126                   ngx_align_ptr((uintptr_t) p + pages *
sizeof(ngx_slab_page_t),
        127                                  ngx_pagesize);

The `size` takes space occupied by *slots* into account, that'll make
`pages`
a little bit larger. Then,

* because `p` is already advanced by sizeof *slots*, the following
`ngx_memzero`
will operates on more `ngx_slab_page_t`'s than expected.

* also `pool->start` will start at a higher postion before aligned by
`ngx_pagesize`. One more page maybe available if `pages` is a little
smaller?


Can someone please tell me these lines's true intention? I must get it
wrong
somewhere.


  Best regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20130717/baeb1ef9/attachment.html>


More information about the nginx-devel mailing list