Skip to content

Commit 1616a4c

Browse files
Coly Liaxboe
authored andcommitted
bcache: remove bcache device self-defined readahead
For read cache missing, bcache defines a readahead size for the read I/O request to the backing device for the missing data. This readahead size is initialized to 0, and almost no one uses it to avoid unnecessary read amplifying onto backing device and write amplifying onto cache device. Considering upper layer file system code has readahead logic allready and works fine with readahead_cache_policy sysfile interface, we don't have to keep bcache self-defined readahead anymore. This patch removes the bcache self-defined readahead for cache missing request for backing device, and the readahead sysfs file interfaces are removed as well. This is the preparation for next patch to fix potential kernel panic due to oversized request in a simpler method. Reported-by: Alexander Ullrich <[email protected]> Reported-by: Diego Ercolani <[email protected]> Reported-by: Jan Szubiak <[email protected]> Reported-by: Marco Rebhan <[email protected]> Reported-by: Matthias Ferdinand <[email protected]> Reported-by: Victor Westerhuis <[email protected]> Reported-by: Vojtech Pavlik <[email protected]> Reported-and-tested-by: Rolf Fokkens <[email protected]> Reported-and-tested-by: Thorsten Knabe <[email protected]> Signed-off-by: Coly Li <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Cc: [email protected] Cc: Kent Overstreet <[email protected]> Cc: Nix <[email protected]> Cc: Takashi Iwai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent e369edb commit 1616a4c

File tree

5 files changed

+1
-32
lines changed

5 files changed

+1
-32
lines changed

drivers/md/bcache/bcache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ struct cached_dev {
364364

365365
/* The rest of this all shows up in sysfs */
366366
unsigned int sequential_cutoff;
367-
unsigned int readahead;
368367

369368
unsigned int io_disable:1;
370369
unsigned int verify:1;

drivers/md/bcache/request.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,6 @@ static int cached_dev_cache_miss(struct btree *b, struct search *s,
880880
struct bio *bio, unsigned int sectors)
881881
{
882882
int ret = MAP_CONTINUE;
883-
unsigned int reada = 0;
884883
struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
885884
struct bio *miss, *cache_bio;
886885

@@ -892,14 +891,7 @@ static int cached_dev_cache_miss(struct btree *b, struct search *s,
892891
goto out_submit;
893892
}
894893

895-
if (!(bio->bi_opf & REQ_RAHEAD) &&
896-
!(bio->bi_opf & (REQ_META|REQ_PRIO)) &&
897-
s->iop.c->gc_stats.in_use < CUTOFF_CACHE_READA)
898-
reada = min_t(sector_t, dc->readahead >> 9,
899-
get_capacity(bio->bi_bdev->bd_disk) -
900-
bio_end_sector(bio));
901-
902-
s->insert_bio_sectors = min(sectors, bio_sectors(bio) + reada);
894+
s->insert_bio_sectors = min(sectors, bio_sectors(bio));
903895

904896
s->iop.replace_key = KEY(s->iop.inode,
905897
bio->bi_iter.bi_sector + s->insert_bio_sectors,
@@ -933,9 +925,6 @@ static int cached_dev_cache_miss(struct btree *b, struct search *s,
933925
if (bch_bio_alloc_pages(cache_bio, __GFP_NOWARN|GFP_NOIO))
934926
goto out_put;
935927

936-
if (reada)
937-
bch_mark_cache_readahead(s->iop.c, s->d);
938-
939928
s->cache_miss = miss;
940929
s->iop.bio = cache_bio;
941930
bio_get(cache_bio);

drivers/md/bcache/stats.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ read_attribute(cache_misses);
4646
read_attribute(cache_bypass_hits);
4747
read_attribute(cache_bypass_misses);
4848
read_attribute(cache_hit_ratio);
49-
read_attribute(cache_readaheads);
5049
read_attribute(cache_miss_collisions);
5150
read_attribute(bypassed);
5251

@@ -64,7 +63,6 @@ SHOW(bch_stats)
6463
DIV_SAFE(var(cache_hits) * 100,
6564
var(cache_hits) + var(cache_misses)));
6665

67-
var_print(cache_readaheads);
6866
var_print(cache_miss_collisions);
6967
sysfs_hprint(bypassed, var(sectors_bypassed) << 9);
7068
#undef var
@@ -86,7 +84,6 @@ static struct attribute *bch_stats_files[] = {
8684
&sysfs_cache_bypass_hits,
8785
&sysfs_cache_bypass_misses,
8886
&sysfs_cache_hit_ratio,
89-
&sysfs_cache_readaheads,
9087
&sysfs_cache_miss_collisions,
9188
&sysfs_bypassed,
9289
NULL
@@ -113,7 +110,6 @@ void bch_cache_accounting_clear(struct cache_accounting *acc)
113110
acc->total.cache_misses = 0;
114111
acc->total.cache_bypass_hits = 0;
115112
acc->total.cache_bypass_misses = 0;
116-
acc->total.cache_readaheads = 0;
117113
acc->total.cache_miss_collisions = 0;
118114
acc->total.sectors_bypassed = 0;
119115
}
@@ -145,7 +141,6 @@ static void scale_stats(struct cache_stats *stats, unsigned long rescale_at)
145141
scale_stat(&stats->cache_misses);
146142
scale_stat(&stats->cache_bypass_hits);
147143
scale_stat(&stats->cache_bypass_misses);
148-
scale_stat(&stats->cache_readaheads);
149144
scale_stat(&stats->cache_miss_collisions);
150145
scale_stat(&stats->sectors_bypassed);
151146
}
@@ -168,7 +163,6 @@ static void scale_accounting(struct timer_list *t)
168163
move_stat(cache_misses);
169164
move_stat(cache_bypass_hits);
170165
move_stat(cache_bypass_misses);
171-
move_stat(cache_readaheads);
172166
move_stat(cache_miss_collisions);
173167
move_stat(sectors_bypassed);
174168

@@ -209,14 +203,6 @@ void bch_mark_cache_accounting(struct cache_set *c, struct bcache_device *d,
209203
mark_cache_stats(&c->accounting.collector, hit, bypass);
210204
}
211205

212-
void bch_mark_cache_readahead(struct cache_set *c, struct bcache_device *d)
213-
{
214-
struct cached_dev *dc = container_of(d, struct cached_dev, disk);
215-
216-
atomic_inc(&dc->accounting.collector.cache_readaheads);
217-
atomic_inc(&c->accounting.collector.cache_readaheads);
218-
}
219-
220206
void bch_mark_cache_miss_collision(struct cache_set *c, struct bcache_device *d)
221207
{
222208
struct cached_dev *dc = container_of(d, struct cached_dev, disk);

drivers/md/bcache/stats.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ struct cache_stat_collector {
77
atomic_t cache_misses;
88
atomic_t cache_bypass_hits;
99
atomic_t cache_bypass_misses;
10-
atomic_t cache_readaheads;
1110
atomic_t cache_miss_collisions;
1211
atomic_t sectors_bypassed;
1312
};

drivers/md/bcache/sysfs.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ rw_attribute(io_disable);
137137
rw_attribute(discard);
138138
rw_attribute(running);
139139
rw_attribute(label);
140-
rw_attribute(readahead);
141140
rw_attribute(errors);
142141
rw_attribute(io_error_limit);
143142
rw_attribute(io_error_halflife);
@@ -260,7 +259,6 @@ SHOW(__bch_cached_dev)
260259
var_printf(partial_stripes_expensive, "%u");
261260

262261
var_hprint(sequential_cutoff);
263-
var_hprint(readahead);
264262

265263
sysfs_print(running, atomic_read(&dc->running));
266264
sysfs_print(state, states[BDEV_STATE(&dc->sb)]);
@@ -365,7 +363,6 @@ STORE(__cached_dev)
365363
sysfs_strtoul_clamp(sequential_cutoff,
366364
dc->sequential_cutoff,
367365
0, UINT_MAX);
368-
d_strtoi_h(readahead);
369366

370367
if (attr == &sysfs_clear_stats)
371368
bch_cache_accounting_clear(&dc->accounting);
@@ -538,7 +535,6 @@ static struct attribute *bch_cached_dev_files[] = {
538535
&sysfs_running,
539536
&sysfs_state,
540537
&sysfs_label,
541-
&sysfs_readahead,
542538
#ifdef CONFIG_BCACHE_DEBUG
543539
&sysfs_verify,
544540
&sysfs_bypass_torture_test,

0 commit comments

Comments
 (0)