bcache: get rid of discard code from journal
Subsystems (2)
PATCH 1/4 bcache: get rid of discard code from journal
From: Coly Li <[email protected]>
In bcache journal there is discard funcationality but almost useless in reality. Becasue discard happens after a journal bucket is reclaimed, and the reclaimed bucket is allocated for new journaling immediately. There is no time for underlying SSD to use the discard hint for internal data management.
The discard code in bcache journal doesn't bring any performance optimization and wastes CPU cycles for issuing discard bios. Therefore this patch gits rid of it from journal.c and journal.h.
--- drivers/md/bcache/journal.c | 85 ++----------------------------------- drivers/md/bcache/journal.h | 13 ------ 2 files changed, 4 insertions(+), 94 deletions(-)
drivers/md/bcache/journal.c +4 -81
@@ -275,8 +275,7 @@ int bch_journal_read(struct cache_set *c, struct list_head *list)* ja->cur_idx */ ja->cur_idx = i; - ja->last_idx = ja->discard_idx = (i +1 ) % - ca->sb.njournal_buckets; + ja->last_idx = (i +1 ) % ca->sb.njournal_buckets; }
@@ -336,16 +335,6 @@ void bch_journal_mark(struct cache_set *c, struct list_head *list) } } -static bool is_discard_enabled (struct cache_set *s) -{ -struct cache *ca = s->cache; - -if (ca->discard) -return true; - -return false; -} -int bch_journal_replay (struct cache_set *s,struct list_head *list) {int ret =0 , keys =0 , entries =0 ;
@@ -360,15 +349,10 @@ int bch_journal_replay(struct cache_set *s, struct list_head *list)BUG_ON (i->pin &&atomic_read (i->pin) !=1 );if (n != i->j.seq) { -if (n == start &&is_discard_enabled (s)) -pr_info ("journal entries %llu-%llu may be discarded! (replaying %llu-%llu)\n" , - n, i->j.seq -1 , start, end); -else {pr_err ("journal entries %llu-%llu missing! (replaying %llu-%llu)\n" , n, i->j.seq -1 , start, end); ret = -EIO ; goto err; - } } for (k = i->j.start;
@@ -568,65 +552,6 @@ static void btree_flush_write(struct cache_set *c)#define last_seq (j) ((j)->seq - fifo_used(&(j)->pin) + 1) -static void journal_discard_endio (struct bio *bio) -{ -struct journal_device *ja = - container_of(bio, struct journal_device, discard_bio); - struct cache *ca = container_of(ja, struct cache, journal); - -atomic_set (&ja->discard_in_flight,DISCARD_DONE ); - -closure_wake_up (&ca->set->journal.wait); -closure_put (&ca->set->cl); -} - -static void journal_discard_work (struct work_struct *work) -{ -struct journal_device *ja = - container_of(work, struct journal_device, discard_work); - -submit_bio (&ja->discard_bio); -} - -static void do_journal_discard (struct cache *ca) -{ -struct journal_device *ja = &ca->journal; -struct bio *bio = &ja->discard_bio; - -if (!ca->discard) { - ja->discard_idx = ja->last_idx; -return ; - } - -switch (atomic_read (&ja->discard_in_flight)) { -case DISCARD_IN_FLIGHT : -return ; - -case DISCARD_DONE : - ja->discard_idx = (ja->discard_idx +1 ) % - ca->sb.njournal_buckets; - -atomic_set (&ja->discard_in_flight,DISCARD_READY ); - fallthrough; - -case DISCARD_READY : -if (ja->discard_idx == ja->last_idx) -return ; - -atomic_set (&ja->discard_in_flight,DISCARD_IN_FLIGHT ); - -bio_init (bio, ca->bdev, bio->bi_inline_vecs,1 ,REQ_OP_DISCARD ); - bio->bi_iter.bi_sector =bucket_to_sector (ca->set, - ca->sb.d[ja->discard_idx]); - bio->bi_iter.bi_size =bucket_bytes (ca); - bio->bi_end_io = journal_discard_endio; - -closure_get (&ca->set->cl); -INIT_WORK (&ja->discard_work, journal_discard_work); -queue_work (bch_journal_wq, &ja->discard_work); - } -} -static unsigned int free_journal_buckets (struct cache_set *c) {struct journal *j = &c->journal;
@@ -635,10 +560,10 @@ static unsigned int free_journal_buckets(struct cache_set *c)unsigned int n;/* In case njournal_buckets is not power of 2 */ -if (ja->cur_idx >= ja->discard_idx) - n = ca->sb.njournal_buckets + ja->discard_idx - ja->cur_idx; +if (ja->cur_idx >= ja->last_idx) + n = ca->sb.njournal_buckets + ja->last_idx - ja->cur_idx;else - n = ja->discard_idx - ja->cur_idx; + n = ja->last_idx - ja->cur_idx;if (n > (1 + j->do_reserve))return n - (1 + j->do_reserve);
@@ -668,8 +593,6 @@ static void journal_reclaim(struct cache_set *c) ja->last_idx = (ja->last_idx +1 ) % ca->sb.njournal_buckets; -do_journal_discard (ca); -if (c->journal.blocks_free) goto out;
drivers/md/bcache/journal.h +0 -13
@@ -139,19 +139,6 @@ struct journal_device {/* Last journal bucket that still contains an open journal entry */ unsigned int last_idx; -/* Next journal bucket to be discarded */ -unsigned int discard_idx; - -#define DISCARD_READY 0 -#define DISCARD_IN_FLIGHT 1 -#define DISCARD_DONE 2 -/* 1 - discard in flight, -1 - discard completed */ -atomic_t discard_in_flight; - -struct work_struct discard_work; -struct bio discard_bio; -struct bio_vec discard_bv; -/* Bio for journal reads/writes to this device */ struct bio bio;struct bio_vec bv[8 ];
Signature · 1 line
2.47.2
PATCH 2/4 bcache: remove discard code from alloc.c
From: Coly Li <[email protected]>
Bcache allocator initially has no free space to allocate. Firstly it does a garbage collection which is triggered by a cache device write and fills free space into ca->free[] lists. The discard happens after the free bucket is handled by garbage collection added into one of the ca->free[] lists. But normally this bucket will be allocated out very soon to requester and filled data onto it. The discard hint on this bucket LBA range doesn't help SSD control to improve internal erasure performance, and waste extra CPU cycles to issue discard bios.
This patch removes the almost-useless discard code from alloc.c.
--- drivers/md/bcache/alloc.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)
drivers/md/bcache/alloc.c +4 -17
@@ -24,21 +24,18 @@* Since the gens and priorities are all stored contiguously on disk, we can * batch this up: We fill up the free_inc list with freshly invalidated buckets, * call prio_write(), and when prio_write() finishes we pull buckets off the -* free_inc list and optionally discard them. +* free_inc list. * * free_inc isn't the only freelist - if it was, we'd often to sleep while * priorities and gens were being written before we could allocate. c->free is a * smaller freelist, and buckets on that list are always ready to be used. * -* If we've got discards enabled, that happens when a bucket moves from the -* free_inc list to the free list. -* * There is another freelist, because sometimes we have buckets that we know * have nothing pointing into them - these we can reuse without waiting for * priorities to be rewritten. These come from freed btree nodes and buckets * that garbage collection discovered no longer had valid keys pointing into * them (because they were overwritten). That's the unused list - buckets on the -* unused list move to the free list, optionally being discarded in the process. +* unused list move to the free list. * * It's also important to ensure that gens don't wrap around - with respect to * either the oldest gen in the btree or the gen on disk. This is quite
@@ -118,8 +115,7 @@ void bch_rescale_priorities(struct cache_set *c, int sectors)/* * Background allocation thread: scans for buckets to be invalidated, * invalidates them, rewrites prios/gens (marking them as invalidated on disk), -* then optionally issues discard commands to the newly free buckets, then puts -* them on the various freelists. +* then puts them on the various freelists. */ static inline bool can_inc_bucket_gen (struct bucket *b)
@@ -321,8 +317,7 @@ static int bch_allocator_thread(void *arg)while (1 ) {/* * First, we pull buckets off of the unused and free_inc lists, -* possibly issue discards to them, then we add the bucket to -* the free list: +* then we add the bucket to the free list: */ while (1 ) {long bucket;
@@ -330,14 +325,6 @@ static int bch_allocator_thread(void *arg)if (!fifo_pop (&ca->free_inc, bucket))break ; -if (ca->discard) { -mutex_unlock (&ca->set->bucket_lock); -blkdev_issue_discard (ca->bdev, -bucket_to_sector (ca->set, bucket), - ca->sb.bucket_size,GFP_KERNEL ); -mutex_lock (&ca->set->bucket_lock); - } -allocator_wait (ca,bch_allocator_push (ca, bucket));wake_up (&ca->set->btree_cache_wait);wake_up (&ca->set->bucket_wait);
Signature · 1 line
2.47.2
PATCH 3/4 bcache: drop discard sysfs interface
In reply to [email protected]From: Coly Li <[email protected]>
Since discard code is removed, now the sysfs interface to enable discard is useless. This patch removes the corresponding sysfs entry, and remove bool variable 'discard' from struct cache as well.
--- drivers/md/bcache/bcache.h | 5 +---- drivers/md/bcache/super.c | 3 --- drivers/md/bcache/sysfs.c | 15 --------------- drivers/md/bcache/writeback.c | 3 +-- 4 files changed, 2 insertions(+), 24 deletions(-)
drivers/md/bcache/bcache.h +1 -4
@@ -448,8 +448,7 @@ struct cache {* free_inc: Incoming buckets - these are buckets that currently have * cached data in them, and we can't reuse them until after we write * their new gen to disk. After prio_write() finishes writing the new -* gens/prios, they'll be moved to the free list (and possibly discarded -* in the process) +* gens/prios, they'll be moved to the free list. */ DECLARE_FIFO (long, free)[RESERVE_NR ];DECLARE_FIFO (long, free_inc);
@@ -468,8 +467,6 @@ struct cache {*/ unsigned int invalidate_needs_gc; -bool discard;/* Get rid of? */ -struct journal_device journal;/* The rest of this all shows up in sysfs */
drivers/md/bcache/super.c +0 -3
@@ -2382,9 +2382,6 @@ static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk, ca->bdev =file_bdev (bdev_file); ca->sb_disk = sb_disk; -if (bdev_max_discard_sectors (file_bdev (bdev_file))) - ca->discard =CACHE_DISCARD (&ca->sb); - ret =cache_alloc (ca);if (ret !=0 ) {if (ret == -ENOMEM )
drivers/md/bcache/sysfs.c +0 -15
@@ -134,7 +134,6 @@ read_attribute(partial_stripes_expensive);rw_attribute (synchronous);rw_attribute (journal_delay_ms);rw_attribute (io_disable); -rw_attribute (discard);rw_attribute (running);rw_attribute (label);rw_attribute (errors);
@@ -1036,7 +1035,6 @@ SHOW(__bch_cache)sysfs_hprint (bucket_size,bucket_bytes (ca));sysfs_hprint (block_size,block_bytes (ca));sysfs_print (nbuckets, ca->sb.nbuckets); -sysfs_print (discard, ca->discard);sysfs_hprint (written,atomic_long_read (&ca->sectors_written) <<9 );sysfs_hprint (btree_written,atomic_long_read (&ca->btree_sectors_written) <<9 );
@@ -1142,18 +1140,6 @@ STORE(__bch_cache)if (bcache_is_reboot)return -EBUSY ; -if (attr == &sysfs_discard) { -bool v =strtoul_or_return (buf); - -if (bdev_max_discard_sectors (ca->bdev)) - ca->discard = v; - -if (v !=CACHE_DISCARD (&ca->sb)) { -SET_CACHE_DISCARD (&ca->sb, v); -bcache_write_super (ca->set); - } - } -if (attr == &sysfs_cache_replacement_policy) { v =__sysfs_match_string (cache_replacement_policies,-1 , buf);if (v <0 )
@@ -1185,7 +1171,6 @@ static struct attribute *bch_cache_attrs[] = { &sysfs_block_size, &sysfs_nbuckets, &sysfs_priority_stats, - &sysfs_discard, &sysfs_written, &sysfs_btree_written, &sysfs_metadata_written,
drivers/md/bcache/writeback.c +1 -2
@@ -793,8 +793,7 @@ static int bch_writeback_thread(void *arg)* may set BCH_ENABLE_AUTO_GC via sysfs, then when * BCH_DO_AUTO_GC is set, garbage collection thread * will be wake up here. After moving gc, the shrunk -* btree and discarded free buckets SSD space may be -* helpful for following write requests. +* btree may be helpful for following write requests. */ if (c->gc_after_writeback == (BCH_ENABLE_AUTO_GC |BCH_DO_AUTO_GC )) {
Signature · 1 line
2.47.2
PATCH 4/4 bcache: remove discard sysfs interface document
In reply to [email protected]From: Coly Li <[email protected]>
This patch removes documents of bcache discard sysfs interface, it drops discard related sections from,
- Documentation/ABI/testing/sysfs-block-bcache
- Documentation/admin-guide/bcache.rst
--- Documentation/ABI/testing/sysfs-block-bcache | 7 ------- Documentation/admin-guide/bcache.rst | 13 ++----------- 2 files changed, 2 insertions(+), 18 deletions(-)
Documentation/ABI/testing/sysfs-block-bcache +0 -7
@@ -106,13 +106,6 @@ Description: will be discarded from the cache. Should not be turned off with writeback caching enabled. -What: /sys/block/<disk>/bcache/discard -Date: November 2010 -Contact: Kent Overstreet <[email protected]> -Description: - For a cache, a boolean allowing discard/TRIM to be turned off - or back on if the device supports it. - What: /sys/block/<disk>/bcache/bucket_size Date: November 2010 Contact: Kent Overstreet <[email protected]>
Documentation/admin-guide/bcache.rst +2 -11
@@ -17,8 +17,7 @@ The latest bcache kernel code can be found from mainline Linux kernel: It's designed around the performance characteristics of SSDs - it only allocates in erase block sized buckets, and it uses a hybrid btree/log to track cached extents (which can be anywhere from a single sector to the bucket size). It's -designed to avoid random writes at all costs; it fills up an erase block -sequentially, then issues a discard before reusing it. +designed to avoid random writes at all costs. Both writethrough and writeback caching are supported. Writeback defaults to off, but can be switched on and off arbitrarily at runtime. Bcache goes to
@@ -618,19 +617,11 @@ bucket_size cache_replacement_policy One of either lru, fifo or random. -discard - Boolean; if on a discard/TRIM will be issued to each bucket before it is - reused. Defaults to off, since SATA TRIM is an unqueued command (and thus - slow). - freelist_percent Size of the freelist as a percentage of nbuckets. Can be written to to increase the number of buckets kept on the freelist, which lets you artificially reduce the size of the cache at runtime. Mostly for testing - purposes (i.e. testing how different size caches affect your hit rate), but - since buckets are discarded when they move on to the freelist will also make - the SSD's garbage collection easier by effectively giving it more reserved - space. + purposes (i.e. testing how different size caches affect your hit rate). io_errors Number of errors that have occurred, decayed by io_error_halflife.
Signature · 1 line
2.47.2