This article original for freas_1990, reprint please indicate source: http://blog.csdn.net/freas_1990/article/details/42052813
When the value of a Redis key is swap to a file, the value of the key to the Redisobject will be changed to Vmpointer,vmpointer to save the value on the disk file. This includes the offset of the start page and the number of consecutive pages.
typedef struct REDISOBJECT { unsigned type:4; unsigned storage:2; /* Redis_vm_memory or redis_vm_swapping */ unsigned encoding:4; unsigned lru:22; /* LRU time (relative to Server.lruclock) */ int refcount; void *ptr; /* VM Fields was only allocated if VM is active, otherwise the * Object allocation function would just allocate * sizeof (REDISOBJCT) minus sizeof (REDISOBJECTVM), so using * Redis without VM active is not having any overhead. */} RO bj
typedef struct VMPOINTER { unsigned type:4; unsigned storage:2; /* redis_vm_swapped or redis_vm_loading */ unsigned notused:26; unsigned int vtype; /* Type of the object stored in the swap file */ off_t page; /* The page at witch the object was stored on disk */ off_t usedpages; /* Number of pages used on disk */} Vmpointer;
The logic to import the key's value into memory is as follows:
RobJ *vmreadobjectfromswap (off_t page, int type) { robj *o; if (server.vm_enabled) Pthread_mutex_lock (&server.io_swapfile_mutex); if (Fseeko (server.vm_fp,page*server.vm_page_size,seek_set) = =-1) { redislog (redis_warning, "unrecoverable VM problem in Vmreadobjectfromswap (): Can ' t seek:%s ", strerror (errno)); _exit (1); } o = Rdbloadobject (TYPE,SERVER.VM_FP); if (o = = NULL) { redislog (redis_warning, "unrecoverable VM problem in Vmreadobjectfromswap (): Can ' t load object from Swap file:%s ", Strerror (errno)); _exit (1); } if (server.vm_enabled) Pthread_mutex_unlock (&server.io_swapfile_mutex); return o;}
Here, the essence of the Redis VM is dissected, okay?
Dissected Redis VMS