request.c 33 KB

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