+---------------+ | Mapped Device | +-------+-------+ | v +---------------+ | mapper table | +-------+-------+ | | flashcache | +---+---+ | | v v +-----+ +------+ | SSD | | DISK | +-----+ +------+
flashcache做为缓存层,提供了三种写入模式:
writeback
writethrough
writearound
三种模式的区别如下图所示:
1 2 3 4 5 6 7
writethrough writearound writeback | | | -----|------------|-----------|------------ v | v SSD -----|------------|------------------------ v v DISK -------------------------------------------
writethrough:进行写操作时,会同时写入SSD和磁盘
writearound: 进行写操作时,只对磁盘进行写操作
writeback: 进行写操作时,只写入SSD,flashcache异步地将内容写入磁盘
下面分析flashcache模块的初始化。
flashcache内核模块的入口函数为flashcache_init。
1
module_init(flashcache_init);
flashcache_init首先会对job相关的变量及结构进行初始化:
1 2 3 4 5
r = flashcache_jobs_init(); if (r) return r; atomic_set(&nr_cache_jobs, 0); atomic_set(&nr_pending_jobs, 0);
staticstructnotifier_blockflashcache_notifier = { .notifier_call = flashcache_notify_reboot, .next = NULL, .priority = INT_MAX, /* should be > ssd pri's and disk dev pri's */ };