Dissected Redis VMS

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.