Skip to content

Commit 038ba8c

Browse files
Coly Liaxboe
authored andcommitted
bcache: add readahead cache policy options via sysfs interface
In year 2007 high performance SSD was still expensive, in order to save more space for real workload or meta data, the readahead I/Os for non-meta data was bypassed and not cached on SSD. In now days, SSD price drops a lot and people can find larger size SSD with more comfortable price. It is unncessary to alway bypass normal readahead I/Os to save SSD space for now. This patch adds options for readahead data cache policies via sysfs file /sys/block/bcache<N>/readahead_cache_policy, the options are, - "all": cache all readahead data I/Os. - "meta-only": only cache meta data, and bypass other regular I/Os. If users want to make bcache continue to only cache readahead request for metadata and bypass regular data readahead, please set "meta-only" to this sysfs file. By default, bcache will back to cache all read- ahead requests now. Cc: [email protected] Signed-off-by: Coly Li <[email protected]> Acked-by: Eric Wheeler <[email protected]> Cc: Michael Lyle <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 7c02b00 commit 038ba8c

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

drivers/md/bcache/bcache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ struct cached_dev {
330330
*/
331331
atomic_t has_dirty;
332332

333+
#define BCH_CACHE_READA_ALL 0
334+
#define BCH_CACHE_READA_META_ONLY 1
335+
unsigned int cache_readahead_policy;
333336
struct bch_ratelimit writeback_rate;
334337
struct delayed_work writeback_rate_update;
335338

drivers/md/bcache/request.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,20 @@ static bool check_should_bypass(struct cached_dev *dc, struct bio *bio)
379379
goto skip;
380380

381381
/*
382-
* Flag for bypass if the IO is for read-ahead or background,
383-
* unless the read-ahead request is for metadata
382+
* If the bio is for read-ahead or background IO, bypass it or
383+
* not depends on the following situations,
384+
* - If the IO is for meta data, always cache it and no bypass
385+
* - If the IO is not meta data, check dc->cache_reada_policy,
386+
* BCH_CACHE_READA_ALL: cache it and not bypass
387+
* BCH_CACHE_READA_META_ONLY: not cache it and bypass
388+
* That is, read-ahead request for metadata always get cached
384389
* (eg, for gfs2 or xfs).
385390
*/
386-
if (bio->bi_opf & (REQ_RAHEAD|REQ_BACKGROUND) &&
387-
!(bio->bi_opf & (REQ_META|REQ_PRIO)))
388-
goto skip;
391+
if ((bio->bi_opf & (REQ_RAHEAD|REQ_BACKGROUND))) {
392+
if (!(bio->bi_opf & (REQ_META|REQ_PRIO)) &&
393+
(dc->cache_readahead_policy != BCH_CACHE_READA_ALL))
394+
goto skip;
395+
}
389396

390397
if (bio->bi_iter.bi_sector & (c->sb.block_size - 1) ||
391398
bio_sectors(bio) & (c->sb.block_size - 1)) {

drivers/md/bcache/sysfs.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ static const char * const bch_cache_modes[] = {
2727
NULL
2828
};
2929

30+
static const char * const bch_reada_cache_policies[] = {
31+
"all",
32+
"meta-only",
33+
NULL
34+
};
35+
3036
/* Default is 0 ("auto") */
3137
static const char * const bch_stop_on_failure_modes[] = {
3238
"auto",
@@ -100,6 +106,7 @@ rw_attribute(congested_write_threshold_us);
100106
rw_attribute(sequential_cutoff);
101107
rw_attribute(data_csum);
102108
rw_attribute(cache_mode);
109+
rw_attribute(readahead_cache_policy);
103110
rw_attribute(stop_when_cache_set_failed);
104111
rw_attribute(writeback_metadata);
105112
rw_attribute(writeback_running);
@@ -168,6 +175,11 @@ SHOW(__bch_cached_dev)
168175
bch_cache_modes,
169176
BDEV_CACHE_MODE(&dc->sb));
170177

178+
if (attr == &sysfs_readahead_cache_policy)
179+
return bch_snprint_string_list(buf, PAGE_SIZE,
180+
bch_reada_cache_policies,
181+
dc->cache_readahead_policy);
182+
171183
if (attr == &sysfs_stop_when_cache_set_failed)
172184
return bch_snprint_string_list(buf, PAGE_SIZE,
173185
bch_stop_on_failure_modes,
@@ -353,6 +365,15 @@ STORE(__cached_dev)
353365
}
354366
}
355367

368+
if (attr == &sysfs_readahead_cache_policy) {
369+
v = __sysfs_match_string(bch_reada_cache_policies, -1, buf);
370+
if (v < 0)
371+
return v;
372+
373+
if ((unsigned int) v != dc->cache_readahead_policy)
374+
dc->cache_readahead_policy = v;
375+
}
376+
356377
if (attr == &sysfs_stop_when_cache_set_failed) {
357378
v = __sysfs_match_string(bch_stop_on_failure_modes, -1, buf);
358379
if (v < 0)
@@ -467,6 +488,7 @@ static struct attribute *bch_cached_dev_files[] = {
467488
&sysfs_data_csum,
468489
#endif
469490
&sysfs_cache_mode,
491+
&sysfs_readahead_cache_policy,
470492
&sysfs_stop_when_cache_set_failed,
471493
&sysfs_writeback_metadata,
472494
&sysfs_writeback_running,

0 commit comments

Comments
 (0)