zoukankan      html  css  js  c++  java
  • 道破Redis的VM

    原创文章是freas_1990。转载请注明出处:http://blog.csdn.net/freas_1990/article/details/42052813



    Redis唯一的那个key的value是swap文件上的时候,该key的value指向的RedisObject将会改变成VMPointer。VMPointer保存了该value在磁盘文件上的信息,包含起始页面的偏移和连续的页面数等。


    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 are only allocated if VM is active, otherwise the
         * object allocation function will just allocate
         * sizeof(redisObjct) minus sizeof(redisObjectVM), so using
         * Redis without VM active will not have any overhead. */
    } robj;


    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 is stored on disk */
        off_t usedpages;    /* number of pages used on disk */
    } vmpointer;

    将该key的value导入内存的逻辑例如以下:

    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;
    }

    到这里,redis VM已经指出的精髓,明白了吧?


    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    .net core EF 入门笔记Code First
    Windows环境下安装MongodDB
    Ueditor1.4.3.3 富文本编辑器在图片不显示问题
    .net IIS网站部署Host文件简单应用
    .Net初学Less的安装与部署
    EF+MVC动态Lamda表达式拼接(学习笔记二)
    EF+MVC动态Lamda表达式拼接(学习笔记)
    区块链从入门到放弃
    Unity3D的update和FixedUpdate
    忽雷太极拳十三式
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4646491.html
Copyright © 2011-2022 走看看