Lay Bare Redis VMS

Source: Internet
Author: User

The original article is freas_1990. Reprint Please specify source: http://blog.csdn.net/freas_1990/article/details/42052813



The value of the only key that Redis has is the swap file, and the key's value points to the redisobject that will change to Vmpointer. Vmpointer holds the value's information on the disk file, including the offset of the starting 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 for importing 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 Redis VM has pointed out the essence, understand it?


Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Lay bare 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.