request.c 33 KB

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