首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Flash >

linux内核源码翻阅之facebook硬盘加速flashcache之六

2013-09-18 
linux内核源码阅读之facebook硬盘加速flashcache之六其实到目前为止,如果对读流程已经能轻松地看懂了,那么

linux内核源码阅读之facebook硬盘加速flashcache之六

其实到目前为止,如果对读流程已经能轻松地看懂了,那么写流程不需要太多脑细胞。我觉得再写下去没有太大的必要了,后面想想为了保持flashcache完整性,还是写出来吧。接着到写流程:

1411static void1412flashcache_write_miss(struct cache_c *dmc, struct bio *bio, int index)1413{1414     struct cacheblock *cacheblk;1415     struct kcached_job *job;1416     int queued;14171418     cacheblk = &dmc->cache[index];1419     queued = flashcache_inval_blocks(dmc, bio);1420     if (queued) {1421          if (unlikely(queued < 0))1422               flashcache_bio_endio(bio, -EIO);1423          spin_unlock_irq(&dmc->cache_spin_lock);1424          return;1425     }1426     if (cacheblk->cache_state & VALID)1427          dmc->wr_replace++;1428     else1429          dmc->cached_blocks++;1430     cacheblk->cache_state = VALID | CACHEWRITEINPROG;1431     cacheblk->dbn = bio->bi_sector;1432     spin_unlock_irq(&dmc->cache_spin_lock);1433     job = new_kcached_job(dmc, bio, index);1434     if (unlikely(sysctl_flashcache_error_inject & WRITE_MISS_JOB_ALLOC_FAIL)) {1435          if (job)1436               flashcache_free_cache_job(job);1437          job = NULL;1438          sysctl_flashcache_error_inject &= ~WRITE_MISS_JOB_ALLOC_FAIL;1439     }1440     if (unlikely(job == NULL)) {1441          /* 1442          * We have a write miss, and can't allocate a job.1443          * Since we dropped the spinlock, we have to drain any 1444          * pending jobs.1445          */1446          DMERR("flashcache: Write (miss) failed ! Can't allocate memory for cache IO, block %lu", 1447                cacheblk->dbn);1448          flashcache_bio_endio(bio, -EIO);1449          spin_lock_irq(&dmc->cache_spin_lock);1450          dmc->cached_blocks--;1451          cacheblk->cache_state &= ~VALID;1452          cacheblk->cache_state |= INVALID;1453          flashcache_free_pending_jobs(dmc, cacheblk, -EIO);1454          cacheblk->cache_state &= ~(BLOCK_IO_INPROG);1455          spin_unlock_irq(&dmc->cache_spin_lock);1456     } else {1457          job->action = WRITECACHE; 1458          atomic_inc(&dmc->nr_jobs);1459          dmc->ssd_writes++;1460          dm_io_async_bvec(1, &job->cache, WRITE, 1461                    bio->bi_io_vec + bio->bi_idx,1462                    flashcache_io_callback, job);1463          flashcache_unplug_device(dmc->cache_dev->bdev);1464          flashcache_clean_set(dmc, index / dmc->assoc);1465     }1466}

大多数函数都已经是老朋友了。第1430行cache块设置了VALID标志,表示在有效数据,第1431行设置cache块对应的磁盘的bi_sector扇区。接着到第1460行下发写缓存请求,写缓存的情况与写命中的一样就不再继续跟进了。下一节讲缓存超水位线写回磁盘。

热点排行