request.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  1. /*
  2. * Main bcache entry point - handle a read or a write request and decide what to
  3. * do with it; the make_request functions are called by the block layer.
  4. *
  5. * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
  6. * Copyright 2012 Google, Inc.
  7. */
  8. #include "bcache.h"
  9. #include "btree.h"
  10. #include "debug.h"
  11. #include "request.h"
  12. #include "writeback.h"
  13. #include <linux/cgroup.h>
  14. #include <linux/module.h>
  15. #include <linux/hash.h>
  16. #include <linux/random.h>
  17. #include "blk-cgroup.h"
  18. #include <trace/events/bcache.h>
  19. #define CUTOFF_CACHE_ADD 95
  20. #define CUTOFF_CACHE_READA 90
  21. struct kmem_cache *bch_search_cache;
  22. static void bch_data_insert_start(struct closure *);
  23. /* Cgroup interface */
  24. #ifdef CONFIG_CGROUP_BCACHE
  25. static struct bch_cgroup bcache_default_cgroup = { .cache_mode = -1 };
  26. static struct bch_cgroup *cgroup_to_bcache(struct cgroup *cgroup)
  27. {
  28. struct cgroup_subsys_state *css;
  29. return cgroup &&
  30. (css = cgroup_subsys_state(cgroup, bcache_subsys_id))
  31. ? container_of(css, struct bch_cgroup, css)
  32. : &bcache_default_cgroup;
  33. }
  34. struct bch_cgroup *bch_bio_to_cgroup(struct bio *bio)
  35. {
  36. struct cgroup_subsys_state *css = bio->bi_css
  37. ? cgroup_subsys_state(bio->bi_css->cgroup, bcache_subsys_id)
  38. : task_subsys_state(current, bcache_subsys_id);
  39. return css
  40. ? container_of(css, struct bch_cgroup, css)
  41. : &bcache_default_cgroup;
  42. }
  43. static ssize_t cache_mode_read(struct cgroup *cgrp, struct cftype *cft,
  44. struct file *file,
  45. char __user *buf, size_t nbytes, loff_t *ppos)
  46. {
  47. char tmp[1024];
  48. int len = bch_snprint_string_list(tmp, PAGE_SIZE, bch_cache_modes,
  49. cgroup_to_bcache(cgrp)->cache_mode + 1);
  50. if (len < 0)
  51. return len;
  52. return simple_read_from_buffer(buf, nbytes, ppos, tmp, len);
  53. }
  54. static int cache_mode_write(struct cgroup *cgrp, struct cftype *cft,
  55. const char *buf)
  56. {
  57. int v = bch_read_string_list(buf, bch_cache_modes);
  58. if (v < 0)
  59. return v;
  60. cgroup_to_bcache(cgrp)->cache_mode = v - 1;
  61. return 0;
  62. }
  63. static u64 bch_verify_read(struct cgroup *cgrp, struct cftype *cft)
  64. {
  65. return cgroup_to_bcache(cgrp)->verify;
  66. }
  67. static int bch_verify_write(struct cgroup *cgrp, struct cftype *cft, u64 val)
  68. {
  69. cgroup_to_bcache(cgrp)->verify = val;
  70. return 0;
  71. }
  72. static u64 bch_cache_hits_read(struct cgroup *cgrp, struct cftype *cft)
  73. {
  74. struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp);
  75. return atomic_read(&bcachecg->stats.cache_hits);
  76. }
  77. static u64 bch_cache_misses_read(struct cgroup *cgrp, struct cftype *cft)
  78. {
  79. struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp);
  80. return atomic_read(&bcachecg->stats.cache_misses);
  81. }
  82. static u64 bch_cache_bypass_hits_read(struct cgroup *cgrp,
  83. struct cftype *cft)
  84. {
  85. struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp);
  86. return atomic_read(&bcachecg->stats.cache_bypass_hits);
  87. }
  88. static u64 bch_cache_bypass_misses_read(struct cgroup *cgrp,
  89. struct cftype *cft)
  90. {
  91. struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp);
  92. return atomic_read(&bcachecg->stats.cache_bypass_misses);
  93. }
  94. static struct cftype bch_files[] = {
  95. {
  96. .name = "cache_mode",
  97. .read = cache_mode_read,
  98. .write_string = cache_mode_write,
  99. },
  100. {
  101. .name = "verify",
  102. .read_u64 = bch_verify_read,
  103. .write_u64 = bch_verify_write,
  104. },
  105. {
  106. .name = "cache_hits",
  107. .read_u64 = bch_cache_hits_read,
  108. },
  109. {
  110. .name = "cache_misses",
  111. .read_u64 = bch_cache_misses_read,
  112. },
  113. {
  114. .name = "cache_bypass_hits",
  115. .read_u64 = bch_cache_bypass_hits_read,
  116. },
  117. {
  118. .name = "cache_bypass_misses",
  119. .read_u64 = bch_cache_bypass_misses_read,
  120. },
  121. { } /* terminate */
  122. };
  123. static void init_bch_cgroup(struct bch_cgroup *cg)
  124. {
  125. cg->cache_mode = -1;
  126. }
  127. static struct cgroup_subsys_state *bcachecg_create(struct cgroup *cgroup)
  128. {
  129. struct bch_cgroup *cg;
  130. cg = kzalloc(sizeof(*cg), GFP_KERNEL);
  131. if (!cg)
  132. return ERR_PTR(-ENOMEM);
  133. init_bch_cgroup(cg);
  134. return &cg->css;
  135. }
  136. static void bcachecg_destroy(struct cgroup *cgroup)
  137. {
  138. struct bch_cgroup *cg = cgroup_to_bcache(cgroup);
  139. free_css_id(&bcache_subsys, &cg->css);
  140. kfree(cg);
  141. }
  142. struct cgroup_subsys bcache_subsys = {
  143. .create = bcachecg_create,
  144. .destroy = bcachecg_destroy,
  145. .subsys_id = bcache_subsys_id,
  146. .name = "bcache",
  147. .module = THIS_MODULE,
  148. };
  149. EXPORT_SYMBOL_GPL(bcache_subsys);
  150. #endif
  151. static unsigned cache_mode(struct cached_dev *dc, struct bio *bio)
  152. {
  153. #ifdef CONFIG_CGROUP_BCACHE
  154. int r = bch_bio_to_cgroup(bio)->cache_mode;
  155. if (r >= 0)
  156. return r;
  157. #endif
  158. return BDEV_CACHE_MODE(&dc->sb);
  159. }
  160. static bool verify(struct cached_dev *dc, struct bio *bio)
  161. {
  162. #ifdef CONFIG_CGROUP_BCACHE
  163. if (bch_bio_to_cgroup(bio)->verify)
  164. return true;
  165. #endif
  166. return dc->verify;
  167. }
  168. static void bio_csum(struct bio *bio, struct bkey *k)
  169. {
  170. struct bio_vec *bv;
  171. uint64_t csum = 0;
  172. int i;
  173. bio_for_each_segment(bv, bio, i) {
  174. void *d = kmap(bv->bv_page) + bv->bv_offset;
  175. csum = bch_crc64_update(csum, d, bv->bv_len);
  176. kunmap(bv->bv_page);
  177. }
  178. k->ptr[KEY_PTRS(k)] = csum & (~0ULL >> 1);
  179. }
  180. /* Insert data into cache */
  181. static void bch_data_insert_keys(struct closure *cl)
  182. {
  183. struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
  184. atomic_t *journal_ref = NULL;
  185. struct bkey *replace_key = op->replace ? &op->replace_key : NULL;
  186. int ret;
  187. /*
  188. * If we're looping, might already be waiting on
  189. * another journal write - can't wait on more than one journal write at
  190. * a time
  191. *
  192. * XXX: this looks wrong
  193. */
  194. #if 0
  195. while (atomic_read(&s->cl.remaining) & CLOSURE_WAITING)
  196. closure_sync(&s->cl);
  197. #endif
  198. if (!op->replace)
  199. journal_ref = bch_journal(op->c, &op->insert_keys,
  200. op->flush_journal ? cl : NULL);
  201. ret = bch_btree_insert(op->c, &op->insert_keys,
  202. journal_ref, replace_key);
  203. if (ret == -ESRCH) {
  204. op->replace_collision = true;
  205. } else if (ret) {
  206. op->error = -ENOMEM;
  207. op->insert_data_done = true;
  208. }
  209. if (journal_ref)
  210. atomic_dec_bug(journal_ref);
  211. if (!op->insert_data_done)
  212. continue_at(cl, bch_data_insert_start, bcache_wq);
  213. bch_keylist_free(&op->insert_keys);
  214. closure_return(cl);
  215. }
  216. static void bch_data_invalidate(struct closure *cl)
  217. {
  218. struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
  219. struct bio *bio = op->bio;
  220. pr_debug("invalidating %i sectors from %llu",
  221. bio_sectors(bio), (uint64_t) bio->bi_sector);
  222. while (bio_sectors(bio)) {
  223. unsigned sectors = min(bio_sectors(bio),
  224. 1U << (KEY_SIZE_BITS - 1));
  225. if (bch_keylist_realloc(&op->insert_keys, 0, op->c))
  226. goto out;
  227. bio->bi_sector += sectors;
  228. bio->bi_size -= sectors << 9;
  229. bch_keylist_add(&op->insert_keys,
  230. &KEY(op->inode, bio->bi_sector, sectors));
  231. }
  232. op->insert_data_done = true;
  233. bio_put(bio);
  234. out:
  235. continue_at(cl, bch_data_insert_keys, bcache_wq);
  236. }
  237. static void bch_data_insert_error(struct closure *cl)
  238. {
  239. struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
  240. /*
  241. * Our data write just errored, which means we've got a bunch of keys to
  242. * insert that point to data that wasn't succesfully written.
  243. *
  244. * We don't have to insert those keys but we still have to invalidate
  245. * that region of the cache - so, if we just strip off all the pointers
  246. * from the keys we'll accomplish just that.
  247. */
  248. struct bkey *src = op->insert_keys.keys, *dst = op->insert_keys.keys;
  249. while (src != op->insert_keys.top) {
  250. struct bkey *n = bkey_next(src);
  251. SET_KEY_PTRS(src, 0);
  252. memmove(dst, src, bkey_bytes(src));
  253. dst = bkey_next(dst);
  254. src = n;
  255. }
  256. op->insert_keys.top = dst;
  257. bch_data_insert_keys(cl);
  258. }
  259. static void bch_data_insert_endio(struct bio *bio, int error)
  260. {
  261. struct closure *cl = bio->bi_private;
  262. struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
  263. if (error) {
  264. /* TODO: We could try to recover from this. */
  265. if (op->writeback)
  266. op->error = error;
  267. else if (!op->replace)
  268. set_closure_fn(cl, bch_data_insert_error, bcache_wq);
  269. else
  270. set_closure_fn(cl, NULL, NULL);
  271. }
  272. bch_bbio_endio(op->c, bio, error, "writing data to cache");
  273. }
  274. static void bch_data_insert_start(struct closure *cl)
  275. {
  276. struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
  277. struct bio *bio = op->bio, *n;
  278. if (op->bypass)
  279. return bch_data_invalidate(cl);
  280. if (atomic_sub_return(bio_sectors(bio), &op->c->sectors_to_gc) < 0) {
  281. set_gc_sectors(op->c);
  282. wake_up_gc(op->c);
  283. }
  284. /*
  285. * Journal writes are marked REQ_FLUSH; if the original write was a
  286. * flush, it'll wait on the journal write.
  287. */
  288. bio->bi_rw &= ~(REQ_FLUSH|REQ_FUA);
  289. do {
  290. unsigned i;
  291. struct bkey *k;
  292. struct bio_set *split = op->c->bio_split;
  293. /* 1 for the device pointer and 1 for the chksum */
  294. if (bch_keylist_realloc(&op->insert_keys,
  295. 1 + (op->csum ? 1 : 0),
  296. op->c))
  297. continue_at(cl, bch_data_insert_keys, bcache_wq);
  298. k = op->insert_keys.top;
  299. bkey_init(k);
  300. SET_KEY_INODE(k, op->inode);
  301. SET_KEY_OFFSET(k, bio->bi_sector);
  302. if (!bch_alloc_sectors(op->c, k, bio_sectors(bio),
  303. op->write_point, op->write_prio,
  304. op->writeback))
  305. goto err;
  306. n = bch_bio_split(bio, KEY_SIZE(k), GFP_NOIO, split);
  307. n->bi_end_io = bch_data_insert_endio;
  308. n->bi_private = cl;
  309. if (op->writeback) {
  310. SET_KEY_DIRTY(k, true);
  311. for (i = 0; i < KEY_PTRS(k); i++)
  312. SET_GC_MARK(PTR_BUCKET(op->c, k, i),
  313. GC_MARK_DIRTY);
  314. }
  315. SET_KEY_CSUM(k, op->csum);
  316. if (KEY_CSUM(k))
  317. bio_csum(n, k);
  318. trace_bcache_cache_insert(k);
  319. bch_keylist_push(&op->insert_keys);
  320. n->bi_rw |= REQ_WRITE;
  321. bch_submit_bbio(n, op->c, k, 0);
  322. } while (n != bio);
  323. op->insert_data_done = true;
  324. continue_at(cl, bch_data_insert_keys, bcache_wq);
  325. err:
  326. /* bch_alloc_sectors() blocks if s->writeback = true */
  327. BUG_ON(op->writeback);
  328. /*
  329. * But if it's not a writeback write we'd rather just bail out if
  330. * there aren't any buckets ready to write to - it might take awhile and
  331. * we might be starving btree writes for gc or something.
  332. */
  333. if (!op->replace) {
  334. /*
  335. * Writethrough write: We can't complete the write until we've
  336. * updated the index. But we don't want to delay the write while
  337. * we wait for buckets to be freed up, so just invalidate the
  338. * rest of the write.
  339. */
  340. op->bypass = true;
  341. return bch_data_invalidate(cl);
  342. } else {
  343. /*
  344. * From a cache miss, we can just insert the keys for the data
  345. * we have written or bail out if we didn't do anything.
  346. */
  347. op->insert_data_done = true;
  348. bio_put(bio);
  349. if (!bch_keylist_empty(&op->insert_keys))
  350. continue_at(cl, bch_data_insert_keys, bcache_wq);
  351. else
  352. closure_return(cl);
  353. }
  354. }
  355. /**
  356. * bch_data_insert - stick some data in the cache
  357. *
  358. * This is the starting point for any data to end up in a cache device; it could
  359. * be from a normal write, or a writeback write, or a write to a flash only
  360. * volume - it's also used by the moving garbage collector to compact data in
  361. * mostly empty buckets.
  362. *
  363. * It first writes the data to the cache, creating a list of keys to be inserted
  364. * (if the data had to be fragmented there will be multiple keys); after the
  365. * data is written it calls bch_journal, and after the keys have been added to
  366. * the next journal write they're inserted into the btree.
  367. *
  368. * It inserts the data in s->cache_bio; bi_sector is used for the key offset,
  369. * and op->inode is used for the key inode.
  370. *
  371. * If s->bypass is true, instead of inserting the data it invalidates the
  372. * region of the cache represented by s->cache_bio and op->inode.
  373. */
  374. void bch_data_insert(struct closure *cl)
  375. {
  376. struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
  377. trace_bcache_write(op->bio, op->writeback, op->bypass);
  378. bch_keylist_init(&op->insert_keys);
  379. bio_get(op->bio);
  380. bch_data_insert_start(cl);
  381. }
  382. /* Congested? */
  383. unsigned bch_get_congested(struct cache_set *c)
  384. {
  385. int i;
  386. long rand;
  387. if (!c->congested_read_threshold_us &&
  388. !c->congested_write_threshold_us)
  389. return 0;
  390. i = (local_clock_us() - c->congested_last_us) / 1024;
  391. if (i < 0)
  392. return 0;
  393. i += atomic_read(&c->congested);
  394. if (i >= 0)
  395. return 0;
  396. i += CONGESTED_MAX;
  397. if (i > 0)
  398. i = fract_exp_two(i, 6);
  399. rand = get_random_int();
  400. i -= bitmap_weight(&rand, BITS_PER_LONG);
  401. return i > 0 ? i : 1;
  402. }
  403. static void add_sequential(struct task_struct *t)
  404. {
  405. ewma_add(t->sequential_io_avg,
  406. t->sequential_io, 8, 0);
  407. t->sequential_io = 0;
  408. }
  409. static struct hlist_head *iohash(struct cached_dev *dc, uint64_t k)
  410. {
  411. return &dc->io_hash[hash_64(k, RECENT_IO_BITS)];
  412. }
  413. static bool check_should_bypass(struct cached_dev *dc, struct bio *bio)
  414. {
  415. struct cache_set *c = dc->disk.c;
  416. unsigned mode = cache_mode(dc, bio);
  417. unsigned sectors, congested = bch_get_congested(c);
  418. struct task_struct *task = current;
  419. if (atomic_read(&dc->disk.detaching) ||
  420. c->gc_stats.in_use > CUTOFF_CACHE_ADD ||
  421. (bio->bi_rw & REQ_DISCARD))
  422. goto skip;
  423. if (mode == CACHE_MODE_NONE ||
  424. (mode == CACHE_MODE_WRITEAROUND &&
  425. (bio->bi_rw & REQ_WRITE)))
  426. goto skip;
  427. if (bio->bi_sector & (c->sb.block_size - 1) ||
  428. bio_sectors(bio) & (c->sb.block_size - 1)) {
  429. pr_debug("skipping unaligned io");
  430. goto skip;
  431. }
  432. if (!congested && !dc->sequential_cutoff)
  433. goto rescale;
  434. if (!congested &&
  435. mode == CACHE_MODE_WRITEBACK &&
  436. (bio->bi_rw & REQ_WRITE) &&
  437. (bio->bi_rw & REQ_SYNC))
  438. goto rescale;
  439. if (dc->sequential_merge) {
  440. struct io *i;
  441. spin_lock(&dc->io_lock);
  442. hlist_for_each_entry(i, iohash(dc, bio->bi_sector), hash)
  443. if (i->last == bio->bi_sector &&
  444. time_before(jiffies, i->jiffies))
  445. goto found;
  446. i = list_first_entry(&dc->io_lru, struct io, lru);
  447. add_sequential(task);
  448. i->sequential = 0;
  449. found:
  450. if (i->sequential + bio->bi_size > i->sequential)
  451. i->sequential += bio->bi_size;
  452. i->last = bio_end_sector(bio);
  453. i->jiffies = jiffies + msecs_to_jiffies(5000);
  454. task->sequential_io = i->sequential;
  455. hlist_del(&i->hash);
  456. hlist_add_head(&i->hash, iohash(dc, i->last));
  457. list_move_tail(&i->lru, &dc->io_lru);
  458. spin_unlock(&dc->io_lock);
  459. } else {
  460. task->sequential_io = bio->bi_size;
  461. add_sequential(task);
  462. }
  463. sectors = max(task->sequential_io,
  464. task->sequential_io_avg) >> 9;
  465. if (dc->sequential_cutoff &&
  466. sectors >= dc->sequential_cutoff >> 9) {
  467. trace_bcache_bypass_sequential(bio);
  468. goto skip;
  469. }
  470. if (congested && sectors >= congested) {
  471. trace_bcache_bypass_congested(bio);
  472. goto skip;
  473. }
  474. rescale:
  475. bch_rescale_priorities(c, bio_sectors(bio));
  476. return false;
  477. skip:
  478. bch_mark_sectors_bypassed(c, dc, bio_sectors(bio));
  479. return true;
  480. }
  481. /* Cache lookup */
  482. struct search {
  483. /* Stack frame for bio_complete */
  484. struct closure cl;
  485. struct bcache_device *d;
  486. struct bbio bio;
  487. struct bio *orig_bio;
  488. struct bio *cache_miss;
  489. unsigned insert_bio_sectors;
  490. unsigned recoverable:1;
  491. unsigned unaligned_bvec:1;
  492. unsigned write:1;
  493. unsigned long start_time;
  494. struct btree_op op;
  495. struct data_insert_op iop;
  496. };
  497. static void bch_cache_read_endio(struct bio *bio, int error)
  498. {
  499. struct bbio *b = container_of(bio, struct bbio, bio);
  500. struct closure *cl = bio->bi_private;
  501. struct search *s = container_of(cl, struct search, cl);
  502. /*
  503. * If the bucket was reused while our bio was in flight, we might have
  504. * read the wrong data. Set s->error but not error so it doesn't get
  505. * counted against the cache device, but we'll still reread the data
  506. * from the backing device.
  507. */
  508. if (error)
  509. s->iop.error = error;
  510. else if (ptr_stale(s->iop.c, &b->key, 0)) {
  511. atomic_long_inc(&s->iop.c->cache_read_races);
  512. s->iop.error = -EINTR;
  513. }
  514. bch_bbio_endio(s->iop.c, bio, error, "reading from cache");
  515. }
  516. /*
  517. * Read from a single key, handling the initial cache miss if the key starts in
  518. * the middle of the bio
  519. */
  520. static int cache_lookup_fn(struct btree_op *op, struct btree *b, struct bkey *k)
  521. {
  522. struct search *s = container_of(op, struct search, op);
  523. struct bio *n, *bio = &s->bio.bio;
  524. struct bkey *bio_key;
  525. unsigned ptr;
  526. if (bkey_cmp(k, &KEY(s->iop.inode, bio->bi_sector, 0)) <= 0)
  527. return MAP_CONTINUE;
  528. if (KEY_INODE(k) != s->iop.inode ||
  529. KEY_START(k) > bio->bi_sector) {
  530. unsigned bio_sectors = bio_sectors(bio);
  531. unsigned sectors = KEY_INODE(k) == s->iop.inode
  532. ? min_t(uint64_t, INT_MAX,
  533. KEY_START(k) - bio->bi_sector)
  534. : INT_MAX;
  535. int ret = s->d->cache_miss(b, s, bio, sectors);
  536. if (ret != MAP_CONTINUE)
  537. return ret;
  538. /* if this was a complete miss we shouldn't get here */
  539. BUG_ON(bio_sectors <= sectors);
  540. }
  541. if (!KEY_SIZE(k))
  542. return MAP_CONTINUE;
  543. /* XXX: figure out best pointer - for multiple cache devices */
  544. ptr = 0;
  545. PTR_BUCKET(b->c, k, ptr)->prio = INITIAL_PRIO;
  546. n = bch_bio_split(bio, min_t(uint64_t, INT_MAX,
  547. KEY_OFFSET(k) - bio->bi_sector),
  548. GFP_NOIO, s->d->bio_split);
  549. bio_key = &container_of(n, struct bbio, bio)->key;
  550. bch_bkey_copy_single_ptr(bio_key, k, ptr);
  551. bch_cut_front(&KEY(s->iop.inode, n->bi_sector, 0), bio_key);
  552. bch_cut_back(&KEY(s->iop.inode, bio_end_sector(n), 0), bio_key);
  553. n->bi_end_io = bch_cache_read_endio;
  554. n->bi_private = &s->cl;
  555. /*
  556. * The bucket we're reading from might be reused while our bio
  557. * is in flight, and we could then end up reading the wrong
  558. * data.
  559. *
  560. * We guard against this by checking (in cache_read_endio()) if
  561. * the pointer is stale again; if so, we treat it as an error
  562. * and reread from the backing device (but we don't pass that
  563. * error up anywhere).
  564. */
  565. __bch_submit_bbio(n, b->c);
  566. return n == bio ? MAP_DONE : MAP_CONTINUE;
  567. }
  568. static void cache_lookup(struct closure *cl)
  569. {
  570. struct search *s = container_of(cl, struct search, iop.cl);
  571. struct bio *bio = &s->bio.bio;
  572. int ret = bch_btree_map_keys(&s->op, s->iop.c,
  573. &KEY(s->iop.inode, bio->bi_sector, 0),
  574. cache_lookup_fn, MAP_END_KEY);
  575. if (ret == -EAGAIN)
  576. continue_at(cl, cache_lookup, bcache_wq);
  577. closure_return(cl);
  578. }
  579. /* Common code for the make_request functions */
  580. static void request_endio(struct bio *bio, int error)
  581. {
  582. struct closure *cl = bio->bi_private;
  583. if (error) {
  584. struct search *s = container_of(cl, struct search, cl);
  585. s->iop.error = error;
  586. /* Only cache read errors are recoverable */
  587. s->recoverable = false;
  588. }
  589. bio_put(bio);
  590. closure_put(cl);
  591. }
  592. static void bio_complete(struct search *s)
  593. {
  594. if (s->orig_bio) {
  595. int cpu, rw = bio_data_dir(s->orig_bio);
  596. unsigned long duration = jiffies - s->start_time;
  597. cpu = part_stat_lock();
  598. part_round_stats(cpu, &s->d->disk->part0);
  599. part_stat_add(cpu, &s->d->disk->part0, ticks[rw], duration);
  600. part_stat_unlock();
  601. trace_bcache_request_end(s->d, s->orig_bio);
  602. bio_endio(s->orig_bio, s->iop.error);
  603. s->orig_bio = NULL;
  604. }
  605. }
  606. static void do_bio_hook(struct search *s)
  607. {
  608. struct bio *bio = &s->bio.bio;
  609. memcpy(bio, s->orig_bio, sizeof(struct bio));
  610. bio->bi_end_io = request_endio;
  611. bio->bi_private = &s->cl;
  612. atomic_set(&bio->bi_cnt, 3);
  613. }
  614. static void search_free(struct closure *cl)
  615. {
  616. struct search *s = container_of(cl, struct search, cl);
  617. bio_complete(s);
  618. if (s->iop.bio)
  619. bio_put(s->iop.bio);
  620. if (s->unaligned_bvec)
  621. mempool_free(s->bio.bio.bi_io_vec, s->d->unaligned_bvec);
  622. closure_debug_destroy(cl);
  623. mempool_free(s, s->d->c->search);
  624. }
  625. static struct search *search_alloc(struct bio *bio, struct bcache_device *d)
  626. {
  627. struct search *s;
  628. struct bio_vec *bv;
  629. s = mempool_alloc(d->c->search, GFP_NOIO);
  630. memset(s, 0, offsetof(struct search, iop.insert_keys));
  631. __closure_init(&s->cl, NULL);
  632. s->iop.inode = d->id;
  633. s->iop.c = d->c;
  634. s->d = d;
  635. s->op.lock = -1;
  636. s->iop.write_point = hash_long((unsigned long) current, 16);
  637. s->orig_bio = bio;
  638. s->write = (bio->bi_rw & REQ_WRITE) != 0;
  639. s->iop.flush_journal = (bio->bi_rw & (REQ_FLUSH|REQ_FUA)) != 0;
  640. s->recoverable = 1;
  641. s->start_time = jiffies;
  642. do_bio_hook(s);
  643. if (bio->bi_size != bio_segments(bio) * PAGE_SIZE) {
  644. bv = mempool_alloc(d->unaligned_bvec, GFP_NOIO);
  645. memcpy(bv, bio_iovec(bio),
  646. sizeof(struct bio_vec) * bio_segments(bio));
  647. s->bio.bio.bi_io_vec = bv;
  648. s->unaligned_bvec = 1;
  649. }
  650. return s;
  651. }
  652. /* Cached devices */
  653. static void cached_dev_bio_complete(struct closure *cl)
  654. {
  655. struct search *s = container_of(cl, struct search, cl);
  656. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  657. search_free(cl);
  658. cached_dev_put(dc);
  659. }
  660. /* Process reads */
  661. static void cached_dev_cache_miss_done(struct closure *cl)
  662. {
  663. struct search *s = container_of(cl, struct search, cl);
  664. if (s->iop.replace_collision)
  665. bch_mark_cache_miss_collision(s->iop.c, s->d);
  666. if (s->iop.bio) {
  667. int i;
  668. struct bio_vec *bv;
  669. bio_for_each_segment_all(bv, s->iop.bio, i)
  670. __free_page(bv->bv_page);
  671. }
  672. cached_dev_bio_complete(cl);
  673. }
  674. static void cached_dev_read_error(struct closure *cl)
  675. {
  676. struct search *s = container_of(cl, struct search, cl);
  677. struct bio *bio = &s->bio.bio;
  678. struct bio_vec *bv;
  679. int i;
  680. if (s->recoverable) {
  681. /* Retry from the backing device: */
  682. trace_bcache_read_retry(s->orig_bio);
  683. s->iop.error = 0;
  684. bv = s->bio.bio.bi_io_vec;
  685. do_bio_hook(s);
  686. s->bio.bio.bi_io_vec = bv;
  687. if (!s->unaligned_bvec)
  688. bio_for_each_segment(bv, s->orig_bio, i)
  689. bv->bv_offset = 0, bv->bv_len = PAGE_SIZE;
  690. else
  691. memcpy(s->bio.bio.bi_io_vec,
  692. bio_iovec(s->orig_bio),
  693. sizeof(struct bio_vec) *
  694. bio_segments(s->orig_bio));
  695. /* XXX: invalidate cache */
  696. closure_bio_submit(bio, cl, s->d);
  697. }
  698. continue_at(cl, cached_dev_cache_miss_done, NULL);
  699. }
  700. static void cached_dev_read_done(struct closure *cl)
  701. {
  702. struct search *s = container_of(cl, struct search, cl);
  703. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  704. /*
  705. * We had a cache miss; cache_bio now contains data ready to be inserted
  706. * into the cache.
  707. *
  708. * First, we copy the data we just read from cache_bio's bounce buffers
  709. * to the buffers the original bio pointed to:
  710. */
  711. if (s->iop.bio) {
  712. bio_reset(s->iop.bio);
  713. s->iop.bio->bi_sector = s->cache_miss->bi_sector;
  714. s->iop.bio->bi_bdev = s->cache_miss->bi_bdev;
  715. s->iop.bio->bi_size = s->insert_bio_sectors << 9;
  716. bch_bio_map(s->iop.bio, NULL);
  717. bio_copy_data(s->cache_miss, s->iop.bio);
  718. bio_put(s->cache_miss);
  719. s->cache_miss = NULL;
  720. }
  721. if (verify(dc, &s->bio.bio) && s->recoverable && !s->unaligned_bvec)
  722. bch_data_verify(dc, s->orig_bio);
  723. bio_complete(s);
  724. if (s->iop.bio &&
  725. !test_bit(CACHE_SET_STOPPING, &s->iop.c->flags)) {
  726. BUG_ON(!s->iop.replace);
  727. closure_call(&s->iop.cl, bch_data_insert, NULL, cl);
  728. }
  729. continue_at(cl, cached_dev_cache_miss_done, NULL);
  730. }
  731. static void cached_dev_read_done_bh(struct closure *cl)
  732. {
  733. struct search *s = container_of(cl, struct search, cl);
  734. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  735. bch_mark_cache_accounting(s->iop.c, s->d,
  736. !s->cache_miss, s->iop.bypass);
  737. trace_bcache_read(s->orig_bio, !s->cache_miss, s->iop.bypass);
  738. if (s->iop.error)
  739. continue_at_nobarrier(cl, cached_dev_read_error, bcache_wq);
  740. else if (s->iop.bio || verify(dc, &s->bio.bio))
  741. continue_at_nobarrier(cl, cached_dev_read_done, bcache_wq);
  742. else
  743. continue_at_nobarrier(cl, cached_dev_bio_complete, NULL);
  744. }
  745. static int cached_dev_cache_miss(struct btree *b, struct search *s,
  746. struct bio *bio, unsigned sectors)
  747. {
  748. int ret = MAP_CONTINUE;
  749. unsigned reada = 0;
  750. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  751. struct bio *miss, *cache_bio;
  752. if (s->cache_miss || s->iop.bypass) {
  753. miss = bch_bio_split(bio, sectors, GFP_NOIO, s->d->bio_split);
  754. ret = miss == bio ? MAP_DONE : MAP_CONTINUE;
  755. goto out_submit;
  756. }
  757. if (!(bio->bi_rw & REQ_RAHEAD) &&
  758. !(bio->bi_rw & REQ_META) &&
  759. s->iop.c->gc_stats.in_use < CUTOFF_CACHE_READA)
  760. reada = min_t(sector_t, dc->readahead >> 9,
  761. bdev_sectors(bio->bi_bdev) - bio_end_sector(bio));
  762. s->insert_bio_sectors = min(sectors, bio_sectors(bio) + reada);
  763. s->iop.replace_key = KEY(s->iop.inode,
  764. bio->bi_sector + s->insert_bio_sectors,
  765. s->insert_bio_sectors);
  766. ret = bch_btree_insert_check_key(b, &s->op, &s->iop.replace_key);
  767. if (ret)
  768. return ret;
  769. s->iop.replace = true;
  770. miss = bch_bio_split(bio, sectors, GFP_NOIO, s->d->bio_split);
  771. /* btree_search_recurse()'s btree iterator is no good anymore */
  772. ret = miss == bio ? MAP_DONE : -EINTR;
  773. cache_bio = bio_alloc_bioset(GFP_NOWAIT,
  774. DIV_ROUND_UP(s->insert_bio_sectors, PAGE_SECTORS),
  775. dc->disk.bio_split);
  776. if (!cache_bio)
  777. goto out_submit;
  778. cache_bio->bi_sector = miss->bi_sector;
  779. cache_bio->bi_bdev = miss->bi_bdev;
  780. cache_bio->bi_size = s->insert_bio_sectors << 9;
  781. cache_bio->bi_end_io = request_endio;
  782. cache_bio->bi_private = &s->cl;
  783. bch_bio_map(cache_bio, NULL);
  784. if (bio_alloc_pages(cache_bio, __GFP_NOWARN|GFP_NOIO))
  785. goto out_put;
  786. if (reada)
  787. bch_mark_cache_readahead(s->iop.c, s->d);
  788. s->cache_miss = miss;
  789. s->iop.bio = cache_bio;
  790. bio_get(cache_bio);
  791. closure_bio_submit(cache_bio, &s->cl, s->d);
  792. return ret;
  793. out_put:
  794. bio_put(cache_bio);
  795. out_submit:
  796. miss->bi_end_io = request_endio;
  797. miss->bi_private = &s->cl;
  798. closure_bio_submit(miss, &s->cl, s->d);
  799. return ret;
  800. }
  801. static void cached_dev_read(struct cached_dev *dc, struct search *s)
  802. {
  803. struct closure *cl = &s->cl;
  804. closure_call(&s->iop.cl, cache_lookup, NULL, cl);
  805. continue_at(cl, cached_dev_read_done_bh, NULL);
  806. }
  807. /* Process writes */
  808. static void cached_dev_write_complete(struct closure *cl)
  809. {
  810. struct search *s = container_of(cl, struct search, cl);
  811. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  812. up_read_non_owner(&dc->writeback_lock);
  813. cached_dev_bio_complete(cl);
  814. }
  815. static void cached_dev_write(struct cached_dev *dc, struct search *s)
  816. {
  817. struct closure *cl = &s->cl;
  818. struct bio *bio = &s->bio.bio;
  819. struct bkey start = KEY(dc->disk.id, bio->bi_sector, 0);
  820. struct bkey end = KEY(dc->disk.id, bio_end_sector(bio), 0);
  821. bch_keybuf_check_overlapping(&s->iop.c->moving_gc_keys, &start, &end);
  822. down_read_non_owner(&dc->writeback_lock);
  823. if (bch_keybuf_check_overlapping(&dc->writeback_keys, &start, &end)) {
  824. /*
  825. * We overlap with some dirty data undergoing background
  826. * writeback, force this write to writeback
  827. */
  828. s->iop.bypass = false;
  829. s->iop.writeback = true;
  830. }
  831. /*
  832. * Discards aren't _required_ to do anything, so skipping if
  833. * check_overlapping returned true is ok
  834. *
  835. * But check_overlapping drops dirty keys for which io hasn't started,
  836. * so we still want to call it.
  837. */
  838. if (bio->bi_rw & REQ_DISCARD)
  839. s->iop.bypass = true;
  840. if (should_writeback(dc, s->orig_bio,
  841. cache_mode(dc, bio),
  842. s->iop.bypass)) {
  843. s->iop.bypass = false;
  844. s->iop.writeback = true;
  845. }
  846. if (s->iop.bypass) {
  847. s->iop.bio = s->orig_bio;
  848. bio_get(s->iop.bio);
  849. if (!(bio->bi_rw & REQ_DISCARD) ||
  850. blk_queue_discard(bdev_get_queue(dc->bdev)))
  851. closure_bio_submit(bio, cl, s->d);
  852. } else if (s->iop.writeback) {
  853. bch_writeback_add(dc);
  854. s->iop.bio = bio;
  855. if (bio->bi_rw & REQ_FLUSH) {
  856. /* Also need to send a flush to the backing device */
  857. struct bio *flush = bio_alloc_bioset(GFP_NOIO, 0,
  858. dc->disk.bio_split);
  859. flush->bi_rw = WRITE_FLUSH;
  860. flush->bi_bdev = bio->bi_bdev;
  861. flush->bi_end_io = request_endio;
  862. flush->bi_private = cl;
  863. closure_bio_submit(flush, cl, s->d);
  864. }
  865. } else {
  866. s->iop.bio = bio_clone_bioset(bio, GFP_NOIO,
  867. dc->disk.bio_split);
  868. closure_bio_submit(bio, cl, s->d);
  869. }
  870. closure_call(&s->iop.cl, bch_data_insert, NULL, cl);
  871. continue_at(cl, cached_dev_write_complete, NULL);
  872. }
  873. static void cached_dev_nodata(struct closure *cl)
  874. {
  875. struct search *s = container_of(cl, struct search, cl);
  876. struct bio *bio = &s->bio.bio;
  877. if (s->iop.flush_journal)
  878. bch_journal_meta(s->iop.c, cl);
  879. /* If it's a flush, we send the flush to the backing device too */
  880. closure_bio_submit(bio, cl, s->d);
  881. continue_at(cl, cached_dev_bio_complete, NULL);
  882. }
  883. /* Cached devices - read & write stuff */
  884. static void cached_dev_make_request(struct request_queue *q, struct bio *bio)
  885. {
  886. struct search *s;
  887. struct bcache_device *d = bio->bi_bdev->bd_disk->private_data;
  888. struct cached_dev *dc = container_of(d, struct cached_dev, disk);
  889. int cpu, rw = bio_data_dir(bio);
  890. cpu = part_stat_lock();
  891. part_stat_inc(cpu, &d->disk->part0, ios[rw]);
  892. part_stat_add(cpu, &d->disk->part0, sectors[rw], bio_sectors(bio));
  893. part_stat_unlock();
  894. bio->bi_bdev = dc->bdev;
  895. bio->bi_sector += dc->sb.data_offset;
  896. if (cached_dev_get(dc)) {
  897. s = search_alloc(bio, d);
  898. trace_bcache_request_start(s->d, bio);
  899. if (!bio->bi_size) {
  900. /*
  901. * can't call bch_journal_meta from under
  902. * generic_make_request
  903. */
  904. continue_at_nobarrier(&s->cl,
  905. cached_dev_nodata,
  906. bcache_wq);
  907. } else {
  908. s->iop.bypass = check_should_bypass(dc, bio);
  909. if (rw)
  910. cached_dev_write(dc, s);
  911. else
  912. cached_dev_read(dc, s);
  913. }
  914. } else {
  915. if ((bio->bi_rw & REQ_DISCARD) &&
  916. !blk_queue_discard(bdev_get_queue(dc->bdev)))
  917. bio_endio(bio, 0);
  918. else
  919. bch_generic_make_request(bio, &d->bio_split_hook);
  920. }
  921. }
  922. static int cached_dev_ioctl(struct bcache_device *d, fmode_t mode,
  923. unsigned int cmd, unsigned long arg)
  924. {
  925. struct cached_dev *dc = container_of(d, struct cached_dev, disk);
  926. return __blkdev_driver_ioctl(dc->bdev, mode, cmd, arg);
  927. }
  928. static int cached_dev_congested(void *data, int bits)
  929. {
  930. struct bcache_device *d = data;
  931. struct cached_dev *dc = container_of(d, struct cached_dev, disk);
  932. struct request_queue *q = bdev_get_queue(dc->bdev);
  933. int ret = 0;
  934. if (bdi_congested(&q->backing_dev_info, bits))
  935. return 1;
  936. if (cached_dev_get(dc)) {
  937. unsigned i;
  938. struct cache *ca;
  939. for_each_cache(ca, d->c, i) {
  940. q = bdev_get_queue(ca->bdev);
  941. ret |= bdi_congested(&q->backing_dev_info, bits);
  942. }
  943. cached_dev_put(dc);
  944. }
  945. return ret;
  946. }
  947. void bch_cached_dev_request_init(struct cached_dev *dc)
  948. {
  949. struct gendisk *g = dc->disk.disk;
  950. g->queue->make_request_fn = cached_dev_make_request;
  951. g->queue->backing_dev_info.congested_fn = cached_dev_congested;
  952. dc->disk.cache_miss = cached_dev_cache_miss;
  953. dc->disk.ioctl = cached_dev_ioctl;
  954. }
  955. /* Flash backed devices */
  956. static int flash_dev_cache_miss(struct btree *b, struct search *s,
  957. struct bio *bio, unsigned sectors)
  958. {
  959. struct bio_vec *bv;
  960. int i;
  961. /* Zero fill bio */
  962. bio_for_each_segment(bv, bio, i) {
  963. unsigned j = min(bv->bv_len >> 9, sectors);
  964. void *p = kmap(bv->bv_page);
  965. memset(p + bv->bv_offset, 0, j << 9);
  966. kunmap(bv->bv_page);
  967. sectors -= j;
  968. }
  969. bio_advance(bio, min(sectors << 9, bio->bi_size));
  970. if (!bio->bi_size)
  971. return MAP_DONE;
  972. return MAP_CONTINUE;
  973. }
  974. static void flash_dev_nodata(struct closure *cl)
  975. {
  976. struct search *s = container_of(cl, struct search, cl);
  977. if (s->iop.flush_journal)
  978. bch_journal_meta(s->iop.c, cl);
  979. continue_at(cl, search_free, NULL);
  980. }
  981. static void flash_dev_make_request(struct request_queue *q, struct bio *bio)
  982. {
  983. struct search *s;
  984. struct closure *cl;
  985. struct bcache_device *d = bio->bi_bdev->bd_disk->private_data;
  986. int cpu, rw = bio_data_dir(bio);
  987. cpu = part_stat_lock();
  988. part_stat_inc(cpu, &d->disk->part0, ios[rw]);
  989. part_stat_add(cpu, &d->disk->part0, sectors[rw], bio_sectors(bio));
  990. part_stat_unlock();
  991. s = search_alloc(bio, d);
  992. cl = &s->cl;
  993. bio = &s->bio.bio;
  994. trace_bcache_request_start(s->d, bio);
  995. if (!bio->bi_size) {
  996. /*
  997. * can't call bch_journal_meta from under
  998. * generic_make_request
  999. */
  1000. continue_at_nobarrier(&s->cl,
  1001. flash_dev_nodata,
  1002. bcache_wq);
  1003. } else if (rw) {
  1004. bch_keybuf_check_overlapping(&s->iop.c->moving_gc_keys,
  1005. &KEY(d->id, bio->bi_sector, 0),
  1006. &KEY(d->id, bio_end_sector(bio), 0));
  1007. s->iop.bypass = (bio->bi_rw & REQ_DISCARD) != 0;
  1008. s->iop.writeback = true;
  1009. s->iop.bio = bio;
  1010. closure_call(&s->iop.cl, bch_data_insert, NULL, cl);
  1011. } else {
  1012. closure_call(&s->iop.cl, cache_lookup, NULL, cl);
  1013. }
  1014. continue_at(cl, search_free, NULL);
  1015. }
  1016. static int flash_dev_ioctl(struct bcache_device *d, fmode_t mode,
  1017. unsigned int cmd, unsigned long arg)
  1018. {
  1019. return -ENOTTY;
  1020. }
  1021. static int flash_dev_congested(void *data, int bits)
  1022. {
  1023. struct bcache_device *d = data;
  1024. struct request_queue *q;
  1025. struct cache *ca;
  1026. unsigned i;
  1027. int ret = 0;
  1028. for_each_cache(ca, d->c, i) {
  1029. q = bdev_get_queue(ca->bdev);
  1030. ret |= bdi_congested(&q->backing_dev_info, bits);
  1031. }
  1032. return ret;
  1033. }
  1034. void bch_flash_dev_request_init(struct bcache_device *d)
  1035. {
  1036. struct gendisk *g = d->disk;
  1037. g->queue->make_request_fn = flash_dev_make_request;
  1038. g->queue->backing_dev_info.congested_fn = flash_dev_congested;
  1039. d->cache_miss = flash_dev_cache_miss;
  1040. d->ioctl = flash_dev_ioctl;
  1041. }
  1042. void bch_request_exit(void)
  1043. {
  1044. #ifdef CONFIG_CGROUP_BCACHE
  1045. cgroup_unload_subsys(&bcache_subsys);
  1046. #endif
  1047. if (bch_search_cache)
  1048. kmem_cache_destroy(bch_search_cache);
  1049. }
  1050. int __init bch_request_init(void)
  1051. {
  1052. bch_search_cache = KMEM_CACHE(search, 0);
  1053. if (!bch_search_cache)
  1054. return -ENOMEM;
  1055. #ifdef CONFIG_CGROUP_BCACHE
  1056. cgroup_load_subsys(&bcache_subsys);
  1057. init_bch_cgroup(&bcache_default_cgroup);
  1058. cgroup_add_cftypes(&bcache_subsys, bch_files);
  1059. #endif
  1060. return 0;
  1061. }