Redis_BIO

Redis Async library BIO(Background IO)

Redis异步io库,主要作用,分三个thread分别处理三种job

  1. aof dump
  2. free memory(redisObject, redis database, redis skiplist)
  3. close aof fd

Description

1: AOF(Append Only File) dump

redis使用异步io的方式,来持久化redis进程数据,底层使用的是fsync同步io的方式,fsync会阻塞进程确保fd修改的内容已经成功刷盘。linux常规的write只是更新memory中的page cache,并不是同步刷盘的,redis为了确保数据的不丢失,则采用这种同步刷盘的方式。

2:Release Redis object

释放redisObject的内存

配置来决定释放内存的方式 :
int lazyfree_lazy_eviction; // 定时清空内存,是否超过设置的最大内存
int lazyfree_lazy_expire; // 超时的object
int lazyfree_lazy_server_del; // 删除的object

1
2
3
4
5
6
7
8
9
typedef struct redisObject {
unsigned type:4;
unsigned encoding:4;
unsigned lru:LRU_BITS; /* LRU time (relative to global lru_clock) or
* LFU data (least significant 8 bits frequency
* and most significant 16 bits access time). */
int refcount;
void *ptr; // data ptr
} robj;
  1. 释放data ptr
  2. 释放该redisObject的ptr,
  3. 释放之前需要确保refcount=1

释放删除的redis的database

释放skiplist(skiplist mapping Redis Cluster keys to slots in the lazyfree thread)

3:Close aof fd

关闭aof相关fd(文件描述符)