<div dir="ltr"><div><div><br></div><div>I find a couple of lines confusing while reading the slab allocator's code.</div><div><br></div><div> 96 p = (u_char *) pool + sizeof(ngx_slab_pool_t); </div><div> 97 size = pool->end - p;</div>
<div> ... </div><div> 110 p += n * sizeof(ngx_slab_page_t); </div><div> 111 </div><div> 112 pages = (ngx_uint_t) (size / (ngx_pagesize + sizeof(ngx_slab_page_t))); </div><div> 113 </div>
<div> 114 ngx_memzero(p, pages * sizeof(ngx_slab_page_t));</div><div> 115 </div><div> ... </div><div> 125 pool->start = (u_char *) </div><div> 126 ngx_align_ptr((uintptr_t) p + pages * sizeof(ngx_slab_page_t), </div>
<div> 127 ngx_pagesize);</div><div> </div><div>The `size` takes space occupied by *slots* into account, that'll make `pages`</div><div>a little bit larger. Then, </div><div>
<br></div><div>* because `p` is already advanced by sizeof *slots*, the following `ngx_memzero`</div><div>will operates on more `ngx_slab_page_t`'s than expected.</div><div><br></div><div>* also `pool->start` will start at a higher postion before aligned by </div>
<div>`ngx_pagesize`. One more page maybe available if `pages` is a little smaller?</div><div><br></div><div><br></div><div>Can someone please tell me these lines's true intention? I must get it wrong </div><div>somewhere.</div>
</div><div><br></div><br clear="all"><div> Best regards.</div>
</div>