Posts

Showing posts from July, 2013

Nginx's Memory Allocation

Nginx's Memory allocation Memory allocation performs a crucial role in a high-performance server's design, a poor efficiency memory management can become the bottleneck for high performance. Nginx, as a fast web server, implemented its own memory allocation. It's memory allocation source code located in ngx_palloc.c. It works in following ways. Nginx's memory allocation system has two kinds of chain, like the following figure. the above chain with equal data block size M, it works in this way: when Nginx want to allocate any memory equal or smaller than size M, it will be allocated from this chain, when neither of the nodes in this chain has enough space to satisfy this request. Then Nginx will build another chain node to finish this request. when Nginx want to allocate any memory larger than size M, it will allocate from the chain in the bottom side. this chain's node should be built dynamically, and can be destroyed. I write a copycat memory alloc