From ed0bf94281867497c0e088451e4edc1fd517209f Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Wed, 23 Nov 2022 23:10:20 -0500 Subject: bcachefs: Optimize cacheline access in __bch2_write() This tweaks __bch2_write() to add the bch_write_op to the writepoint list before submitting the bio - we prefer to not have to touch the op at all after submitting the bio, and before submitting the bio the writepoint is still in cache. Also, this centralizes where we set BCH_WRITE_DONE, making for a minor cleanup. Signed-off-by: Kent Overstreet --- fs/bcachefs/io.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c index 25534a113b7b..e40d196edb58 100644 --- a/fs/bcachefs/io.c +++ b/fs/bcachefs/io.c @@ -1620,27 +1620,33 @@ again: BCH_WRITE_ONLY_SPECIFIED_DEVS)) ? NULL : &op->cl, &wp)); if (unlikely(ret)) { - if (unlikely(ret != -EAGAIN)) { - op->error = ret; - op->flags |= BCH_WRITE_DONE; - } + if (ret == -EAGAIN) + break; - break; + goto err; } - bch2_open_bucket_get(c, wp, &op->open_buckets); ret = bch2_write_extent(op, wp, &bio); + if (ret >= 0) + bch2_open_bucket_get(c, wp, &op->open_buckets); bch2_alloc_sectors_done_inlined(c, wp); +err: + if (ret <= 0) { + if (!(op->flags & BCH_WRITE_SYNC)) { + spin_lock(&wp->writes_lock); + op->wp = wp; + list_add_tail(&op->wp_list, &wp->writes); + spin_unlock(&wp->writes_lock); + } - if (ret < 0) { - op->error = ret; op->flags |= BCH_WRITE_DONE; - break; - } - if (!ret) - op->flags |= BCH_WRITE_DONE; + if (ret < 0) { + op->error = ret; + break; + } + } bio->bi_end_io = bch2_write_endio; bio->bi_private = &op->cl; @@ -1670,11 +1676,6 @@ again: goto again; bch2_write_done(&op->cl); } else { - spin_lock(&wp->writes_lock); - op->wp = wp; - list_add_tail(&op->wp_list, &wp->writes); - spin_unlock(&wp->writes_lock); - continue_at(&op->cl, bch2_write_index, NULL); } out_nofs_restore: -- cgit v1.2.3