Why is (getpagesize() - 1) special?
/*
* NGX_MAX_ALLOC_FROM_POOL should be (ngx_pagesize - 1), i.e. 4095 on x86.
* On Win开发者_开发百科dows NT it decreases a number of locked pages in a kernel.
*/
#define NGX_MAX_ALLOC_FROM_POOL (ngx_pagesize - 1)
The above is extracted from nginx, but I don't understand why the max memory that can be allocated from the pool is getpagesize()-1
?
In ngx_pool_t, there are two methods to alloc memory. 1. get not used memory from the memory pool (alloced previously). 2. get memory by calling the palloc to get memory from the OS directly.
while the memory required is less than pagesize(4k), use the memory pool, on the other hand get memory from the OS directly.
精彩评论