{"action":"created","issue":{"url":"https://api.github.com/repos/memcached/memcached/issues/93","labels_url":"https://api.github.com/repos/memcached/memcached/issues/93/labels{/name}","comments_url":"https://api.github.com/repos/memcached/memcached/issues/93/comments","events_url":"https://api.github.com/repos/memcached/memcached/issues/93/events","html_url":"https://github.com/memcached/memcached/pull/93","id":51524056,"number":93,"title":"Release memory back to system","user":{"login":"zwChan","id":6017948,"avatar_url":"https://avatars.githubusercontent.com/u/6017948?v=3","gravatar_id":"","url":"https://api.github.com/users/zwChan","html_url":"https://github.com/zwChan","followers_url":"https://api.github.com/users/zwChan/followers","following_url":"https://api.github.com/users/zwChan/following{/other_user}","gists_url":"https://api.github.com/users/zwChan/gists{/gist_id}","starred_url":"https://api.github.com/users/zwChan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zwChan/subscriptions","organizations_url":"https://api.github.com/users/zwChan/orgs","repos_url":"https://api.github.com/users/zwChan/repos","events_url":"https://api.github.com/users/zwChan/events{/privacy}","received_events_url":"https://api.github.com/users/zwChan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2014-12-10T06:34:20Z","updated_at":"2015-01-05T11:02:17Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/memcached/memcached/pulls/93","html_url":"https://github.com/memcached/memcached/pull/93","diff_url":"https://github.com/memcached/memcached/pull/93.diff","patch_url":"https://github.com/memcached/memcached/pull/93.patch"},"body":"  Add a feature that support release memory back to system. If the ratio of used items in a slab is less than release_mem_start(default is 50%), then start release memory; If the ratio  of used items greater than release_mem_stop(default is 80%), then stop release memory.\r\n  It is not complicated because it base on the slab_reassign(auto move) function. The different is that the picked page is not assign to other slab, but freed. And it also depend on the lru_crawler to clear the expired items.\r\n  The feature is useful when a cache cluster support  a lot of services(or application). We assign each service several cache instance in fixed size(say 4GB) randomly among cache servers(it's memory is 32GB or 64GB). Most of the time the service just used a few memory of their caches, and only reach the peak of memory usage at certain time. What is worse is that some services just don't know how much memory they need, so they required a lot of memory for 'safety'. With this feature, we can support more services using the current cache servers."},"comment":{"url":"https://api.github.com/repos/memcached/memcached/issues/comments/68694211","html_url":"https://github.com/memcached/memcached/pull/93#issuecomment-68694211","issue_url":"https://api.github.com/repos/memcached/memcached/issues/93","id":68694211,"user":{"login":"zwChan","id":6017948,"avatar_url":"https://avatars.githubusercontent.com/u/6017948?v=3","gravatar_id":"","url":"https://api.github.com/users/zwChan","html_url":"https://github.com/zwChan","followers_url":"https://api.github.com/users/zwChan/followers","following_url":"https://api.github.com/users/zwChan/following{/other_user}","gists_url":"https://api.github.com/users/zwChan/gists{/gist_id}","starred_url":"https://api.github.com/users/zwChan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zwChan/subscriptions","organizations_url":"https://api.github.com/users/zwChan/orgs","repos_url":"https://api.github.com/users/zwChan/repos","events_url":"https://api.github.com/users/zwChan/events{/privacy}","received_events_url":"https://api.github.com/users/zwChan/received_events","type":"User","site_admin":false},"created_at":"2015-01-05T11:02:17Z","updated_at":"2015-01-05T11:02:17Z","body":"I have tested at CentOS 6.3 and Ubuntu 14.04, using t/slab_free_memory_compare.t.\r\nIn slab_free_memory_compare.t, I send 100k keys with random expire and value length to 2 memcached, one is disable release memory function, named 'server1'; the other enable release function, named 'server2'.\r\n### At CentOS, \r\nthe result is something like: \r\n> total_mem1=26345472 B,total_mem2=25690112 B,diff=655 kB,evict1_incr=0,evict_diff=0,sys_mem1=28752 kB,sys_mem2=27652 kB,release sys_memory:1100 kB. \r\n\r\nIt is interesting that the system release memory more than the memcached malloc diff(as it show in the stats). The CentOS seems has no reserved  padding at the top of the heap.\r\n\r\n### At Ubuntu,\r\n the result is something like:\r\n> total_mem1=9699328 B,total_mem2=8257536 B,diff=1441 kB,sys_mem1=11772 kB,sys_mem2=10352 kB,release sys_memory:1420 kB\r\n\r\nThe Ubuntu seems reserved some padding at the top of the heap, but average we can release 2/3 of the freed memory to the system.\r\n\r\n### About eviction\r\n I also test about the effect on eviction. When the evicted keys just happen sometimes(e.g. a peak traffic to the cache), release memory function can reduce the number of evicted keys significantly. However, it has no improvement if the memory is very deficient.\r\n\r\nIn sum, I think this feature can work \"good enough\" even if the OS reserves padding at the top of the heap, and it can reduce the occupied memory, also reduce the number of evicted keys."}}