V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
little
V2EX  ›  问与答

小白请教一段开源代码

  •  
  •   little · 2016-05-10 09:04:52 +08:00 · 1207 次点击
    这是一个创建于 2929 天前的主题,其中的信息可能已经有所发展或是发生改变。

    摘自 lessfs 没有写全:

    #define MAX_FUSE_BLKSIZE
    ...
    char * cache;
    unsigned int cs = 0;
    unsigned long calc;
    ...
    cache = read_val("CACHESIZE");
    	if(cache)
    		cs = atoi(cache);
    	if(cs <= 0)
    		cs = 1;
    	cal = cs;
    	config->cachesize = (cal * 1024 * 1024) / MAX_FUSE_BLKSIZE;
    ...
    TCTREE *workqtree;              // Used to buffer incoming data (writes)
    TCTREE *readcachetree;          // Used to cache chunks of data that are likely to be read  
    ...
        if (tctreernum(workqtree) * 2 > config->cachesize ||
            tctreernum(readcachetree) * 2 > config->cachesize) {
    		//workqtree 脏数据先写回
    		flush_wait(0);
    		//清除缓存处理
            purge_read_cache(0, 1, (char *) __PRETTY_FUNCTION__);
        }
    ...
    

    中文部分注释是自己加的 想问的问题是:上面 tctreernum(workqtree) * 2 > config->cachesize || tctreernum(readcachetree) * 2 > config->cachesize 为什么在做判断的时候*2

    1 条回复    2016-05-10 10:29:39 +08:00
    lonelinsky
        1
    lonelinsky  
       2016-05-10 10:29:39 +08:00
    从贴出来的代码猜测应该是想在 workqtree 或者 readcachetree 占用 cache 超过一半的时候将数据写回并清理缓存吧。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1029 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:19 · PVG 03:19 · LAX 12:19 · JFK 15:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.