小白请教一段开源代码

2016-05-10 09:04:52 +08:00
 little

摘自 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

1212 次点击
所在节点    问与答
1 条回复
lonelinsky
2016-05-10 10:29:39 +08:00
从贴出来的代码猜测应该是想在 workqtree 或者 readcachetree 占用 cache 超过一半的时候将数据写回并清理缓存吧。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/277515

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX