request.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  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,
  541. bio_data_dir(s->orig_bio),
  542. &s->d->disk->part0, s->start_time);
  543. trace_bcache_request_end(s->d, s->orig_bio);
  544. s->orig_bio->bi_status = s->iop.status;
  545. bio_endio(s->orig_bio);
  546. s->orig_bio = NULL;
  547. }
  548. }
  549. static void do_bio_hook(struct search *s,
  550. struct bio *orig_bio,
  551. bio_end_io_t *end_io_fn)
  552. {
  553. struct bio *bio = &s->bio.bio;
  554. bio_init(bio, NULL, 0);
  555. __bio_clone_fast(bio, orig_bio);
  556. /*
  557. * bi_end_io can be set separately somewhere else, e.g. the
  558. * variants in,
  559. * - cache_bio->bi_end_io from cached_dev_cache_miss()
  560. * - n->bi_end_io from cache_lookup_fn()
  561. */
  562. bio->bi_end_io = end_io_fn;
  563. bio->bi_private = &s->cl;
  564. bio_cnt_set(bio, 3);
  565. }
  566. static void search_free(struct closure *cl)
  567. {
  568. struct search *s = container_of(cl, struct search, cl);
  569. if (s->iop.bio)
  570. bio_put(s->iop.bio);
  571. bio_complete(s);
  572. closure_debug_destroy(cl);
  573. mempool_free(s, s->d->c->search);
  574. }
  575. static inline struct search *search_alloc(struct bio *bio,
  576. struct bcache_device *d)
  577. {
  578. struct search *s;
  579. s = mempool_alloc(d->c->search, GFP_NOIO);
  580. closure_init(&s->cl, NULL);
  581. do_bio_hook(s, bio, request_endio);
  582. s->orig_bio = bio;
  583. s->cache_miss = NULL;
  584. s->cache_missed = 0;
  585. s->d = d;
  586. s->recoverable = 1;
  587. s->write = op_is_write(bio_op(bio));
  588. s->read_dirty_data = 0;
  589. s->start_time = jiffies;
  590. s->iop.c = d->c;
  591. s->iop.bio = NULL;
  592. s->iop.inode = d->id;
  593. s->iop.write_point = hash_long((unsigned long) current, 16);
  594. s->iop.write_prio = 0;
  595. s->iop.status = 0;
  596. s->iop.flags = 0;
  597. s->iop.flush_journal = op_is_flush(bio->bi_opf);
  598. s->iop.wq = bcache_wq;
  599. return s;
  600. }
  601. /* Cached devices */
  602. static void cached_dev_bio_complete(struct closure *cl)
  603. {
  604. struct search *s = container_of(cl, struct search, cl);
  605. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  606. search_free(cl);
  607. cached_dev_put(dc);
  608. }
  609. /* Process reads */
  610. static void cached_dev_cache_miss_done(struct closure *cl)
  611. {
  612. struct search *s = container_of(cl, struct search, cl);
  613. if (s->iop.replace_collision)
  614. bch_mark_cache_miss_collision(s->iop.c, s->d);
  615. if (s->iop.bio)
  616. bio_free_pages(s->iop.bio);
  617. cached_dev_bio_complete(cl);
  618. }
  619. static void cached_dev_read_error(struct closure *cl)
  620. {
  621. struct search *s = container_of(cl, struct search, cl);
  622. struct bio *bio = &s->bio.bio;
  623. /*
  624. * If read request hit dirty data (s->read_dirty_data is true),
  625. * then recovery a failed read request from cached device may
  626. * get a stale data back. So read failure recovery is only
  627. * permitted when read request hit clean data in cache device,
  628. * or when cache read race happened.
  629. */
  630. if (s->recoverable && !s->read_dirty_data) {
  631. /* Retry from the backing device: */
  632. trace_bcache_read_retry(s->orig_bio);
  633. s->iop.status = 0;
  634. do_bio_hook(s, s->orig_bio, backing_request_endio);
  635. /* XXX: invalidate cache */
  636. /* I/O request sent to backing device */
  637. closure_bio_submit(s->iop.c, bio, cl);
  638. }
  639. continue_at(cl, cached_dev_cache_miss_done, NULL);
  640. }
  641. static void cached_dev_read_done(struct closure *cl)
  642. {
  643. struct search *s = container_of(cl, struct search, cl);
  644. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  645. /*
  646. * We had a cache miss; cache_bio now contains data ready to be inserted
  647. * into the cache.
  648. *
  649. * First, we copy the data we just read from cache_bio's bounce buffers
  650. * to the buffers the original bio pointed to:
  651. */
  652. if (s->iop.bio) {
  653. bio_reset(s->iop.bio);
  654. s->iop.bio->bi_iter.bi_sector = s->cache_miss->bi_iter.bi_sector;
  655. bio_copy_dev(s->iop.bio, s->cache_miss);
  656. s->iop.bio->bi_iter.bi_size = s->insert_bio_sectors << 9;
  657. bch_bio_map(s->iop.bio, NULL);
  658. bio_copy_data(s->cache_miss, s->iop.bio);
  659. bio_put(s->cache_miss);
  660. s->cache_miss = NULL;
  661. }
  662. if (verify(dc) && s->recoverable && !s->read_dirty_data)
  663. bch_data_verify(dc, s->orig_bio);
  664. bio_complete(s);
  665. if (s->iop.bio &&
  666. !test_bit(CACHE_SET_STOPPING, &s->iop.c->flags)) {
  667. BUG_ON(!s->iop.replace);
  668. closure_call(&s->iop.cl, bch_data_insert, NULL, cl);
  669. }
  670. continue_at(cl, cached_dev_cache_miss_done, NULL);
  671. }
  672. static void cached_dev_read_done_bh(struct closure *cl)
  673. {
  674. struct search *s = container_of(cl, struct search, cl);
  675. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  676. bch_mark_cache_accounting(s->iop.c, s->d,
  677. !s->cache_missed, s->iop.bypass);
  678. trace_bcache_read(s->orig_bio, !s->cache_miss, s->iop.bypass);
  679. if (s->iop.status)
  680. continue_at_nobarrier(cl, cached_dev_read_error, bcache_wq);
  681. else if (s->iop.bio || verify(dc))
  682. continue_at_nobarrier(cl, cached_dev_read_done, bcache_wq);
  683. else
  684. continue_at_nobarrier(cl, cached_dev_bio_complete, NULL);
  685. }
  686. static int cached_dev_cache_miss(struct btree *b, struct search *s,
  687. struct bio *bio, unsigned sectors)
  688. {
  689. int ret = MAP_CONTINUE;
  690. unsigned reada = 0;
  691. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  692. struct bio *miss, *cache_bio;
  693. s->cache_missed = 1;
  694. if (s->cache_miss || s->iop.bypass) {
  695. miss = bio_next_split(bio, sectors, GFP_NOIO, s->d->bio_split);
  696. ret = miss == bio ? MAP_DONE : MAP_CONTINUE;
  697. goto out_submit;
  698. }
  699. if (!(bio->bi_opf & REQ_RAHEAD) &&
  700. !(bio->bi_opf & REQ_META) &&
  701. s->iop.c->gc_stats.in_use < CUTOFF_CACHE_READA)
  702. reada = min_t(sector_t, dc->readahead >> 9,
  703. get_capacity(bio->bi_disk) - bio_end_sector(bio));
  704. s->insert_bio_sectors = min(sectors, bio_sectors(bio) + reada);
  705. s->iop.replace_key = KEY(s->iop.inode,
  706. bio->bi_iter.bi_sector + s->insert_bio_sectors,
  707. s->insert_bio_sectors);
  708. ret = bch_btree_insert_check_key(b, &s->op, &s->iop.replace_key);
  709. if (ret)
  710. return ret;
  711. s->iop.replace = true;
  712. miss = bio_next_split(bio, sectors, GFP_NOIO, s->d->bio_split);
  713. /* btree_search_recurse()'s btree iterator is no good anymore */
  714. ret = miss == bio ? MAP_DONE : -EINTR;
  715. cache_bio = bio_alloc_bioset(GFP_NOWAIT,
  716. DIV_ROUND_UP(s->insert_bio_sectors, PAGE_SECTORS),
  717. dc->disk.bio_split);
  718. if (!cache_bio)
  719. goto out_submit;
  720. cache_bio->bi_iter.bi_sector = miss->bi_iter.bi_sector;
  721. bio_copy_dev(cache_bio, miss);
  722. cache_bio->bi_iter.bi_size = s->insert_bio_sectors << 9;
  723. cache_bio->bi_end_io = backing_request_endio;
  724. cache_bio->bi_private = &s->cl;
  725. bch_bio_map(cache_bio, NULL);
  726. if (bch_bio_alloc_pages(cache_bio, __GFP_NOWARN|GFP_NOIO))
  727. goto out_put;
  728. if (reada)
  729. bch_mark_cache_readahead(s->iop.c, s->d);
  730. s->cache_miss = miss;
  731. s->iop.bio = cache_bio;
  732. bio_get(cache_bio);
  733. /* I/O request sent to backing device */
  734. closure_bio_submit(s->iop.c, cache_bio, &s->cl);
  735. return ret;
  736. out_put:
  737. bio_put(cache_bio);
  738. out_submit:
  739. miss->bi_end_io = backing_request_endio;
  740. miss->bi_private = &s->cl;
  741. /* I/O request sent to backing device */
  742. closure_bio_submit(s->iop.c, miss, &s->cl);
  743. return ret;
  744. }
  745. static void cached_dev_read(struct cached_dev *dc, struct search *s)
  746. {
  747. struct closure *cl = &s->cl;
  748. closure_call(&s->iop.cl, cache_lookup, NULL, cl);
  749. continue_at(cl, cached_dev_read_done_bh, NULL);
  750. }
  751. /* Process writes */
  752. static void cached_dev_write_complete(struct closure *cl)
  753. {
  754. struct search *s = container_of(cl, struct search, cl);
  755. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  756. up_read_non_owner(&dc->writeback_lock);
  757. cached_dev_bio_complete(cl);
  758. }
  759. static void cached_dev_write(struct cached_dev *dc, struct search *s)
  760. {
  761. struct closure *cl = &s->cl;
  762. struct bio *bio = &s->bio.bio;
  763. struct bkey start = KEY(dc->disk.id, bio->bi_iter.bi_sector, 0);
  764. struct bkey end = KEY(dc->disk.id, bio_end_sector(bio), 0);
  765. bch_keybuf_check_overlapping(&s->iop.c->moving_gc_keys, &start, &end);
  766. down_read_non_owner(&dc->writeback_lock);
  767. if (bch_keybuf_check_overlapping(&dc->writeback_keys, &start, &end)) {
  768. /*
  769. * We overlap with some dirty data undergoing background
  770. * writeback, force this write to writeback
  771. */
  772. s->iop.bypass = false;
  773. s->iop.writeback = true;
  774. }
  775. /*
  776. * Discards aren't _required_ to do anything, so skipping if
  777. * check_overlapping returned true is ok
  778. *
  779. * But check_overlapping drops dirty keys for which io hasn't started,
  780. * so we still want to call it.
  781. */
  782. if (bio_op(bio) == REQ_OP_DISCARD)
  783. s->iop.bypass = true;
  784. if (should_writeback(dc, s->orig_bio,
  785. cache_mode(dc),
  786. s->iop.bypass)) {
  787. s->iop.bypass = false;
  788. s->iop.writeback = true;
  789. }
  790. if (s->iop.bypass) {
  791. s->iop.bio = s->orig_bio;
  792. bio_get(s->iop.bio);
  793. if (bio_op(bio) == REQ_OP_DISCARD &&
  794. !blk_queue_discard(bdev_get_queue(dc->bdev)))
  795. goto insert_data;
  796. /* I/O request sent to backing device */
  797. bio->bi_end_io = backing_request_endio;
  798. closure_bio_submit(s->iop.c, bio, cl);
  799. } else if (s->iop.writeback) {
  800. bch_writeback_add(dc);
  801. s->iop.bio = bio;
  802. if (bio->bi_opf & REQ_PREFLUSH) {
  803. /*
  804. * Also need to send a flush to the backing
  805. * device.
  806. */
  807. struct bio *flush;
  808. flush = bio_alloc_bioset(GFP_NOIO, 0,
  809. dc->disk.bio_split);
  810. if (!flush) {
  811. s->iop.status = BLK_STS_RESOURCE;
  812. goto insert_data;
  813. }
  814. bio_copy_dev(flush, bio);
  815. flush->bi_end_io = backing_request_endio;
  816. flush->bi_private = cl;
  817. flush->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
  818. /* I/O request sent to backing device */
  819. closure_bio_submit(s->iop.c, flush, cl);
  820. }
  821. } else {
  822. s->iop.bio = bio_clone_fast(bio, GFP_NOIO, dc->disk.bio_split);
  823. /* I/O request sent to backing device */
  824. bio->bi_end_io = backing_request_endio;
  825. closure_bio_submit(s->iop.c, bio, cl);
  826. }
  827. insert_data:
  828. closure_call(&s->iop.cl, bch_data_insert, NULL, cl);
  829. continue_at(cl, cached_dev_write_complete, NULL);
  830. }
  831. static void cached_dev_nodata(struct closure *cl)
  832. {
  833. struct search *s = container_of(cl, struct search, cl);
  834. struct bio *bio = &s->bio.bio;
  835. if (s->iop.flush_journal)
  836. bch_journal_meta(s->iop.c, cl);
  837. /* If it's a flush, we send the flush to the backing device too */
  838. bio->bi_end_io = backing_request_endio;
  839. closure_bio_submit(s->iop.c, bio, cl);
  840. continue_at(cl, cached_dev_bio_complete, NULL);
  841. }
  842. struct detached_dev_io_private {
  843. struct bcache_device *d;
  844. unsigned long start_time;
  845. bio_end_io_t *bi_end_io;
  846. void *bi_private;
  847. };
  848. static void detached_dev_end_io(struct bio *bio)
  849. {
  850. struct detached_dev_io_private *ddip;
  851. ddip = bio->bi_private;
  852. bio->bi_end_io = ddip->bi_end_io;
  853. bio->bi_private = ddip->bi_private;
  854. generic_end_io_acct(ddip->d->disk->queue,
  855. bio_data_dir(bio),
  856. &ddip->d->disk->part0, ddip->start_time);
  857. if (bio->bi_status) {
  858. struct cached_dev *dc = container_of(ddip->d,
  859. struct cached_dev, disk);
  860. /* should count I/O error for backing device here */
  861. bch_count_backing_io_errors(dc, bio);
  862. }
  863. kfree(ddip);
  864. bio->bi_end_io(bio);
  865. }
  866. static void detached_dev_do_request(struct bcache_device *d, struct bio *bio)
  867. {
  868. struct detached_dev_io_private *ddip;
  869. struct cached_dev *dc = container_of(d, struct cached_dev, disk);
  870. /*
  871. * no need to call closure_get(&dc->disk.cl),
  872. * because upper layer had already opened bcache device,
  873. * which would call closure_get(&dc->disk.cl)
  874. */
  875. ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO);
  876. ddip->d = d;
  877. ddip->start_time = jiffies;
  878. ddip->bi_end_io = bio->bi_end_io;
  879. ddip->bi_private = bio->bi_private;
  880. bio->bi_end_io = detached_dev_end_io;
  881. bio->bi_private = ddip;
  882. if ((bio_op(bio) == REQ_OP_DISCARD) &&
  883. !blk_queue_discard(bdev_get_queue(dc->bdev)))
  884. bio->bi_end_io(bio);
  885. else
  886. generic_make_request(bio);
  887. }
  888. /* Cached devices - read & write stuff */
  889. static blk_qc_t cached_dev_make_request(struct request_queue *q,
  890. struct bio *bio)
  891. {
  892. struct search *s;
  893. struct bcache_device *d = bio->bi_disk->private_data;
  894. struct cached_dev *dc = container_of(d, struct cached_dev, disk);
  895. int rw = bio_data_dir(bio);
  896. if (unlikely((d->c && test_bit(CACHE_SET_IO_DISABLE, &d->c->flags)) ||
  897. dc->io_disable)) {
  898. bio->bi_status = BLK_STS_IOERR;
  899. bio_endio(bio);
  900. return BLK_QC_T_NONE;
  901. }
  902. atomic_set(&dc->backing_idle, 0);
  903. generic_start_io_acct(q, rw, bio_sectors(bio), &d->disk->part0);
  904. bio_set_dev(bio, dc->bdev);
  905. bio->bi_iter.bi_sector += dc->sb.data_offset;
  906. if (cached_dev_get(dc)) {
  907. s = search_alloc(bio, d);
  908. trace_bcache_request_start(s->d, bio);
  909. if (!bio->bi_iter.bi_size) {
  910. /*
  911. * can't call bch_journal_meta from under
  912. * generic_make_request
  913. */
  914. continue_at_nobarrier(&s->cl,
  915. cached_dev_nodata,
  916. bcache_wq);
  917. } else {
  918. s->iop.bypass = check_should_bypass(dc, bio);
  919. if (rw)
  920. cached_dev_write(dc, s);
  921. else
  922. cached_dev_read(dc, s);
  923. }
  924. } else
  925. /* I/O request sent to backing device */
  926. detached_dev_do_request(d, bio);
  927. return BLK_QC_T_NONE;
  928. }
  929. static int cached_dev_ioctl(struct bcache_device *d, fmode_t mode,
  930. unsigned int cmd, unsigned long arg)
  931. {
  932. struct cached_dev *dc = container_of(d, struct cached_dev, disk);
  933. return __blkdev_driver_ioctl(dc->bdev, mode, cmd, arg);
  934. }
  935. static int cached_dev_congested(void *data, int bits)
  936. {
  937. struct bcache_device *d = data;
  938. struct cached_dev *dc = container_of(d, struct cached_dev, disk);
  939. struct request_queue *q = bdev_get_queue(dc->bdev);
  940. int ret = 0;
  941. if (bdi_congested(q->backing_dev_info, bits))
  942. return 1;
  943. if (cached_dev_get(dc)) {
  944. unsigned i;
  945. struct cache *ca;
  946. for_each_cache(ca, d->c, i) {
  947. q = bdev_get_queue(ca->bdev);
  948. ret |= bdi_congested(q->backing_dev_info, bits);
  949. }
  950. cached_dev_put(dc);
  951. }
  952. return ret;
  953. }
  954. void bch_cached_dev_request_init(struct cached_dev *dc)
  955. {
  956. struct gendisk *g = dc->disk.disk;
  957. g->queue->make_request_fn = cached_dev_make_request;
  958. g->queue->backing_dev_info->congested_fn = cached_dev_congested;
  959. dc->disk.cache_miss = cached_dev_cache_miss;
  960. dc->disk.ioctl = cached_dev_ioctl;
  961. }
  962. /* Flash backed devices */
  963. static int flash_dev_cache_miss(struct btree *b, struct search *s,
  964. struct bio *bio, unsigned sectors)
  965. {
  966. unsigned bytes = min(sectors, bio_sectors(bio)) << 9;
  967. swap(bio->bi_iter.bi_size, bytes);
  968. zero_fill_bio(bio);
  969. swap(bio->bi_iter.bi_size, bytes);
  970. bio_advance(bio, bytes);
  971. if (!bio->bi_iter.bi_size)
  972. return MAP_DONE;
  973. return MAP_CONTINUE;
  974. }
  975. static void flash_dev_nodata(struct closure *cl)
  976. {
  977. struct search *s = container_of(cl, struct search, cl);
  978. if (s->iop.flush_journal)
  979. bch_journal_meta(s->iop.c, cl);
  980. continue_at(cl, search_free, NULL);
  981. }
  982. static blk_qc_t flash_dev_make_request(struct request_queue *q,
  983. struct bio *bio)
  984. {
  985. struct search *s;
  986. struct closure *cl;
  987. struct bcache_device *d = bio->bi_disk->private_data;
  988. int rw = bio_data_dir(bio);
  989. if (unlikely(d->c && test_bit(CACHE_SET_IO_DISABLE, &d->c->flags))) {
  990. bio->bi_status = BLK_STS_IOERR;
  991. bio_endio(bio);
  992. return BLK_QC_T_NONE;
  993. }
  994. generic_start_io_acct(q, rw, bio_sectors(bio), &d->disk->part0);
  995. s = search_alloc(bio, d);
  996. cl = &s->cl;
  997. bio = &s->bio.bio;
  998. trace_bcache_request_start(s->d, bio);
  999. if (!bio->bi_iter.bi_size) {
  1000. /*
  1001. * can't call bch_journal_meta from under
  1002. * generic_make_request
  1003. */
  1004. continue_at_nobarrier(&s->cl,
  1005. flash_dev_nodata,
  1006. bcache_wq);
  1007. return BLK_QC_T_NONE;
  1008. } else if (rw) {
  1009. bch_keybuf_check_overlapping(&s->iop.c->moving_gc_keys,
  1010. &KEY(d->id, bio->bi_iter.bi_sector, 0),
  1011. &KEY(d->id, bio_end_sector(bio), 0));
  1012. s->iop.bypass = (bio_op(bio) == REQ_OP_DISCARD) != 0;
  1013. s->iop.writeback = true;
  1014. s->iop.bio = bio;
  1015. closure_call(&s->iop.cl, bch_data_insert, NULL, cl);
  1016. } else {
  1017. closure_call(&s->iop.cl, cache_lookup, NULL, cl);
  1018. }
  1019. continue_at(cl, search_free, NULL);
  1020. return BLK_QC_T_NONE;
  1021. }
  1022. static int flash_dev_ioctl(struct bcache_device *d, fmode_t mode,
  1023. unsigned int cmd, unsigned long arg)
  1024. {
  1025. return -ENOTTY;
  1026. }
  1027. static int flash_dev_congested(void *data, int bits)
  1028. {
  1029. struct bcache_device *d = data;
  1030. struct request_queue *q;
  1031. struct cache *ca;
  1032. unsigned i;
  1033. int ret = 0;
  1034. for_each_cache(ca, d->c, i) {
  1035. q = bdev_get_queue(ca->bdev);
  1036. ret |= bdi_congested(q->backing_dev_info, bits);
  1037. }
  1038. return ret;
  1039. }
  1040. void bch_flash_dev_request_init(struct bcache_device *d)
  1041. {
  1042. struct gendisk *g = d->disk;
  1043. g->queue->make_request_fn = flash_dev_make_request;
  1044. g->queue->backing_dev_info->congested_fn = flash_dev_congested;
  1045. d->cache_miss = flash_dev_cache_miss;
  1046. d->ioctl = flash_dev_ioctl;
  1047. }
  1048. void bch_request_exit(void)
  1049. {
  1050. if (bch_search_cache)
  1051. kmem_cache_destroy(bch_search_cache);
  1052. }
  1053. int __init bch_request_init(void)
  1054. {
  1055. bch_search_cache = KMEM_CACHE(search, 0);
  1056. if (!bch_search_cache)
  1057. return -ENOMEM;
  1058. return 0;
  1059. }