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


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

  • 相关阅读:
    AMD and CMD are dead之KMD规范
    AMD and CMD are dead之js模块化黑魔法
    码农干货系列【20】--add gtTime to Promise.js
    ReactNative: 使用选择器组件PickerIOS组件
    ReactNative: 使用选择器组件Picker组件
    ReactNative: 使用模态组件Modal组件
    ReactNative: 使用列表组件ListView组件
    ReactNative: 使用键盘避免视图KeyboardAvoidingView组件实现键盘自适应
    ReactNative: 使用图片存储组件ImageStore组件
    ReactNative: 使用图片裁剪组件ImageEditor组件
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4646491.html
Copyright © 2020-2023  润新知