Redis内存分配简单分析
2015-07-12 00:50
721 查看
Redis内存管理 1.Redis内存申请内存方式有三种: (1)系统自带的malloc/free方式进行申请/释放。 (2)使用tcmalloc进行内存的申请/释放。 (3)使用jemalloc进行内存申请/释放。 /* Explicitly override malloc/free etc when using tcmalloc. */ #if defined(USE_TCMALLOC) #define malloc(size) tc_malloc(size) #define calloc(count,size) tc_calloc(count,size) #define realloc(ptr,size) tc_realloc(ptr,size) #define free(ptr) tc_free(ptr) #elif defined(USE_JEMALLOC) #define malloc(size) je_malloc(size) #define calloc(count,size) je_calloc(count,size) #define realloc(ptr,size) je_realloc(ptr,size) #define free(ptr) je_free(ptr) #endif 2.内存计数器上使用了gcc的一组原子操作,实现的功能就是在used_memory+n的操作 //1.先做操作,再返回变化后的值 //2.先返回变化前的值,再做操作 #if defined(__ATOMIC_RELAXED) #define update_zmalloc_stat_add(__n) __atomic_add_fetch(&used_memory, (__n), __ATOMIC_RELAXED) //used_memory+=n; #define update_zmalloc_stat_sub(__n) __atomic_sub_fetch(&used_memory, (__n), __ATOMIC_RELAXED) //used_memory-=n; #elif defined(HAVE_ATOMIC) #define update_zmalloc_stat_add(__n) __sync_add_and_fetch(&used_memory, (__n)) //used_memory+=n; #define update_zmalloc_stat_sub(__n) __sync_sub_and_fetch(&used_memory, (__n)) //used_memory-=n; #else 3.还有一部函数获取系统的配置信息
相关文章推荐
- tomcat利用redis实现session共享
- [你必须知道的NOSQL系列]专题二:Redis快速入门
- Redis 事件(1) -- 文件事件
- linux下redis安装
- Redis AOF持久化
- 深入理解Spring Redis的使用 (一)、Spring Redis基本使用
- 深入浅出Redis01安装
- Redis应用场景
- Redis命令使用
- Redis持久化配置
- Redis主从配置相关脚本
- Redis_conf配置文件说明
- Redis远程连接
- Redis用户验证设置
- ServiceStack.Redis之IRedisClient
- Redis注册服务
- 使用ElasticSearch+LogStash+Kibana+Redis搭建日志管理服务
- Redis安装(单机)
- Redis监控方案
- redislive