.. | .. |
---|
62 | 62 | struct bkey *replace_key = op->replace ? &op->replace_key : NULL; |
---|
63 | 63 | int ret; |
---|
64 | 64 | |
---|
65 | | - /* |
---|
66 | | - * If we're looping, might already be waiting on |
---|
67 | | - * another journal write - can't wait on more than one journal write at |
---|
68 | | - * a time |
---|
69 | | - * |
---|
70 | | - * XXX: this looks wrong |
---|
71 | | - */ |
---|
72 | | -#if 0 |
---|
73 | | - while (atomic_read(&s->cl.remaining) & CLOSURE_WAITING) |
---|
74 | | - closure_sync(&s->cl); |
---|
75 | | -#endif |
---|
76 | | - |
---|
77 | 65 | if (!op->replace) |
---|
78 | 66 | journal_ref = bch_journal(op->c, &op->insert_keys, |
---|
79 | 67 | op->flush_journal ? cl : NULL); |
---|
.. | .. |
---|
111 | 99 | * bch_data_insert_keys() will insert the keys created so far |
---|
112 | 100 | * and finish the rest when the keylist is empty. |
---|
113 | 101 | */ |
---|
114 | | - if (newsize * sizeof(uint64_t) > block_bytes(c) - sizeof(struct jset)) |
---|
| 102 | + if (newsize * sizeof(uint64_t) > block_bytes(c->cache) - sizeof(struct jset)) |
---|
115 | 103 | return -ENOMEM; |
---|
116 | 104 | |
---|
117 | 105 | return __bch_keylist_realloc(l, u64s); |
---|
.. | .. |
---|
122 | 110 | struct data_insert_op *op = container_of(cl, struct data_insert_op, cl); |
---|
123 | 111 | struct bio *bio = op->bio; |
---|
124 | 112 | |
---|
125 | | - pr_debug("invalidating %i sectors from %llu", |
---|
| 113 | + pr_debug("invalidating %i sectors from %llu\n", |
---|
126 | 114 | bio_sectors(bio), (uint64_t) bio->bi_iter.bi_sector); |
---|
127 | 115 | |
---|
128 | 116 | while (bio_sectors(bio)) { |
---|
.. | .. |
---|
311 | 299 | * data is written it calls bch_journal, and after the keys have been added to |
---|
312 | 300 | * the next journal write they're inserted into the btree. |
---|
313 | 301 | * |
---|
314 | | - * It inserts the data in s->cache_bio; bi_sector is used for the key offset, |
---|
| 302 | + * It inserts the data in op->bio; bi_sector is used for the key offset, |
---|
315 | 303 | * and op->inode is used for the key inode. |
---|
316 | 304 | * |
---|
317 | | - * If s->bypass is true, instead of inserting the data it invalidates the |
---|
318 | | - * region of the cache represented by s->cache_bio and op->inode. |
---|
| 305 | + * If op->bypass is true, instead of inserting the data it invalidates the |
---|
| 306 | + * region of the cache represented by op->bio and op->inode. |
---|
319 | 307 | */ |
---|
320 | 308 | void bch_data_insert(struct closure *cl) |
---|
321 | 309 | { |
---|
.. | .. |
---|
329 | 317 | bch_data_insert_start(cl); |
---|
330 | 318 | } |
---|
331 | 319 | |
---|
332 | | -/* Congested? */ |
---|
333 | | - |
---|
334 | | -unsigned int bch_get_congested(struct cache_set *c) |
---|
| 320 | +/* |
---|
| 321 | + * Congested? Return 0 (not congested) or the limit (in sectors) |
---|
| 322 | + * beyond which we should bypass the cache due to congestion. |
---|
| 323 | + */ |
---|
| 324 | +unsigned int bch_get_congested(const struct cache_set *c) |
---|
335 | 325 | { |
---|
336 | 326 | int i; |
---|
337 | | - long rand; |
---|
338 | 327 | |
---|
339 | 328 | if (!c->congested_read_threshold_us && |
---|
340 | 329 | !c->congested_write_threshold_us) |
---|
.. | .. |
---|
353 | 342 | if (i > 0) |
---|
354 | 343 | i = fract_exp_two(i, 6); |
---|
355 | 344 | |
---|
356 | | - rand = get_random_int(); |
---|
357 | | - i -= bitmap_weight(&rand, BITS_PER_LONG); |
---|
| 345 | + i -= hweight32(get_random_u32()); |
---|
358 | 346 | |
---|
359 | 347 | return i > 0 ? i : 1; |
---|
360 | 348 | } |
---|
.. | .. |
---|
376 | 364 | { |
---|
377 | 365 | struct cache_set *c = dc->disk.c; |
---|
378 | 366 | unsigned int mode = cache_mode(dc); |
---|
379 | | - unsigned int sectors, congested = bch_get_congested(c); |
---|
| 367 | + unsigned int sectors, congested; |
---|
380 | 368 | struct task_struct *task = current; |
---|
381 | 369 | struct io *i; |
---|
382 | 370 | |
---|
.. | .. |
---|
406 | 394 | goto skip; |
---|
407 | 395 | } |
---|
408 | 396 | |
---|
409 | | - if (bio->bi_iter.bi_sector & (c->sb.block_size - 1) || |
---|
410 | | - bio_sectors(bio) & (c->sb.block_size - 1)) { |
---|
411 | | - pr_debug("skipping unaligned io"); |
---|
| 397 | + if (bio->bi_iter.bi_sector & (c->cache->sb.block_size - 1) || |
---|
| 398 | + bio_sectors(bio) & (c->cache->sb.block_size - 1)) { |
---|
| 399 | + pr_debug("skipping unaligned io\n"); |
---|
412 | 400 | goto skip; |
---|
413 | 401 | } |
---|
414 | 402 | |
---|
.. | .. |
---|
419 | 407 | goto rescale; |
---|
420 | 408 | } |
---|
421 | 409 | |
---|
| 410 | + congested = bch_get_congested(c); |
---|
422 | 411 | if (!congested && !dc->sequential_cutoff) |
---|
423 | 412 | goto rescale; |
---|
424 | 413 | |
---|
.. | .. |
---|
486 | 475 | unsigned int read_dirty_data:1; |
---|
487 | 476 | unsigned int cache_missed:1; |
---|
488 | 477 | |
---|
| 478 | + struct hd_struct *part; |
---|
489 | 479 | unsigned long start_time; |
---|
490 | 480 | |
---|
491 | 481 | struct btree_op op; |
---|
.. | .. |
---|
661 | 651 | */ |
---|
662 | 652 | if (unlikely(s->iop.writeback && |
---|
663 | 653 | bio->bi_opf & REQ_PREFLUSH)) { |
---|
664 | | - pr_err("Can't flush %s: returned bi_status %i", |
---|
| 654 | + pr_err("Can't flush %s: returned bi_status %i\n", |
---|
665 | 655 | dc->backing_dev_name, bio->bi_status); |
---|
666 | 656 | } else { |
---|
667 | 657 | /* set to orig_bio->bi_status in bio_complete() */ |
---|
.. | .. |
---|
679 | 669 | static void bio_complete(struct search *s) |
---|
680 | 670 | { |
---|
681 | 671 | if (s->orig_bio) { |
---|
682 | | - generic_end_io_acct(s->d->disk->queue, bio_op(s->orig_bio), |
---|
683 | | - &s->d->disk->part0, s->start_time); |
---|
| 672 | + /* Count on bcache device */ |
---|
| 673 | + part_end_io_acct(s->part, s->orig_bio, s->start_time); |
---|
684 | 674 | |
---|
685 | 675 | trace_bcache_request_end(s->d, s->orig_bio); |
---|
686 | 676 | s->orig_bio->bi_status = s->iop.status; |
---|
.. | .. |
---|
713 | 703 | { |
---|
714 | 704 | struct search *s = container_of(cl, struct search, cl); |
---|
715 | 705 | |
---|
716 | | - atomic_dec(&s->d->c->search_inflight); |
---|
| 706 | + atomic_dec(&s->iop.c->search_inflight); |
---|
717 | 707 | |
---|
718 | 708 | if (s->iop.bio) |
---|
719 | 709 | bio_put(s->iop.bio); |
---|
720 | 710 | |
---|
721 | 711 | bio_complete(s); |
---|
722 | 712 | closure_debug_destroy(cl); |
---|
723 | | - mempool_free(s, &s->d->c->search); |
---|
| 713 | + mempool_free(s, &s->iop.c->search); |
---|
724 | 714 | } |
---|
725 | 715 | |
---|
726 | 716 | static inline struct search *search_alloc(struct bio *bio, |
---|
.. | .. |
---|
741 | 731 | s->recoverable = 1; |
---|
742 | 732 | s->write = op_is_write(bio_op(bio)); |
---|
743 | 733 | s->read_dirty_data = 0; |
---|
744 | | - s->start_time = jiffies; |
---|
745 | | - |
---|
| 734 | + /* Count on the bcache device */ |
---|
| 735 | + s->start_time = part_start_io_acct(d->disk, &s->part, bio); |
---|
746 | 736 | s->iop.c = d->c; |
---|
747 | 737 | s->iop.bio = NULL; |
---|
748 | 738 | s->iop.inode = d->id; |
---|
.. | .. |
---|
763 | 753 | struct search *s = container_of(cl, struct search, cl); |
---|
764 | 754 | struct cached_dev *dc = container_of(s->d, struct cached_dev, disk); |
---|
765 | 755 | |
---|
766 | | - search_free(cl); |
---|
767 | 756 | cached_dev_put(dc); |
---|
| 757 | + search_free(cl); |
---|
768 | 758 | } |
---|
769 | 759 | |
---|
770 | 760 | /* Process reads */ |
---|
771 | 761 | |
---|
772 | | -static void cached_dev_cache_miss_done(struct closure *cl) |
---|
| 762 | +static void cached_dev_read_error_done(struct closure *cl) |
---|
773 | 763 | { |
---|
774 | 764 | struct search *s = container_of(cl, struct search, cl); |
---|
775 | 765 | |
---|
.. | .. |
---|
807 | 797 | closure_bio_submit(s->iop.c, bio, cl); |
---|
808 | 798 | } |
---|
809 | 799 | |
---|
810 | | - continue_at(cl, cached_dev_cache_miss_done, NULL); |
---|
| 800 | + continue_at(cl, cached_dev_read_error_done, NULL); |
---|
| 801 | +} |
---|
| 802 | + |
---|
| 803 | +static void cached_dev_cache_miss_done(struct closure *cl) |
---|
| 804 | +{ |
---|
| 805 | + struct search *s = container_of(cl, struct search, cl); |
---|
| 806 | + struct bcache_device *d = s->d; |
---|
| 807 | + |
---|
| 808 | + if (s->iop.replace_collision) |
---|
| 809 | + bch_mark_cache_miss_collision(s->iop.c, s->d); |
---|
| 810 | + |
---|
| 811 | + if (s->iop.bio) |
---|
| 812 | + bio_free_pages(s->iop.bio); |
---|
| 813 | + |
---|
| 814 | + cached_dev_bio_complete(cl); |
---|
| 815 | + closure_put(&d->cl); |
---|
811 | 816 | } |
---|
812 | 817 | |
---|
813 | 818 | static void cached_dev_read_done(struct closure *cl) |
---|
.. | .. |
---|
840 | 845 | if (verify(dc) && s->recoverable && !s->read_dirty_data) |
---|
841 | 846 | bch_data_verify(dc, s->orig_bio); |
---|
842 | 847 | |
---|
| 848 | + closure_get(&dc->disk.cl); |
---|
843 | 849 | bio_complete(s); |
---|
844 | 850 | |
---|
845 | 851 | if (s->iop.bio && |
---|
.. | .. |
---|
1067 | 1073 | unsigned long start_time; |
---|
1068 | 1074 | bio_end_io_t *bi_end_io; |
---|
1069 | 1075 | void *bi_private; |
---|
| 1076 | + struct hd_struct *part; |
---|
1070 | 1077 | }; |
---|
1071 | 1078 | |
---|
1072 | 1079 | static void detached_dev_end_io(struct bio *bio) |
---|
.. | .. |
---|
1077 | 1084 | bio->bi_end_io = ddip->bi_end_io; |
---|
1078 | 1085 | bio->bi_private = ddip->bi_private; |
---|
1079 | 1086 | |
---|
1080 | | - generic_end_io_acct(ddip->d->disk->queue, bio_op(bio), |
---|
1081 | | - &ddip->d->disk->part0, ddip->start_time); |
---|
| 1087 | + /* Count on the bcache device */ |
---|
| 1088 | + part_end_io_acct(ddip->part, bio, ddip->start_time); |
---|
1082 | 1089 | |
---|
1083 | 1090 | if (bio->bi_status) { |
---|
1084 | 1091 | struct cached_dev *dc = container_of(ddip->d, |
---|
.. | .. |
---|
1102 | 1109 | * which would call closure_get(&dc->disk.cl) |
---|
1103 | 1110 | */ |
---|
1104 | 1111 | ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO); |
---|
| 1112 | + if (!ddip) { |
---|
| 1113 | + bio->bi_status = BLK_STS_RESOURCE; |
---|
| 1114 | + bio->bi_end_io(bio); |
---|
| 1115 | + return; |
---|
| 1116 | + } |
---|
| 1117 | + |
---|
1105 | 1118 | ddip->d = d; |
---|
1106 | | - ddip->start_time = jiffies; |
---|
| 1119 | + /* Count on the bcache device */ |
---|
| 1120 | + ddip->start_time = part_start_io_acct(d->disk, &ddip->part, bio); |
---|
1107 | 1121 | ddip->bi_end_io = bio->bi_end_io; |
---|
1108 | 1122 | ddip->bi_private = bio->bi_private; |
---|
1109 | 1123 | bio->bi_end_io = detached_dev_end_io; |
---|
.. | .. |
---|
1113 | 1127 | !blk_queue_discard(bdev_get_queue(dc->bdev))) |
---|
1114 | 1128 | bio->bi_end_io(bio); |
---|
1115 | 1129 | else |
---|
1116 | | - generic_make_request(bio); |
---|
| 1130 | + submit_bio_noacct(bio); |
---|
1117 | 1131 | } |
---|
1118 | 1132 | |
---|
1119 | 1133 | static void quit_max_writeback_rate(struct cache_set *c, |
---|
.. | .. |
---|
1156 | 1170 | |
---|
1157 | 1171 | /* Cached devices - read & write stuff */ |
---|
1158 | 1172 | |
---|
1159 | | -static blk_qc_t cached_dev_make_request(struct request_queue *q, |
---|
1160 | | - struct bio *bio) |
---|
| 1173 | +blk_qc_t cached_dev_submit_bio(struct bio *bio) |
---|
1161 | 1174 | { |
---|
1162 | 1175 | struct search *s; |
---|
1163 | 1176 | struct bcache_device *d = bio->bi_disk->private_data; |
---|
.. | .. |
---|
1186 | 1199 | } |
---|
1187 | 1200 | } |
---|
1188 | 1201 | |
---|
1189 | | - generic_start_io_acct(q, |
---|
1190 | | - bio_op(bio), |
---|
1191 | | - bio_sectors(bio), |
---|
1192 | | - &d->disk->part0); |
---|
1193 | | - |
---|
1194 | 1202 | bio_set_dev(bio, dc->bdev); |
---|
1195 | 1203 | bio->bi_iter.bi_sector += dc->sb.data_offset; |
---|
1196 | 1204 | |
---|
.. | .. |
---|
1201 | 1209 | if (!bio->bi_iter.bi_size) { |
---|
1202 | 1210 | /* |
---|
1203 | 1211 | * can't call bch_journal_meta from under |
---|
1204 | | - * generic_make_request |
---|
| 1212 | + * submit_bio_noacct |
---|
1205 | 1213 | */ |
---|
1206 | 1214 | continue_at_nobarrier(&s->cl, |
---|
1207 | 1215 | cached_dev_nodata, |
---|
.. | .. |
---|
1232 | 1240 | return __blkdev_driver_ioctl(dc->bdev, mode, cmd, arg); |
---|
1233 | 1241 | } |
---|
1234 | 1242 | |
---|
1235 | | -static int cached_dev_congested(void *data, int bits) |
---|
1236 | | -{ |
---|
1237 | | - struct bcache_device *d = data; |
---|
1238 | | - struct cached_dev *dc = container_of(d, struct cached_dev, disk); |
---|
1239 | | - struct request_queue *q = bdev_get_queue(dc->bdev); |
---|
1240 | | - int ret = 0; |
---|
1241 | | - |
---|
1242 | | - if (bdi_congested(q->backing_dev_info, bits)) |
---|
1243 | | - return 1; |
---|
1244 | | - |
---|
1245 | | - if (cached_dev_get(dc)) { |
---|
1246 | | - unsigned int i; |
---|
1247 | | - struct cache *ca; |
---|
1248 | | - |
---|
1249 | | - for_each_cache(ca, d->c, i) { |
---|
1250 | | - q = bdev_get_queue(ca->bdev); |
---|
1251 | | - ret |= bdi_congested(q->backing_dev_info, bits); |
---|
1252 | | - } |
---|
1253 | | - |
---|
1254 | | - cached_dev_put(dc); |
---|
1255 | | - } |
---|
1256 | | - |
---|
1257 | | - return ret; |
---|
1258 | | -} |
---|
1259 | | - |
---|
1260 | 1243 | void bch_cached_dev_request_init(struct cached_dev *dc) |
---|
1261 | 1244 | { |
---|
1262 | | - struct gendisk *g = dc->disk.disk; |
---|
1263 | | - |
---|
1264 | | - g->queue->make_request_fn = cached_dev_make_request; |
---|
1265 | | - g->queue->backing_dev_info->congested_fn = cached_dev_congested; |
---|
1266 | 1245 | dc->disk.cache_miss = cached_dev_cache_miss; |
---|
1267 | 1246 | dc->disk.ioctl = cached_dev_ioctl; |
---|
1268 | 1247 | } |
---|
.. | .. |
---|
1296 | 1275 | continue_at(cl, search_free, NULL); |
---|
1297 | 1276 | } |
---|
1298 | 1277 | |
---|
1299 | | -static blk_qc_t flash_dev_make_request(struct request_queue *q, |
---|
1300 | | - struct bio *bio) |
---|
| 1278 | +blk_qc_t flash_dev_submit_bio(struct bio *bio) |
---|
1301 | 1279 | { |
---|
1302 | 1280 | struct search *s; |
---|
1303 | 1281 | struct closure *cl; |
---|
.. | .. |
---|
1309 | 1287 | return BLK_QC_T_NONE; |
---|
1310 | 1288 | } |
---|
1311 | 1289 | |
---|
1312 | | - generic_start_io_acct(q, bio_op(bio), bio_sectors(bio), &d->disk->part0); |
---|
1313 | | - |
---|
1314 | 1290 | s = search_alloc(bio, d); |
---|
1315 | 1291 | cl = &s->cl; |
---|
1316 | 1292 | bio = &s->bio.bio; |
---|
.. | .. |
---|
1319 | 1295 | |
---|
1320 | 1296 | if (!bio->bi_iter.bi_size) { |
---|
1321 | 1297 | /* |
---|
1322 | | - * can't call bch_journal_meta from under |
---|
1323 | | - * generic_make_request |
---|
| 1298 | + * can't call bch_journal_meta from under submit_bio_noacct |
---|
1324 | 1299 | */ |
---|
1325 | 1300 | continue_at_nobarrier(&s->cl, |
---|
1326 | 1301 | flash_dev_nodata, |
---|
.. | .. |
---|
1350 | 1325 | return -ENOTTY; |
---|
1351 | 1326 | } |
---|
1352 | 1327 | |
---|
1353 | | -static int flash_dev_congested(void *data, int bits) |
---|
1354 | | -{ |
---|
1355 | | - struct bcache_device *d = data; |
---|
1356 | | - struct request_queue *q; |
---|
1357 | | - struct cache *ca; |
---|
1358 | | - unsigned int i; |
---|
1359 | | - int ret = 0; |
---|
1360 | | - |
---|
1361 | | - for_each_cache(ca, d->c, i) { |
---|
1362 | | - q = bdev_get_queue(ca->bdev); |
---|
1363 | | - ret |= bdi_congested(q->backing_dev_info, bits); |
---|
1364 | | - } |
---|
1365 | | - |
---|
1366 | | - return ret; |
---|
1367 | | -} |
---|
1368 | | - |
---|
1369 | 1328 | void bch_flash_dev_request_init(struct bcache_device *d) |
---|
1370 | 1329 | { |
---|
1371 | | - struct gendisk *g = d->disk; |
---|
1372 | | - |
---|
1373 | | - g->queue->make_request_fn = flash_dev_make_request; |
---|
1374 | | - g->queue->backing_dev_info->congested_fn = flash_dev_congested; |
---|
1375 | 1330 | d->cache_miss = flash_dev_cache_miss; |
---|
1376 | 1331 | d->ioctl = flash_dev_ioctl; |
---|
1377 | 1332 | } |
---|