request.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  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. *
  240. * This is the starting point for any data to end up in a cache device; it could
  241. * be from a normal write, or a writeback write, or a write to a flash only
  242. * volume - it's also used by the moving garbage collector to compact data in
  243. * mostly empty buckets.
  244. *
  245. * It first writes the data to the cache, creating a list of keys to be inserted
  246. * (if the data had to be fragmented there will be multiple keys); after the
  247. * data is written it calls bch_journal, and after the keys have been added to
  248. * the next journal write they're inserted into the btree.
  249. *
  250. * It inserts the data in s->cache_bio; bi_sector is used for the key offset,
  251. * and op->inode is used for the key inode.
  252. *
  253. * If s->bypass is true, instead of inserting the data it invalidates the
  254. * region of the cache represented by s->cache_bio and op->inode.
  255. */
  256. void bch_data_insert(struct closure *cl)
  257. {
  258. struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
  259. trace_bcache_write(op->c, op->inode, op->bio,
  260. op->writeback, op->bypass);
  261. bch_keylist_init(&op->insert_keys);
  262. bio_get(op->bio);
  263. bch_data_insert_start(cl);
  264. }
  265. /* Congested? */
  266. unsigned bch_get_congested(struct cache_set *c)
  267. {
  268. int i;
  269. long rand;
  270. if (!c->congested_read_threshold_us &&
  271. !c->congested_write_threshold_us)
  272. return 0;
  273. i = (local_clock_us() - c->congested_last_us) / 1024;
  274. if (i < 0)
  275. return 0;
  276. i += atomic_read(&c->congested);
  277. if (i >= 0)
  278. return 0;
  279. i += CONGESTED_MAX;
  280. if (i > 0)
  281. i = fract_exp_two(i, 6);
  282. rand = get_random_int();
  283. i -= bitmap_weight(&rand, BITS_PER_LONG);
  284. return i > 0 ? i : 1;
  285. }
  286. static void add_sequential(struct task_struct *t)
  287. {
  288. ewma_add(t->sequential_io_avg,
  289. t->sequential_io, 8, 0);
  290. t->sequential_io = 0;
  291. }
  292. static struct hlist_head *iohash(struct cached_dev *dc, uint64_t k)
  293. {
  294. return &dc->io_hash[hash_64(k, RECENT_IO_BITS)];
  295. }
  296. static bool check_should_bypass(struct cached_dev *dc, struct bio *bio)
  297. {
  298. struct cache_set *c = dc->disk.c;
  299. unsigned mode = cache_mode(dc);
  300. unsigned sectors, congested = bch_get_congested(c);
  301. struct task_struct *task = current;
  302. struct io *i;
  303. if (test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags) ||
  304. c->gc_stats.in_use > CUTOFF_CACHE_ADD ||
  305. (bio_op(bio) == REQ_OP_DISCARD))
  306. goto skip;
  307. if (mode == CACHE_MODE_NONE ||
  308. (mode == CACHE_MODE_WRITEAROUND &&
  309. op_is_write(bio_op(bio))))
  310. goto skip;
  311. /*
  312. * Flag for bypass if the IO is for read-ahead or background,
  313. * unless the read-ahead request is for metadata (eg, for gfs2).
  314. */
  315. if (bio->bi_opf & (REQ_RAHEAD|REQ_BACKGROUND) &&
  316. !(bio->bi_opf & REQ_META))
  317. goto skip;
  318. if (bio->bi_iter.bi_sector & (c->sb.block_size - 1) ||
  319. bio_sectors(bio) & (c->sb.block_size - 1)) {
  320. pr_debug("skipping unaligned io");
  321. goto skip;
  322. }
  323. if (bypass_torture_test(dc)) {
  324. if ((get_random_int() & 3) == 3)
  325. goto skip;
  326. else
  327. goto rescale;
  328. }
  329. if (!congested && !dc->sequential_cutoff)
  330. goto rescale;
  331. spin_lock(&dc->io_lock);
  332. hlist_for_each_entry(i, iohash(dc, bio->bi_iter.bi_sector), hash)
  333. if (i->last == bio->bi_iter.bi_sector &&
  334. time_before(jiffies, i->jiffies))
  335. goto found;
  336. i = list_first_entry(&dc->io_lru, struct io, lru);
  337. add_sequential(task);
  338. i->sequential = 0;
  339. found:
  340. if (i->sequential + bio->bi_iter.bi_size > i->sequential)
  341. i->sequential += bio->bi_iter.bi_size;
  342. i->last = bio_end_sector(bio);
  343. i->jiffies = jiffies + msecs_to_jiffies(5000);
  344. task->sequential_io = i->sequential;
  345. hlist_del(&i->hash);
  346. hlist_add_head(&i->hash, iohash(dc, i->last));
  347. list_move_tail(&i->lru, &dc->io_lru);
  348. spin_unlock(&dc->io_lock);
  349. sectors = max(task->sequential_io,
  350. task->sequential_io_avg) >> 9;
  351. if (dc->sequential_cutoff &&
  352. sectors >= dc->sequential_cutoff >> 9) {
  353. trace_bcache_bypass_sequential(bio);
  354. goto skip;
  355. }
  356. if (congested && sectors >= congested) {
  357. trace_bcache_bypass_congested(bio);
  358. goto skip;
  359. }
  360. rescale:
  361. bch_rescale_priorities(c, bio_sectors(bio));
  362. return false;
  363. skip:
  364. bch_mark_sectors_bypassed(c, dc, bio_sectors(bio));
  365. return true;
  366. }
  367. /* Cache lookup */
  368. struct search {
  369. /* Stack frame for bio_complete */
  370. struct closure cl;
  371. struct bbio bio;
  372. struct bio *orig_bio;
  373. struct bio *cache_miss;
  374. struct bcache_device *d;
  375. unsigned insert_bio_sectors;
  376. unsigned recoverable:1;
  377. unsigned write:1;
  378. unsigned read_dirty_data:1;
  379. unsigned cache_missed:1;
  380. unsigned long start_time;
  381. struct btree_op op;
  382. struct data_insert_op iop;
  383. };
  384. static void bch_cache_read_endio(struct bio *bio)
  385. {
  386. struct bbio *b = container_of(bio, struct bbio, bio);
  387. struct closure *cl = bio->bi_private;
  388. struct search *s = container_of(cl, struct search, cl);
  389. /*
  390. * If the bucket was reused while our bio was in flight, we might have
  391. * read the wrong data. Set s->error but not error so it doesn't get
  392. * counted against the cache device, but we'll still reread the data
  393. * from the backing device.
  394. */
  395. if (bio->bi_status)
  396. s->iop.status = bio->bi_status;
  397. else if (!KEY_DIRTY(&b->key) &&
  398. ptr_stale(s->iop.c, &b->key, 0)) {
  399. atomic_long_inc(&s->iop.c->cache_read_races);
  400. s->iop.status = BLK_STS_IOERR;
  401. }
  402. bch_bbio_endio(s->iop.c, bio, bio->bi_status, "reading from cache");
  403. }
  404. /*
  405. * Read from a single key, handling the initial cache miss if the key starts in
  406. * the middle of the bio
  407. */
  408. static int cache_lookup_fn(struct btree_op *op, struct btree *b, struct bkey *k)
  409. {
  410. struct search *s = container_of(op, struct search, op);
  411. struct bio *n, *bio = &s->bio.bio;
  412. struct bkey *bio_key;
  413. unsigned ptr;
  414. if (bkey_cmp(k, &KEY(s->iop.inode, bio->bi_iter.bi_sector, 0)) <= 0)
  415. return MAP_CONTINUE;
  416. if (KEY_INODE(k) != s->iop.inode ||
  417. KEY_START(k) > bio->bi_iter.bi_sector) {
  418. unsigned bio_sectors = bio_sectors(bio);
  419. unsigned sectors = KEY_INODE(k) == s->iop.inode
  420. ? min_t(uint64_t, INT_MAX,
  421. KEY_START(k) - bio->bi_iter.bi_sector)
  422. : INT_MAX;
  423. int ret = s->d->cache_miss(b, s, bio, sectors);
  424. if (ret != MAP_CONTINUE)
  425. return ret;
  426. /* if this was a complete miss we shouldn't get here */
  427. BUG_ON(bio_sectors <= sectors);
  428. }
  429. if (!KEY_SIZE(k))
  430. return MAP_CONTINUE;
  431. /* XXX: figure out best pointer - for multiple cache devices */
  432. ptr = 0;
  433. PTR_BUCKET(b->c, k, ptr)->prio = INITIAL_PRIO;
  434. if (KEY_DIRTY(k))
  435. s->read_dirty_data = true;
  436. n = bio_next_split(bio, min_t(uint64_t, INT_MAX,
  437. KEY_OFFSET(k) - bio->bi_iter.bi_sector),
  438. GFP_NOIO, s->d->bio_split);
  439. bio_key = &container_of(n, struct bbio, bio)->key;
  440. bch_bkey_copy_single_ptr(bio_key, k, ptr);
  441. bch_cut_front(&KEY(s->iop.inode, n->bi_iter.bi_sector, 0), bio_key);
  442. bch_cut_back(&KEY(s->iop.inode, bio_end_sector(n), 0), bio_key);
  443. n->bi_end_io = bch_cache_read_endio;
  444. n->bi_private = &s->cl;
  445. /*
  446. * The bucket we're reading from might be reused while our bio
  447. * is in flight, and we could then end up reading the wrong
  448. * data.
  449. *
  450. * We guard against this by checking (in cache_read_endio()) if
  451. * the pointer is stale again; if so, we treat it as an error
  452. * and reread from the backing device (but we don't pass that
  453. * error up anywhere).
  454. */
  455. __bch_submit_bbio(n, b->c);
  456. return n == bio ? MAP_DONE : MAP_CONTINUE;
  457. }
  458. static void cache_lookup(struct closure *cl)
  459. {
  460. struct search *s = container_of(cl, struct search, iop.cl);
  461. struct bio *bio = &s->bio.bio;
  462. struct cached_dev *dc;
  463. int ret;
  464. bch_btree_op_init(&s->op, -1);
  465. ret = bch_btree_map_keys(&s->op, s->iop.c,
  466. &KEY(s->iop.inode, bio->bi_iter.bi_sector, 0),
  467. cache_lookup_fn, MAP_END_KEY);
  468. if (ret == -EAGAIN) {
  469. continue_at(cl, cache_lookup, bcache_wq);
  470. return;
  471. }
  472. /*
  473. * We might meet err when searching the btree, If that happens, we will
  474. * get negative ret, in this scenario we should not recover data from
  475. * backing device (when cache device is dirty) because we don't know
  476. * whether bkeys the read request covered are all clean.
  477. *
  478. * And after that happened, s->iop.status is still its initial value
  479. * before we submit s->bio.bio
  480. */
  481. if (ret < 0) {
  482. BUG_ON(ret == -EINTR);
  483. if (s->d && s->d->c &&
  484. !UUID_FLASH_ONLY(&s->d->c->uuids[s->d->id])) {
  485. dc = container_of(s->d, struct cached_dev, disk);
  486. if (dc && atomic_read(&dc->has_dirty))
  487. s->recoverable = false;
  488. }
  489. if (!s->iop.status)
  490. s->iop.status = BLK_STS_IOERR;
  491. }
  492. closure_return(cl);
  493. }
  494. /* Common code for the make_request functions */
  495. static void request_endio(struct bio *bio)
  496. {
  497. struct closure *cl = bio->bi_private;
  498. if (bio->bi_status) {
  499. struct search *s = container_of(cl, struct search, cl);
  500. s->iop.status = bio->bi_status;
  501. /* Only cache read errors are recoverable */
  502. s->recoverable = false;
  503. }
  504. bio_put(bio);
  505. closure_put(cl);
  506. }
  507. static void backing_request_endio(struct bio *bio)
  508. {
  509. struct closure *cl = bio->bi_private;
  510. if (bio->bi_status) {
  511. struct search *s = container_of(cl, struct search, cl);
  512. struct cached_dev *dc = container_of(s->d,
  513. struct cached_dev, disk);
  514. /*
  515. * If a bio has REQ_PREFLUSH for writeback mode, it is
  516. * speically assembled in cached_dev_write() for a non-zero
  517. * write request which has REQ_PREFLUSH. we don't set
  518. * s->iop.status by this failure, the status will be decided
  519. * by result of bch_data_insert() operation.
  520. */
  521. if (unlikely(s->iop.writeback &&
  522. bio->bi_opf & REQ_PREFLUSH)) {
  523. char buf[BDEVNAME_SIZE];
  524. bio_devname(bio, buf);
  525. pr_err("Can't flush %s: returned bi_status %i",
  526. buf, bio->bi_status);
  527. } else {
  528. /* set to orig_bio->bi_status in bio_complete() */
  529. s->iop.status = bio->bi_status;
  530. }
  531. s->recoverable = false;
  532. /* should count I/O error for backing device here */
  533. bch_count_backing_io_errors(dc, bio);
  534. }
  535. bio_put(bio);
  536. closure_put(cl);
  537. }
  538. static void bio_complete(struct search *s)
  539. {
  540. if (s->orig_bio) {
  541. generic_end_io_acct(s->d->disk->queue,
  542. bio_data_dir(s->orig_bio),
  543. &s->d->disk->part0, s->start_time);
  544. trace_bcache_request_end(s->d, s->orig_bio);
  545. s->orig_bio->bi_status = s->iop.status;
  546. bio_endio(s->orig_bio);
  547. s->orig_bio = NULL;
  548. }
  549. }
  550. static void do_bio_hook(struct search *s,
  551. struct bio *orig_bio,
  552. bio_end_io_t *end_io_fn)
  553. {
  554. struct bio *bio = &s->bio.bio;
  555. bio_init(bio, NULL, 0);
  556. __bio_clone_fast(bio, orig_bio);
  557. /*
  558. * bi_end_io can be set separately somewhere else, e.g. the
  559. * variants in,
  560. * - cache_bio->bi_end_io from cached_dev_cache_miss()
  561. * - n->bi_end_io from cache_lookup_fn()
  562. */
  563. bio->bi_end_io = end_io_fn;
  564. bio->bi_private = &s->cl;
  565. bio_cnt_set(bio, 3);
  566. }
  567. static void search_free(struct closure *cl)
  568. {
  569. struct search *s = container_of(cl, struct search, cl);
  570. if (s->iop.bio)
  571. bio_put(s->iop.bio);
  572. bio_complete(s);
  573. closure_debug_destroy(cl);
  574. mempool_free(s, s->d->c->search);
  575. }
  576. static inline struct search *search_alloc(struct bio *bio,
  577. struct bcache_device *d)
  578. {
  579. struct search *s;
  580. s = mempool_alloc(d->c->search, GFP_NOIO);
  581. closure_init(&s->cl, NULL);
  582. do_bio_hook(s, bio, request_endio);
  583. s->orig_bio = bio;
  584. s->cache_miss = NULL;
  585. s->cache_missed = 0;
  586. s->d = d;
  587. s->recoverable = 1;
  588. s->write = op_is_write(bio_op(bio));
  589. s->read_dirty_data = 0;
  590. s->start_time = jiffies;
  591. s->iop.c = d->c;
  592. s->iop.bio = NULL;
  593. s->iop.inode = d->id;
  594. s->iop.write_point = hash_long((unsigned long) current, 16);
  595. s->iop.write_prio = 0;
  596. s->iop.status = 0;
  597. s->iop.flags = 0;
  598. s->iop.flush_journal = op_is_flush(bio->bi_opf);
  599. s->iop.wq = bcache_wq;
  600. return s;
  601. }
  602. /* Cached devices */
  603. static void cached_dev_bio_complete(struct closure *cl)
  604. {
  605. struct search *s = container_of(cl, struct search, cl);
  606. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  607. search_free(cl);
  608. cached_dev_put(dc);
  609. }
  610. /* Process reads */
  611. static void cached_dev_cache_miss_done(struct closure *cl)
  612. {
  613. struct search *s = container_of(cl, struct search, cl);
  614. if (s->iop.replace_collision)
  615. bch_mark_cache_miss_collision(s->iop.c, s->d);
  616. if (s->iop.bio)
  617. bio_free_pages(s->iop.bio);
  618. cached_dev_bio_complete(cl);
  619. }
  620. static void cached_dev_read_error(struct closure *cl)
  621. {
  622. struct search *s = container_of(cl, struct search, cl);
  623. struct bio *bio = &s->bio.bio;
  624. /*
  625. * If read request hit dirty data (s->read_dirty_data is true),
  626. * then recovery a failed read request from cached device may
  627. * get a stale data back. So read failure recovery is only
  628. * permitted when read request hit clean data in cache device,
  629. * or when cache read race happened.
  630. */
  631. if (s->recoverable && !s->read_dirty_data) {
  632. /* Retry from the backing device: */
  633. trace_bcache_read_retry(s->orig_bio);
  634. s->iop.status = 0;
  635. do_bio_hook(s, s->orig_bio, backing_request_endio);
  636. /* XXX: invalidate cache */
  637. /* I/O request sent to backing device */
  638. closure_bio_submit(s->iop.c, bio, cl);
  639. }
  640. continue_at(cl, cached_dev_cache_miss_done, NULL);
  641. }
  642. static void cached_dev_read_done(struct closure *cl)
  643. {
  644. struct search *s = container_of(cl, struct search, cl);
  645. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  646. /*
  647. * We had a cache miss; cache_bio now contains data ready to be inserted
  648. * into the cache.
  649. *
  650. * First, we copy the data we just read from cache_bio's bounce buffers
  651. * to the buffers the original bio pointed to:
  652. */
  653. if (s->iop.bio) {
  654. bio_reset(s->iop.bio);
  655. s->iop.bio->bi_iter.bi_sector = s->cache_miss->bi_iter.bi_sector;
  656. bio_copy_dev(s->iop.bio, s->cache_miss);
  657. s->iop.bio->bi_iter.bi_size = s->insert_bio_sectors << 9;
  658. bch_bio_map(s->iop.bio, NULL);
  659. bio_copy_data(s->cache_miss, s->iop.bio);
  660. bio_put(s->cache_miss);
  661. s->cache_miss = NULL;
  662. }
  663. if (verify(dc) && s->recoverable && !s->read_dirty_data)
  664. bch_data_verify(dc, s->orig_bio);
  665. bio_complete(s);
  666. if (s->iop.bio &&
  667. !test_bit(CACHE_SET_STOPPING, &s->iop.c->flags)) {
  668. BUG_ON(!s->iop.replace);
  669. closure_call(&s->iop.cl, bch_data_insert, NULL, cl);
  670. }
  671. continue_at(cl, cached_dev_cache_miss_done, NULL);
  672. }
  673. static void cached_dev_read_done_bh(struct closure *cl)
  674. {
  675. struct search *s = container_of(cl, struct search, cl);
  676. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  677. bch_mark_cache_accounting(s->iop.c, s->d,
  678. !s->cache_missed, s->iop.bypass);
  679. trace_bcache_read(s->orig_bio, !s->cache_miss, s->iop.bypass);
  680. if (s->iop.status)
  681. continue_at_nobarrier(cl, cached_dev_read_error, bcache_wq);
  682. else if (s->iop.bio || verify(dc))
  683. continue_at_nobarrier(cl, cached_dev_read_done, bcache_wq);
  684. else
  685. continue_at_nobarrier(cl, cached_dev_bio_complete, NULL);
  686. }
  687. static int cached_dev_cache_miss(struct btree *b, struct search *s,
  688. struct bio *bio, unsigned sectors)
  689. {
  690. int ret = MAP_CONTINUE;
  691. unsigned reada = 0;
  692. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  693. struct bio *miss, *cache_bio;
  694. s->cache_missed = 1;
  695. if (s->cache_miss || s->iop.bypass) {
  696. miss = bio_next_split(bio, sectors, GFP_NOIO, s->d->bio_split);
  697. ret = miss == bio ? MAP_DONE : MAP_CONTINUE;
  698. goto out_submit;
  699. }
  700. if (!(bio->bi_opf & REQ_RAHEAD) &&
  701. !(bio->bi_opf & REQ_META) &&
  702. s->iop.c->gc_stats.in_use < CUTOFF_CACHE_READA)
  703. reada = min_t(sector_t, dc->readahead >> 9,
  704. get_capacity(bio->bi_disk) - bio_end_sector(bio));
  705. s->insert_bio_sectors = min(sectors, bio_sectors(bio) + reada);
  706. s->iop.replace_key = KEY(s->iop.inode,
  707. bio->bi_iter.bi_sector + s->insert_bio_sectors,
  708. s->insert_bio_sectors);
  709. ret = bch_btree_insert_check_key(b, &s->op, &s->iop.replace_key);
  710. if (ret)
  711. return ret;
  712. s->iop.replace = true;
  713. miss = bio_next_split(bio, sectors, GFP_NOIO, s->d->bio_split);
  714. /* btree_search_recurse()'s btree iterator is no good anymore */
  715. ret = miss == bio ? MAP_DONE : -EINTR;
  716. cache_bio = bio_alloc_bioset(GFP_NOWAIT,
  717. DIV_ROUND_UP(s->insert_bio_sectors, PAGE_SECTORS),
  718. dc->disk.bio_split);
  719. if (!cache_bio)
  720. goto out_submit;
  721. cache_bio->bi_iter.bi_sector = miss->bi_iter.bi_sector;
  722. bio_copy_dev(cache_bio, miss);
  723. cache_bio->bi_iter.bi_size = s->insert_bio_sectors << 9;
  724. cache_bio->bi_end_io = backing_request_endio;
  725. cache_bio->bi_private = &s->cl;
  726. bch_bio_map(cache_bio, NULL);
  727. if (bch_bio_alloc_pages(cache_bio, __GFP_NOWARN|GFP_NOIO))
  728. goto out_put;
  729. if (reada)
  730. bch_mark_cache_readahead(s->iop.c, s->d);
  731. s->cache_miss = miss;
  732. s->iop.bio = cache_bio;
  733. bio_get(cache_bio);
  734. /* I/O request sent to backing device */
  735. closure_bio_submit(s->iop.c, cache_bio, &s->cl);
  736. return ret;
  737. out_put:
  738. bio_put(cache_bio);
  739. out_submit:
  740. miss->bi_end_io = backing_request_endio;
  741. miss->bi_private = &s->cl;
  742. /* I/O request sent to backing device */
  743. closure_bio_submit(s->iop.c, miss, &s->cl);
  744. return ret;
  745. }
  746. static void cached_dev_read(struct cached_dev *dc, struct search *s)
  747. {
  748. struct closure *cl = &s->cl;
  749. closure_call(&s->iop.cl, cache_lookup, NULL, cl);
  750. continue_at(cl, cached_dev_read_done_bh, NULL);
  751. }
  752. /* Process writes */
  753. static void cached_dev_write_complete(struct closure *cl)
  754. {
  755. struct search *s = container_of(cl, struct search, cl);
  756. struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
  757. up_read_non_owner(&dc->writeback_lock);
  758. cached_dev_bio_complete(cl);
  759. }
  760. static void cached_dev_write(struct cached_dev *dc, struct search *s)
  761. {
  762. struct closure *cl = &s->cl;
  763. struct bio *bio = &s->bio.bio;
  764. struct bkey start = KEY(dc->disk.id, bio->bi_iter.bi_sector, 0);
  765. struct bkey end = KEY(dc->disk.id, bio_end_sector(bio), 0);
  766. bch_keybuf_check_overlapping(&s->iop.c->moving_gc_keys, &start, &end);
  767. down_read_non_owner(&dc->writeback_lock);
  768. if (bch_keybuf_check_overlapping(&dc->writeback_keys, &start, &end)) {
  769. /*
  770. * We overlap with some dirty data undergoing background
  771. * writeback, force this write to writeback
  772. */
  773. s->iop.bypass = false;
  774. s->iop.writeback = true;
  775. }
  776. /*
  777. * Discards aren't _required_ to do anything, so skipping if
  778. * check_overlapping returned true is ok
  779. *
  780. * But check_overlapping drops dirty keys for which io hasn't started,
  781. * so we still want to call it.
  782. */
  783. if (bio_op(bio) == REQ_OP_DISCARD)
  784. s->iop.bypass = true;
  785. if (should_writeback(dc, s->orig_bio,
  786. cache_mode(dc),
  787. s->iop.bypass)) {
  788. s->iop.bypass = false;
  789. s->iop.writeback = true;
  790. }
  791. if (s->iop.bypass) {
  792. s->iop.bio = s->orig_bio;
  793. bio_get(s->iop.bio);
  794. if (bio_op(bio) == REQ_OP_DISCARD &&
  795. !blk_queue_discard(bdev_get_queue(dc->bdev)))
  796. goto insert_data;
  797. /* I/O request sent to backing device */
  798. bio->bi_end_io = backing_request_endio;
  799. closure_bio_submit(s->iop.c, bio, cl);
  800. } else if (s->iop.writeback) {
  801. bch_writeback_add(dc);
  802. s->iop.bio = bio;
  803. if (bio->bi_opf & REQ_PREFLUSH) {
  804. /*
  805. * Also need to send a flush to the backing
  806. * device.
  807. */
  808. struct bio *flush;
  809. flush = bio_alloc_bioset(GFP_NOIO, 0,
  810. dc->disk.bio_split);
  811. if (!flush) {
  812. s->iop.status = BLK_STS_RESOURCE;
  813. goto insert_data;
  814. }
  815. bio_copy_dev(flush, bio);
  816. flush->bi_end_io = backing_request_endio;
  817. flush->bi_private = cl;
  818. flush->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
  819. /* I/O request sent to backing device */
  820. closure_bio_submit(s->iop.c, flush, cl);
  821. }
  822. } else {
  823. s->iop.bio = bio_clone_fast(bio, GFP_NOIO, dc->disk.bio_split);
  824. /* I/O request sent to backing device */
  825. bio->bi_end_io = backing_request_endio;
  826. closure_bio_submit(s->iop.c, bio, cl);
  827. }
  828. insert_data:
  829. closure_call(&s->iop.cl, bch_data_insert, NULL, cl);
  830. continue_at(cl, cached_dev_write_complete, NULL);
  831. }
  832. static void cached_dev_nodata(struct closure *cl)
  833. {
  834. struct search *s = container_of(cl, struct search, cl);
  835. struct bio *bio = &s->bio.bio;
  836. if (s->iop.flush_journal)
  837. bch_journal_meta(s->iop.c, cl);
  838. /* If it's a flush, we send the flush to the backing device too */
  839. bio->bi_end_io = backing_request_endio;
  840. closure_bio_submit(s->iop.c, bio, cl);
  841. continue_at(cl, cached_dev_bio_complete, NULL);
  842. }
  843. struct detached_dev_io_private {
  844. struct bcache_device *d;
  845. unsigned long start_time;
  846. bio_end_io_t *bi_end_io;
  847. void *bi_private;
  848. };
  849. static void detached_dev_end_io(struct bio *bio)
  850. {
  851. struct detached_dev_io_private *ddip;
  852. ddip = bio->bi_private;
  853. bio->bi_end_io = ddip->bi_end_io;
  854. bio->bi_private = ddip->bi_private;
  855. generic_end_io_acct(ddip->d->disk->queue,
  856. bio_data_dir(bio),
  857. &ddip->d->disk->part0, ddip->start_time);
  858. if (bio->bi_status) {
  859. struct cached_dev *dc = container_of(ddip->d,
  860. struct cached_dev, disk);
  861. /* should count I/O error for backing device here */
  862. bch_count_backing_io_errors(dc, bio);
  863. }
  864. kfree(ddip);
  865. bio->bi_end_io(bio);
  866. }
  867. static void detached_dev_do_request(struct bcache_device *d, struct bio *bio)
  868. {
  869. struct detached_dev_io_private *ddip;
  870. struct cached_dev *dc = container_of(d, struct cached_dev, disk);
  871. /*
  872. * no need to call closure_get(&dc->disk.cl),
  873. * because upper layer had already opened bcache device,
  874. * which would call closure_get(&dc->disk.cl)
  875. */
  876. ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO);
  877. ddip->d = d;
  878. ddip->start_time = jiffies;
  879. ddip->bi_end_io = bio->bi_end_io;
  880. ddip->bi_private = bio->bi_private;
  881. bio->bi_end_io = detached_dev_end_io;
  882. bio->bi_private = ddip;
  883. if ((bio_op(bio) == REQ_OP_DISCARD) &&
  884. !blk_queue_discard(bdev_get_queue(dc->bdev)))
  885. bio->bi_end_io(bio);
  886. else
  887. generic_make_request(bio);
  888. }
  889. /* Cached devices - read & write stuff */
  890. static blk_qc_t cached_dev_make_request(struct request_queue *q,
  891. struct bio *bio)
  892. {
  893. struct search *s;
  894. struct bcache_device *d = bio->bi_disk->private_data;
  895. struct cached_dev *dc = container_of(d, struct cached_dev, disk);
  896. int rw = bio_data_dir(bio);
  897. if (unlikely((d->c && test_bit(CACHE_SET_IO_DISABLE, &d->c->flags)) ||
  898. dc->io_disable)) {
  899. bio->bi_status = BLK_STS_IOERR;
  900. bio_endio(bio);
  901. return BLK_QC_T_NONE;
  902. }
  903. atomic_set(&dc->backing_idle, 0);
  904. generic_start_io_acct(q, rw, bio_sectors(bio), &d->disk->part0);
  905. bio_set_dev(bio, dc->bdev);
  906. bio->bi_iter.bi_sector += dc->sb.data_offset;
  907. if (cached_dev_get(dc)) {
  908. s = search_alloc(bio, d);
  909. trace_bcache_request_start(s->d, bio);
  910. if (!bio->bi_iter.bi_size) {
  911. /*
  912. * can't call bch_journal_meta from under
  913. * generic_make_request
  914. */
  915. continue_at_nobarrier(&s->cl,
  916. cached_dev_nodata,
  917. bcache_wq);
  918. } else {
  919. s->iop.bypass = check_should_bypass(dc, bio);
  920. if (rw)
  921. cached_dev_write(dc, s);
  922. else
  923. cached_dev_read(dc, s);
  924. }
  925. } else
  926. /* I/O request sent to backing device */
  927. detached_dev_do_request(d, bio);
  928. return BLK_QC_T_NONE;
  929. }
  930. static int cached_dev_ioctl(struct bcache_device *d, fmode_t mode,
  931. unsigned int cmd, unsigned long arg)
  932. {
  933. struct cached_dev *dc = container_of(d, struct cached_dev, disk);
  934. return __blkdev_driver_ioctl(dc->bdev, mode, cmd, arg);
  935. }
  936. static int cached_dev_congested(void *data, int bits)
  937. {
  938. struct bcache_device *d = data;
  939. struct cached_dev *dc = container_of(d, struct cached_dev, disk);
  940. struct request_queue *q = bdev_get_queue(dc->bdev);
  941. int ret = 0;
  942. if (bdi_congested(q->backing_dev_info, bits))
  943. return 1;
  944. if (cached_dev_get(dc)) {
  945. unsigned i;
  946. struct cache *ca;
  947. for_each_cache(ca, d->c, i) {
  948. q = bdev_get_queue(ca->bdev);
  949. ret |= bdi_congested(q->backing_dev_info, bits);
  950. }
  951. cached_dev_put(dc);
  952. }
  953. return ret;
  954. }
  955. void bch_cached_dev_request_init(struct cached_dev *dc)
  956. {
  957. struct gendisk *g = dc->disk.disk;
  958. g->queue->make_request_fn = cached_dev_make_request;
  959. g->queue->backing_dev_info->congested_fn = cached_dev_congested;
  960. dc->disk.cache_miss = cached_dev_cache_miss;
  961. dc->disk.ioctl = cached_dev_ioctl;
  962. }
  963. /* Flash backed devices */
  964. static int flash_dev_cache_miss(struct btree *b, struct search *s,
  965. struct bio *bio, unsigned sectors)
  966. {
  967. unsigned bytes = min(sectors, bio_sectors(bio)) << 9;
  968. swap(bio->bi_iter.bi_size, bytes);
  969. zero_fill_bio(bio);
  970. swap(bio->bi_iter.bi_size, bytes);
  971. bio_advance(bio, bytes);
  972. if (!bio->bi_iter.bi_size)
  973. return MAP_DONE;
  974. return MAP_CONTINUE;
  975. }
  976. static void flash_dev_nodata(struct closure *cl)
  977. {
  978. struct search *s = container_of(cl, struct search, cl);
  979. if (s->iop.flush_journal)
  980. bch_journal_meta(s->iop.c, cl);
  981. continue_at(cl, search_free, NULL);
  982. }
  983. static blk_qc_t flash_dev_make_request(struct request_queue *q,
  984. struct bio *bio)
  985. {
  986. struct search *s;
  987. struct closure *cl;
  988. struct bcache_device *d = bio->bi_disk->private_data;
  989. int rw = bio_data_dir(bio);
  990. if (unlikely(d->c && test_bit(CACHE_SET_IO_DISABLE, &d->c->flags))) {
  991. bio->bi_status = BLK_STS_IOERR;
  992. bio_endio(bio);
  993. return BLK_QC_T_NONE;
  994. }
  995. generic_start_io_acct(q, rw, bio_sectors(bio), &d->disk->part0);
  996. s = search_alloc(bio, d);
  997. cl = &s->cl;
  998. bio = &s->bio.bio;
  999. trace_bcache_request_start(s->d, bio);
  1000. if (!bio->bi_iter.bi_size) {
  1001. /*
  1002. * can't call bch_journal_meta from under
  1003. * generic_make_request
  1004. */
  1005. continue_at_nobarrier(&s->cl,
  1006. flash_dev_nodata,
  1007. bcache_wq);
  1008. return BLK_QC_T_NONE;
  1009. } else if (rw) {
  1010. bch_keybuf_check_overlapping(&s->iop.c->moving_gc_keys,
  1011. &KEY(d->id, bio->bi_iter.bi_sector, 0),
  1012. &KEY(d->id, bio_end_sector(bio), 0));
  1013. s->iop.bypass = (bio_op(bio) == REQ_OP_DISCARD) != 0;
  1014. s->iop.writeback = true;
  1015. s->iop.bio = bio;
  1016. closure_call(&s->iop.cl, bch_data_insert, NULL, cl);
  1017. } else {
  1018. closure_call(&s->iop.cl, cache_lookup, NULL, cl);
  1019. }
  1020. continue_at(cl, search_free, NULL);
  1021. return BLK_QC_T_NONE;
  1022. }
  1023. static int flash_dev_ioctl(struct bcache_device *d, fmode_t mode,
  1024. unsigned int cmd, unsigned long arg)
  1025. {
  1026. return -ENOTTY;
  1027. }
  1028. static int flash_dev_congested(void *data, int bits)
  1029. {
  1030. struct bcache_device *d = data;
  1031. struct request_queue *q;
  1032. struct cache *ca;
  1033. unsigned i;
  1034. int ret = 0;
  1035. for_each_cache(ca, d->c, i) {
  1036. q = bdev_get_queue(ca->bdev);
  1037. ret |= bdi_congested(q->backing_dev_info, bits);
  1038. }
  1039. return ret;
  1040. }
  1041. void bch_flash_dev_request_init(struct bcache_device *d)
  1042. {
  1043. struct gendisk *g = d->disk;
  1044. g->queue->make_request_fn = flash_dev_make_request;
  1045. g->queue->backing_dev_info->congested_fn = flash_dev_congested;
  1046. d->cache_miss = flash_dev_cache_miss;
  1047. d->ioctl = flash_dev_ioctl;
  1048. }
  1049. void bch_request_exit(void)
  1050. {
  1051. if (bch_search_cache)
  1052. kmem_cache_destroy(bch_search_cache);
  1053. }
  1054. int __init bch_request_init(void)
  1055. {
  1056. bch_search_cache = KMEM_CACHE(search, 0);
  1057. if (!bch_search_cache)
  1058. return -ENOMEM;
  1059. return 0;
  1060. }