memcache -- memory allocation

why use slab allocation:
    problem allocating memory:     
        cause data in memory changes constantly and not in fixed size, so there will be lots of fragments in memory that is too small to use ,it will cause a wast of  memory ,so memcache use slab allocation to allocate memory.
slab allocation:

the memory is divided into several slabs, each slab consist of serveral chunks of fixed size, as the precedding diagram indicates, when an object requires a 50 bytes of memory it will be allocated into slab class1, and a 120 bytes object will be allocated into slab class 3. but this will also cost a little waste of memory:
in this case a memory of 28 bytes is wasted(indicated by blue shadow in the diagram).

Growth Factor
the chunk sized grows in an fixed pace.  how fast the chunck wil grows is specified by grow factor and you can set growth factor by -f parameter . as the precedding diagram of slabs indicates  :112=1.25*88      144=1.25*112 in this case  1.25 is growth factor (f).
the size of growth factor should be appropriately settd , and 1.25 is the default growth factor of memcache ,and works well in most cases.

what happens when run out of chunks;
     consider this, you need to allocate an object of 120 bytes  ,normally you will allocate it in slab class 3 whose chunk size is 144 bytes. but it happens when you have no more empty chunks in slab  class 3. what will memcache do in this case.
    it will release some trunks in slab class 3 in some rule  to get empty chunks.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值