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已经指出的精髓,明白了吧?


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

  • 相关阅读:
    C# 不用添加WebService引用,调用WebService方法
    贪心 & 动态规划
    trie树 讲解 (转载)
    poj 2151 Check the difficulty of problems (检查问题的难度)
    poj 2513 Colored Sticks 彩色棒
    poj1442 Black Box 栈和优先队列
    啦啦啦
    poj 1265 Area(pick定理)
    poj 2418 Hardwood Species (trie树)
    poj 1836 Alignment 排队
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4646491.html
Copyright © 2011-2022 走看看