๐Ÿ“ฆ yjhjstz / mempool

nginx like mempool

โ˜… 4 stars โ‘‚ 0 forks ๐Ÿ‘ 4 watching
๐Ÿ“ฅ Clone https://github.com/yjhjstz/mempool.git
HTTPS git clone https://github.com/yjhjstz/mempool.git
SSH git clone git@github.com:yjhjstz/mempool.git
CLI gh repo clone yjhjstz/mempool
jianghua.yjh jianghua.yjh update README 6cafc10 9 years ago ๐Ÿ“ History
๐Ÿ“‚ master View all commits โ†’
๐Ÿ“„ Makefile
๐Ÿ“„ mp_alloc.c
๐Ÿ“„ mp_alloc.h
๐Ÿ“„ mp_test.c
๐Ÿ“„ README.md
๐Ÿ“„ README.md

nginx like memory pool

nginx memory pool mode:

where create the memory pool, set the memory pool size is its node size;

  • when alloc memory size < node size; alloc it from one of the pool node;
when all the node doesn't have enough memory for alloc, alloc new node;

  • when alloc memory size >= node size; alloc large chunk for it, likely using malloc directly;
  • free: the memory pool won't release the alloc size < node size block until destroy the pool;
large chunk which size > node size, can be released using mp_free, likely free;

  • reuse: mpresetpool can release all the large chunk in the pool,
but don't release all the allocated node, just reset them for reuse;

advantages

  • reduce the malloc times to promote performance;
  • an reset memory pool can be used for same type work, as web connection;
  • using freemempoollist and usedmempoollist to promote mem_pool reuse;

disadvantages

  • linear scan to free larger memory