Welcome! Log In Create A New Profile

Advanced

A confusion about `slab allocator` 's initialization

July 17, 2013 11:08AM
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.
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

A confusion about `slab allocator` 's initialization

duhoobo 1341 July 17, 2013 11:08AM

Re: A confusion about `slab allocator` 's initialization

Maxim Dounin 678 July 19, 2013 10:00AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 110
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready