memcache -- memory allocation

来源:互联网 发布:ff14拉拉菲尔捏脸数据 编辑:程序博客网 时间:2024/05/29 19:32
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
原创粉丝点击