From patchwork Tue Mar 14 16:59:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13174783 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C589DC05027 for ; Tue, 14 Mar 2023 16:59:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230210AbjCNQ73 (ORCPT ); Tue, 14 Mar 2023 12:59:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbjCNQ72 (ORCPT ); Tue, 14 Mar 2023 12:59:28 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 060AB9E500 for ; Tue, 14 Mar 2023 09:59:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=SOtXqtua60yI6JwuTEN0td7rIeAQSfeuIKl98eWi70A=; b=vaS19mcRkqWi2ToN1RBjgbWJs9 UeGTh9qRcPF3hiBbIrad18E8S9+FrOv4byR5pyAP8uPF7KHkiDIJEvCNg9TZhyaOaKqUkQhOyJPWh 6G10n32bGc88UxUaupeW0TUqqiugExIzaVlW0qCmEcR46GTDxl+ZfKynGblutAOzzSY9GRaU8OQxK AmIseWoUay1ieOpclcHpN9pR9h1TA1Wyrwrt/7TUxRsqs1gqJi4V97tQ00K0TwhUmVxljQv9MpZ4W eSDDsLoAZJpeMoJIcsfza3Agj7VpbAxnpR5XiZ9cbRi0WKxAd+e1vFVyAkt8r5d8OlbbC9ZTn4JVi zU7QZ8kA==; Received: from [2001:4bb8:182:2e36:91ea:d0e2:233a:8356] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pc7za-00Avlm-28; Tue, 14 Mar 2023 16:59:19 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org Subject: [PATCH 01/10] btrfs: use a plain workqueue for ordered_extent processing Date: Tue, 14 Mar 2023 17:59:01 +0100 Message-Id: <20230314165910.373347-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314165910.373347-1-hch@lst.de> References: <20230314165910.373347-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The endio_write_workers and endio_freespace_workers workqueues don't use any of the ordering features in the btrfs_workqueue, so switch them to plain Linux workqueues. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/disk-io.c | 16 ++++++++-------- fs/btrfs/fs.h | 4 ++-- fs/btrfs/ordered-data.c | 8 ++++---- fs/btrfs/ordered-data.h | 2 +- fs/btrfs/super.c | 2 -- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index bb864cf2eed60f..0889eb81e71a7d 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1993,8 +1993,10 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) destroy_workqueue(fs_info->rmw_workers); if (fs_info->compressed_write_workers) destroy_workqueue(fs_info->compressed_write_workers); - btrfs_destroy_workqueue(fs_info->endio_write_workers); - btrfs_destroy_workqueue(fs_info->endio_freespace_worker); + if (fs_info->endio_write_workers) + destroy_workqueue(fs_info->endio_write_workers); + if (fs_info->endio_freespace_worker) + destroy_workqueue(fs_info->endio_freespace_worker); btrfs_destroy_workqueue(fs_info->delayed_workers); btrfs_destroy_workqueue(fs_info->caching_workers); btrfs_destroy_workqueue(fs_info->flush_workers); @@ -2204,13 +2206,11 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info) alloc_workqueue("btrfs-endio-meta", flags, max_active); fs_info->rmw_workers = alloc_workqueue("btrfs-rmw", flags, max_active); fs_info->endio_write_workers = - btrfs_alloc_workqueue(fs_info, "endio-write", flags, - max_active, 2); + alloc_workqueue("btrfs-endio-write", flags, max_active); fs_info->compressed_write_workers = alloc_workqueue("btrfs-compressed-write", flags, max_active); fs_info->endio_freespace_worker = - btrfs_alloc_workqueue(fs_info, "freespace-write", flags, - max_active, 0); + alloc_workqueue("btrfs-freespace-write", flags, max_active); fs_info->delayed_workers = btrfs_alloc_workqueue(fs_info, "delayed-meta", flags, max_active, 0); @@ -4536,9 +4536,9 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info) * the final btrfs_put_ordered_extent() (which must happen at * btrfs_finish_ordered_io() when we are unmounting). */ - btrfs_flush_workqueue(fs_info->endio_write_workers); + flush_workqueue(fs_info->endio_write_workers); /* Ordered extents for free space inodes. */ - btrfs_flush_workqueue(fs_info->endio_freespace_worker); + flush_workqueue(fs_info->endio_freespace_worker); btrfs_run_delayed_iputs(fs_info); cancel_work_sync(&fs_info->async_reclaim_work); diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index 20d554a0c2ac0d..276a17780f2b1b 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -542,8 +542,8 @@ struct btrfs_fs_info { struct workqueue_struct *endio_meta_workers; struct workqueue_struct *rmw_workers; struct workqueue_struct *compressed_write_workers; - struct btrfs_workqueue *endio_write_workers; - struct btrfs_workqueue *endio_freespace_worker; + struct workqueue_struct *endio_write_workers; + struct workqueue_struct *endio_freespace_worker; struct btrfs_workqueue *caching_workers; /* diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index 1848d0d1a9c41e..23f496f0d7b776 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -303,7 +303,7 @@ void btrfs_add_ordered_sum(struct btrfs_ordered_extent *entry, spin_unlock_irq(&tree->lock); } -static void finish_ordered_fn(struct btrfs_work *work) +static void finish_ordered_fn(struct work_struct *work) { struct btrfs_ordered_extent *ordered_extent; @@ -330,7 +330,7 @@ void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode, { struct btrfs_ordered_inode_tree *tree = &inode->ordered_tree; struct btrfs_fs_info *fs_info = inode->root->fs_info; - struct btrfs_workqueue *wq; + struct workqueue_struct *wq; struct rb_node *node; struct btrfs_ordered_extent *entry = NULL; unsigned long flags; @@ -439,8 +439,8 @@ void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode, refcount_inc(&entry->refs); trace_btrfs_ordered_extent_mark_finished(inode, entry); spin_unlock_irqrestore(&tree->lock, flags); - btrfs_init_work(&entry->work, finish_ordered_fn, NULL, NULL); - btrfs_queue_work(wq, &entry->work); + INIT_WORK(&entry->work, finish_ordered_fn); + queue_work(wq, &entry->work); spin_lock_irqsave(&tree->lock, flags); } cur += len; diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index 18007f9c00add8..b8a92f040458f0 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h @@ -146,7 +146,7 @@ struct btrfs_ordered_extent { /* a per root list of all the pending ordered extents */ struct list_head root_extent_list; - struct btrfs_work work; + struct work_struct work; struct completion completion; struct btrfs_work flush_work; diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index d8885966e801cd..065b4fab1ee011 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1632,8 +1632,6 @@ static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, btrfs_workqueue_set_max(fs_info->hipri_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->delalloc_workers, new_pool_size); btrfs_workqueue_set_max(fs_info->caching_workers, new_pool_size); - btrfs_workqueue_set_max(fs_info->endio_write_workers, new_pool_size); - btrfs_workqueue_set_max(fs_info->endio_freespace_worker, new_pool_size); btrfs_workqueue_set_max(fs_info->delayed_workers, new_pool_size); } From patchwork Tue Mar 14 16:59:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13174784 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34055C6FD1F for ; Tue, 14 Mar 2023 16:59:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230233AbjCNQ7a (ORCPT ); Tue, 14 Mar 2023 12:59:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229675AbjCNQ72 (ORCPT ); Tue, 14 Mar 2023 12:59:28 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 910D3A02A7 for ; Tue, 14 Mar 2023 09:59:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=graDNQDKAEOgHjlYqlQU0upJF15HC8DpSAcInFf6Bb8=; b=XLl/jNUrm49DH40h/JdkqkQLGZ hlp188hzCZgea2Nmm22clwfKv28WY5u2KiB5OWCJd7777h6azlZLx8zbTH5Cji2VORbim8Xvjd+4T fWKZO5DUz7g7XfoX+DKexLWNeTGxBdJr4zPBgwlx5OSvMG5cQQjHGNiegtTdoeORw+lU7+SI1FiHB WiqvuMnZTKrnXgRqVmYcMFFNNdgwTNWS8mrQz1QLeZlkg+u4rCE3YK/15Tbjp5j7kBpfx1zyrCxLB VpgdEIrfsNsD61RF4bL8uhRZAUE0x8xhSiATNk3CIw1wGwwY4yi/bwreWJLJpOsXhmVTFSXF71lhg VndfmDRA==; Received: from [2001:4bb8:182:2e36:91ea:d0e2:233a:8356] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pc7ze-00AvmU-38; Tue, 14 Mar 2023 16:59:23 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org Subject: [PATCH 02/10] btrfs: refactor btrfs_end_io_wq Date: Tue, 14 Mar 2023 17:59:02 +0100 Message-Id: <20230314165910.373347-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314165910.373347-1-hch@lst.de> References: <20230314165910.373347-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Pass a btrfs_bio instead of a fs_info and bio. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Reviewed-by: Qu Wenruo --- fs/btrfs/bio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index cf09c6271edbee..85539964864a34 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -296,10 +296,11 @@ static void btrfs_log_dev_io_error(struct bio *bio, struct btrfs_device *dev) btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_FLUSH_ERRS); } -static struct workqueue_struct *btrfs_end_io_wq(struct btrfs_fs_info *fs_info, - struct bio *bio) +static struct workqueue_struct *btrfs_end_io_wq(struct btrfs_bio *bbio) { - if (bio->bi_opf & REQ_META) + struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info; + + if (bbio->bio.bi_opf & REQ_META) return fs_info->endio_meta_workers; return fs_info->endio_workers; } @@ -319,16 +320,15 @@ static void btrfs_simple_end_io(struct bio *bio) { struct btrfs_bio *bbio = btrfs_bio(bio); struct btrfs_device *dev = bio->bi_private; - struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info; - btrfs_bio_counter_dec(fs_info); + btrfs_bio_counter_dec(bbio->inode->root->fs_info); if (bio->bi_status) btrfs_log_dev_io_error(bio, dev); if (bio_op(bio) == REQ_OP_READ) { INIT_WORK(&bbio->end_io_work, btrfs_end_bio_work); - queue_work(btrfs_end_io_wq(fs_info, bio), &bbio->end_io_work); + queue_work(btrfs_end_io_wq(bbio), &bbio->end_io_work); } else { if (bio_op(bio) == REQ_OP_ZONE_APPEND) btrfs_record_physical_zoned(bbio); From patchwork Tue Mar 14 16:59:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13174785 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FB85C6FD1F for ; Tue, 14 Mar 2023 16:59:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230241AbjCNQ7d (ORCPT ); Tue, 14 Mar 2023 12:59:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230155AbjCNQ7c (ORCPT ); Tue, 14 Mar 2023 12:59:32 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CB4AA2C33 for ; Tue, 14 Mar 2023 09:59:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=YdteaEbv9gfHhF8ezsTAEuwWgOu/EQFpLiSWDnWiFHI=; b=4hGHvSlVekPLr1CNsznCkM1Wu1 jnD6EXEnQ8DwnjAL+bCM3fz+5IE3C78qRd3PpTpMCgny4iEVeAmUAyNSRmX6arU+0CShFqWZgFdrQ Z4eo4UpWVskYYm7IsxgPD9l1g1pkpBOfLk1QkWf7pzFsMJ+aelnzMvwga+mga+6vDloA2DpOH7oBQ C2BgasF0yS1b5xRoCTYHw7aej7gpEOcwHdAk+xfDDQk/18THKeOhYDxfS46Fzj8UR84n2tThOFkwh 3rk8pfi4mcxMIaoO3pgtoHmgO49dZN0qmmNjHNQWu7Gkja5LpOUsuJSJ1ABz0vQ+4dHo5t4A1YiY0 v+rGv7BA==; Received: from [2001:4bb8:182:2e36:91ea:d0e2:233a:8356] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pc7zj-00Avmu-1A; Tue, 14 Mar 2023 16:59:27 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org Subject: [PATCH 03/10] btrfs: offload all write I/O completions to a workqueue Date: Tue, 14 Mar 2023 17:59:03 +0100 Message-Id: <20230314165910.373347-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314165910.373347-1-hch@lst.de> References: <20230314165910.373347-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Currently all reads are offloaded to workqueues for checksum verification. Writes are initially processed in the bi_end_io context that usually happens in hard or soft interrupts, and are only offloaded to a workqueue for ordered extent completion or compressed extent handling, and in the future for raid stripe tree handling. Switch to offload all writes to workqueues instead of doing that only for the final ordered extent processing. This means that there are slightly workqueue offloads for large writes as each submitted btrfs_bio can only hold 1MiB worth of data on systems with a 4K page size. On the other hand this will allow large simpliciations by always having a process context. For metadata writes there was not offload at all before, which creates various problems like not being able to drop the final extent_buffered reference from the end_io handler. With the entire series applied this shows no performance differences on data heavy workload, while for metadata heavy workloads like Filipes fs_mark there also is no change in averages, while it seems to somewhat reduce the outliers in terms of best and worst performance. This is probably due to the removal of the irq disabling in the next patches. Signed-off-by: Christoph Hellwig --- fs/btrfs/bio.c | 74 ++++++++++++++++++++++++++++------------- fs/btrfs/disk-io.c | 5 +++ fs/btrfs/fs.h | 1 + fs/btrfs/ordered-data.c | 17 +--------- fs/btrfs/ordered-data.h | 2 -- 5 files changed, 57 insertions(+), 42 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 85539964864a34..037eded3b33ba2 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -300,20 +300,33 @@ static struct workqueue_struct *btrfs_end_io_wq(struct btrfs_bio *bbio) { struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info; - if (bbio->bio.bi_opf & REQ_META) - return fs_info->endio_meta_workers; - return fs_info->endio_workers; + if (btrfs_op(&bbio->bio) == BTRFS_MAP_WRITE) { + if (btrfs_is_free_space_inode(bbio->inode)) + return fs_info->endio_freespace_worker; + if (bbio->bio.bi_opf & REQ_META) + return fs_info->endio_write_meta_workers; + return fs_info->endio_write_workers; + } else { + if (bbio->bio.bi_opf & REQ_META) + return fs_info->endio_meta_workers; + return fs_info->endio_workers; + } } -static void btrfs_end_bio_work(struct work_struct *work) +static void btrfs_simple_end_bio_work(struct work_struct *work) { struct btrfs_bio *bbio = container_of(work, struct btrfs_bio, end_io_work); + struct bio *bio = &bbio->bio; + struct btrfs_device *dev = bio->bi_private; /* Metadata reads are checked and repaired by the submitter. */ - if (bbio->bio.bi_opf & REQ_META) - bbio->end_io(bbio); - else - btrfs_check_read_bio(bbio, bbio->bio.bi_private); + if (bio_op(bio) == REQ_OP_READ && !(bio->bi_opf & REQ_META)) { + btrfs_check_read_bio(bbio, dev); + } else { + if (bio_op(bio) == REQ_OP_ZONE_APPEND) + btrfs_record_physical_zoned(bbio); + btrfs_orig_bbio_end_io(bbio); + } } static void btrfs_simple_end_io(struct bio *bio) @@ -322,18 +335,19 @@ static void btrfs_simple_end_io(struct bio *bio) struct btrfs_device *dev = bio->bi_private; btrfs_bio_counter_dec(bbio->inode->root->fs_info); - if (bio->bi_status) btrfs_log_dev_io_error(bio, dev); - if (bio_op(bio) == REQ_OP_READ) { - INIT_WORK(&bbio->end_io_work, btrfs_end_bio_work); - queue_work(btrfs_end_io_wq(bbio), &bbio->end_io_work); - } else { - if (bio_op(bio) == REQ_OP_ZONE_APPEND) - btrfs_record_physical_zoned(bbio); - btrfs_orig_bbio_end_io(bbio); - } + INIT_WORK(&bbio->end_io_work, btrfs_simple_end_bio_work); + queue_work(btrfs_end_io_wq(bbio), &bbio->end_io_work); +} + +static void btrfs_write_end_bio_work(struct work_struct *work) +{ + struct btrfs_bio *bbio = + container_of(work, struct btrfs_bio, end_io_work); + + btrfs_orig_bbio_end_io(bbio); } static void btrfs_raid56_end_io(struct bio *bio) @@ -343,12 +357,23 @@ static void btrfs_raid56_end_io(struct bio *bio) btrfs_bio_counter_dec(bioc->fs_info); bbio->mirror_num = bioc->mirror_num; - if (bio_op(bio) == REQ_OP_READ && !(bbio->bio.bi_opf & REQ_META)) - btrfs_check_read_bio(bbio, NULL); - else - btrfs_orig_bbio_end_io(bbio); - btrfs_put_bioc(bioc); + + /* + * The RAID5/6 code already completes all bios from workqueues, but for + * writs we need to offload them again to avoid deadlocks in the ordered + * extent processing. + */ + if (bio_op(bio) == REQ_OP_READ) { + /* Metadata reads are checked and repaired by the submitter. */ + if (!(bio->bi_opf & REQ_META)) + btrfs_check_read_bio(bbio, NULL); + else + btrfs_orig_bbio_end_io(bbio); + } else { + INIT_WORK(&btrfs_bio(bio)->end_io_work, btrfs_write_end_bio_work); + queue_work(btrfs_end_io_wq(bbio), &bbio->end_io_work); + } } static void btrfs_orig_write_end_io(struct bio *bio) @@ -372,9 +397,10 @@ static void btrfs_orig_write_end_io(struct bio *bio) bio->bi_status = BLK_STS_IOERR; else bio->bi_status = BLK_STS_OK; - - btrfs_orig_bbio_end_io(bbio); btrfs_put_bioc(bioc); + + INIT_WORK(&bbio->end_io_work, btrfs_write_end_bio_work); + queue_work(btrfs_end_io_wq(bbio), &bbio->end_io_work); } static void btrfs_clone_write_end_io(struct bio *bio) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 0889eb81e71a7d..5b63a5161cedea 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2008,6 +2008,8 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) * the queues used for metadata I/O, since tasks from those other work * queues can do metadata I/O operations. */ + if (fs_info->endio_write_meta_workers) + destroy_workqueue(fs_info->endio_write_meta_workers); if (fs_info->endio_meta_workers) destroy_workqueue(fs_info->endio_meta_workers); } @@ -2204,6 +2206,8 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info) alloc_workqueue("btrfs-endio", flags, max_active); fs_info->endio_meta_workers = alloc_workqueue("btrfs-endio-meta", flags, max_active); + fs_info->endio_write_meta_workers = + alloc_workqueue("btrfs-endio-write-meta", flags, max_active); fs_info->rmw_workers = alloc_workqueue("btrfs-rmw", flags, max_active); fs_info->endio_write_workers = alloc_workqueue("btrfs-endio-write", flags, max_active); @@ -2224,6 +2228,7 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info) fs_info->endio_workers && fs_info->endio_meta_workers && fs_info->compressed_write_workers && fs_info->endio_write_workers && + fs_info->endio_write_meta_workers && fs_info->endio_freespace_worker && fs_info->rmw_workers && fs_info->caching_workers && fs_info->fixup_workers && fs_info->delayed_workers && fs_info->qgroup_rescan_workers && diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index 276a17780f2b1b..e2643bc5c039ad 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -543,6 +543,7 @@ struct btrfs_fs_info { struct workqueue_struct *rmw_workers; struct workqueue_struct *compressed_write_workers; struct workqueue_struct *endio_write_workers; + struct workqueue_struct *endio_write_meta_workers; struct workqueue_struct *endio_freespace_worker; struct btrfs_workqueue *caching_workers; diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index 23f496f0d7b776..48c7510df80a0d 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -303,14 +303,6 @@ void btrfs_add_ordered_sum(struct btrfs_ordered_extent *entry, spin_unlock_irq(&tree->lock); } -static void finish_ordered_fn(struct work_struct *work) -{ - struct btrfs_ordered_extent *ordered_extent; - - ordered_extent = container_of(work, struct btrfs_ordered_extent, work); - btrfs_finish_ordered_io(ordered_extent); -} - /* * Mark all ordered extents io inside the specified range finished. * @@ -330,17 +322,11 @@ void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode, { struct btrfs_ordered_inode_tree *tree = &inode->ordered_tree; struct btrfs_fs_info *fs_info = inode->root->fs_info; - struct workqueue_struct *wq; struct rb_node *node; struct btrfs_ordered_extent *entry = NULL; unsigned long flags; u64 cur = file_offset; - if (btrfs_is_free_space_inode(inode)) - wq = fs_info->endio_freespace_worker; - else - wq = fs_info->endio_write_workers; - if (page) ASSERT(page->mapping && page_offset(page) <= file_offset && file_offset + num_bytes <= page_offset(page) + PAGE_SIZE); @@ -439,8 +425,7 @@ void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode, refcount_inc(&entry->refs); trace_btrfs_ordered_extent_mark_finished(inode, entry); spin_unlock_irqrestore(&tree->lock, flags); - INIT_WORK(&entry->work, finish_ordered_fn); - queue_work(wq, &entry->work); + btrfs_finish_ordered_io(entry); spin_lock_irqsave(&tree->lock, flags); } cur += len; diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index b8a92f040458f0..64a37d42e7a24a 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h @@ -146,8 +146,6 @@ struct btrfs_ordered_extent { /* a per root list of all the pending ordered extents */ struct list_head root_extent_list; - struct work_struct work; - struct completion completion; struct btrfs_work flush_work; struct list_head work_list; From patchwork Tue Mar 14 16:59:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13174786 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 038EDC05027 for ; Tue, 14 Mar 2023 16:59:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230155AbjCNQ7i (ORCPT ); Tue, 14 Mar 2023 12:59:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbjCNQ7g (ORCPT ); Tue, 14 Mar 2023 12:59:36 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 730F88F500 for ; Tue, 14 Mar 2023 09:59:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=IRZWLv3n0s33lS4WUFwIdnCW+lb7UEVkTs0toqJiIiY=; b=EsQOloc+cpRNcfwEjMUxtCvGz1 +hTeG41V+9xlugenYkDxFvhMpK3xxaDUYDdQFBqJ3H+1dqpPop1t2wAmBqoNqRxHk9t8uqlnHAhUb MbElcJGVuDJIhRLZuvXA+22p8+p+EDGGtUu2Qxyu5rWjXtKkJkA9RUupmDJf1UQLiFdjl/WPBJIZc wF0qnxEtNPOsvPIZ3V3Zs1iPhiBHBOsPQ4CqgfDjA3+qKeWCLEPHgSB0f9yNj97u60ZgJZI0K36fU y4NlOtCKQqSVxyvogjRYR6v4YFzJFREYQNnizGw36Pl/oc76vNNWqVpxYmFXwhscgjyuHeaJ1oHzw UnL7xksA==; Received: from [2001:4bb8:182:2e36:91ea:d0e2:233a:8356] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pc7zo-00Avnj-0O; Tue, 14 Mar 2023 16:59:32 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org Subject: [PATCH 04/10] btrfs: remove the compressed_write_workers workqueue Date: Tue, 14 Mar 2023 17:59:04 +0100 Message-Id: <20230314165910.373347-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314165910.373347-1-hch@lst.de> References: <20230314165910.373347-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that all writes completions happen in workqueues, there is no need for an extra offload for compressed write completions. Signed-off-by: Christoph Hellwig --- fs/btrfs/compression.c | 34 ++++++++++------------------------ fs/btrfs/compression.h | 7 ++----- fs/btrfs/disk-io.c | 5 ----- fs/btrfs/fs.h | 1 - 4 files changed, 12 insertions(+), 35 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index c5839d04690d67..1641336a39d215 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -220,27 +220,6 @@ static noinline void end_compressed_writeback(const struct compressed_bio *cb) /* the inode may be gone now */ } -static void btrfs_finish_compressed_write_work(struct work_struct *work) -{ - struct compressed_bio *cb = - container_of(work, struct compressed_bio, write_end_work); - - /* - * Ok, we're the last bio for this extent, step one is to call back - * into the FS and do all the end_io operations. - */ - btrfs_writepage_endio_finish_ordered(cb->bbio.inode, NULL, - cb->start, cb->start + cb->len - 1, - cb->bbio.bio.bi_status == BLK_STS_OK); - - if (cb->writeback) - end_compressed_writeback(cb); - /* Note, our inode could be gone now */ - - btrfs_free_compressed_pages(cb); - bio_put(&cb->bbio.bio); -} - /* * Do the cleanup once all the compressed pages hit the disk. This will clear * writeback on the file pages and free the compressed pages. @@ -251,9 +230,17 @@ static void btrfs_finish_compressed_write_work(struct work_struct *work) static void end_compressed_bio_write(struct btrfs_bio *bbio) { struct compressed_bio *cb = to_compressed_bio(bbio); - struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info; - queue_work(fs_info->compressed_write_workers, &cb->write_end_work); + btrfs_writepage_endio_finish_ordered(cb->bbio.inode, NULL, + cb->start, cb->start + cb->len - 1, + cb->bbio.bio.bi_status == BLK_STS_OK); + + if (cb->writeback) + end_compressed_writeback(cb); + /* Note, our inode could be gone now */ + + btrfs_free_compressed_pages(cb); + bio_put(&bbio->bio); } static void btrfs_add_compressed_bio_pages(struct compressed_bio *cb, @@ -329,7 +316,6 @@ void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start, cb->compressed_pages = compressed_pages; cb->compressed_len = compressed_len; cb->writeback = writeback; - INIT_WORK(&cb->write_end_work, btrfs_finish_compressed_write_work); cb->nr_pages = nr_pages; btrfs_add_compressed_bio_pages(cb, disk_start); diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 5d5146e72a860b..65aaedba35a2ad 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -53,11 +53,8 @@ struct compressed_bio { /* Whether this is a write for writeback. */ bool writeback; - union { - /* For reads, this is the bio we are copying the data into */ - struct btrfs_bio *orig_bbio; - struct work_struct write_end_work; - }; + /* For reads, this is the bio we are copying the data into */ + struct btrfs_bio *orig_bbio; /* Must be last. */ struct btrfs_bio bbio; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 5b63a5161cedea..494081dda5fc66 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1991,8 +1991,6 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) destroy_workqueue(fs_info->endio_workers); if (fs_info->rmw_workers) destroy_workqueue(fs_info->rmw_workers); - if (fs_info->compressed_write_workers) - destroy_workqueue(fs_info->compressed_write_workers); if (fs_info->endio_write_workers) destroy_workqueue(fs_info->endio_write_workers); if (fs_info->endio_freespace_worker) @@ -2211,8 +2209,6 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info) fs_info->rmw_workers = alloc_workqueue("btrfs-rmw", flags, max_active); fs_info->endio_write_workers = alloc_workqueue("btrfs-endio-write", flags, max_active); - fs_info->compressed_write_workers = - alloc_workqueue("btrfs-compressed-write", flags, max_active); fs_info->endio_freespace_worker = alloc_workqueue("btrfs-freespace-write", flags, max_active); fs_info->delayed_workers = @@ -2226,7 +2222,6 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info) if (!(fs_info->workers && fs_info->hipri_workers && fs_info->delalloc_workers && fs_info->flush_workers && fs_info->endio_workers && fs_info->endio_meta_workers && - fs_info->compressed_write_workers && fs_info->endio_write_workers && fs_info->endio_write_meta_workers && fs_info->endio_freespace_worker && fs_info->rmw_workers && diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index e2643bc5c039ad..d926a337d2be20 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -541,7 +541,6 @@ struct btrfs_fs_info { struct workqueue_struct *endio_workers; struct workqueue_struct *endio_meta_workers; struct workqueue_struct *rmw_workers; - struct workqueue_struct *compressed_write_workers; struct workqueue_struct *endio_write_workers; struct workqueue_struct *endio_write_meta_workers; struct workqueue_struct *endio_freespace_worker; From patchwork Tue Mar 14 16:59:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13174787 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03F81C6FD1F for ; Tue, 14 Mar 2023 16:59:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229734AbjCNQ7p (ORCPT ); Tue, 14 Mar 2023 12:59:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229675AbjCNQ7n (ORCPT ); Tue, 14 Mar 2023 12:59:43 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 136079CFE4 for ; Tue, 14 Mar 2023 09:59:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=HqZMJ7pJ8tE8ru4VSLxwj2oeVhU4JPUFstfsVphke0k=; b=SQDOWXwC8cVgFAaaJxaDRKW3Tt O0rrvkyPwqK5jRzKITzvfZWoOlIE4yv6rBwV/tYdS9Xqf0ExKWRLkH08lHwzdRczvVYjBOh4GMC6W 7w40Zg2FNfD4nGW9dfxQsMG1UkVgATEgU8oMT3MICJkcWKc8yOZMRDHh7feL/ywd0PuiBeNm1Sxci kMgmfMZoq5WhCwplcVPuwD3absHSP4O5MB4oCMdiG5GxsieVd7tPpK+U0W/haR61SS/CIYsXcLtVO wMpgzJIVknHkcpKjFVBr7Sjd9tLK+9tB52EvB1DHXIaFeH2ZSLQjsBQiWxzbHTwaoQDjTwj/C7Ay+ U6/vOBDQ==; Received: from [2001:4bb8:182:2e36:91ea:d0e2:233a:8356] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pc7zu-00Avov-0M; Tue, 14 Mar 2023 16:59:39 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org Subject: [PATCH 05/10] btrfs: remove irq disabling for btrfs_workqueue.list_lock Date: Tue, 14 Mar 2023 17:59:05 +0100 Message-Id: <20230314165910.373347-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314165910.373347-1-hch@lst.de> References: <20230314165910.373347-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_queue_work with an ordered_func is never called from irq context, so remove the irq disabling for btrfs_workqueue.list_lock. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/async-thread.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c index aac240430efe13..91ec1e2fea0c69 100644 --- a/fs/btrfs/async-thread.c +++ b/fs/btrfs/async-thread.c @@ -179,11 +179,10 @@ static void run_ordered_work(struct btrfs_workqueue *wq, struct list_head *list = &wq->ordered_list; struct btrfs_work *work; spinlock_t *lock = &wq->list_lock; - unsigned long flags; bool free_self = false; while (1) { - spin_lock_irqsave(lock, flags); + spin_lock(lock); if (list_empty(list)) break; work = list_entry(list->next, struct btrfs_work, @@ -207,13 +206,13 @@ static void run_ordered_work(struct btrfs_workqueue *wq, if (test_and_set_bit(WORK_ORDER_DONE_BIT, &work->flags)) break; trace_btrfs_ordered_sched(work); - spin_unlock_irqrestore(lock, flags); + spin_unlock(lock); work->ordered_func(work); /* now take the lock again and drop our item from the list */ - spin_lock_irqsave(lock, flags); + spin_lock(lock); list_del(&work->ordered_list); - spin_unlock_irqrestore(lock, flags); + spin_unlock(lock); if (work == self) { /* @@ -248,7 +247,7 @@ static void run_ordered_work(struct btrfs_workqueue *wq, trace_btrfs_all_work_done(wq->fs_info, work); } } - spin_unlock_irqrestore(lock, flags); + spin_unlock(lock); if (free_self) { self->ordered_free(self); @@ -307,14 +306,12 @@ void btrfs_init_work(struct btrfs_work *work, btrfs_func_t func, void btrfs_queue_work(struct btrfs_workqueue *wq, struct btrfs_work *work) { - unsigned long flags; - work->wq = wq; thresh_queue_hook(wq); if (work->ordered_func) { - spin_lock_irqsave(&wq->list_lock, flags); + spin_lock(&wq->list_lock); list_add_tail(&work->ordered_list, &wq->ordered_list); - spin_unlock_irqrestore(&wq->list_lock, flags); + spin_unlock(&wq->list_lock); } trace_btrfs_work_queued(work); queue_work(wq->normal_wq, &work->normal_work); From patchwork Tue Mar 14 16:59:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13174788 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4433AC7618A for ; Tue, 14 Mar 2023 16:59:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbjCNQ7t (ORCPT ); Tue, 14 Mar 2023 12:59:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbjCNQ7r (ORCPT ); Tue, 14 Mar 2023 12:59:47 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2D6D8480C for ; Tue, 14 Mar 2023 09:59:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=F3Ldg6G7ZZxZJ1IdTC0e6dwfRrkKRcaIfLMWejjX3SQ=; b=fa3coABEPDjLa/qifjt37cTshd KZZjYLclRnFVGVhcdtC8+zfhHqEhkDRV1uInAYF9KhDIhqQVLHBWHWfhULFEv2sxLYtr0D3bpPIHk ZG8GuI8KcMc/Gw3WYxUPT1lLE+EsgqfiHZ2x2hwa+CjZ/RSwEiC2tF3U4xNOeZM7Y+/xXHfA5x84Q 5yfy6XgBpC4nAlWPNoVqwUT8svJr6khFmT89s2kVzJ80agnUiQJtv8aj7Hs+qCpOvg6ienUJDWNwe 7tuQtTR4lMz82KPV6ROPNp3L2n2xsrli5TV7Xzc3RfYmfVEz1defJV6tYD/w4OumQI4LpQ4jjpnu4 pq4Zjrtg==; Received: from [2001:4bb8:182:2e36:91ea:d0e2:233a:8356] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pc7zy-00AvqF-3C; Tue, 14 Mar 2023 16:59:43 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org Subject: [PATCH 06/10] btrfs: remove irq disabling for subpage.list_lock Date: Tue, 14 Mar 2023 17:59:06 +0100 Message-Id: <20230314165910.373347-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314165910.373347-1-hch@lst.de> References: <20230314165910.373347-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Subpage state isn't modified from irq context any more, so remove the irq disabling. Signed-off-by: Christoph Hellwig --- fs/btrfs/disk-io.c | 7 ++--- fs/btrfs/extent_io.c | 12 ++++---- fs/btrfs/inode.c | 4 +-- fs/btrfs/subpage.c | 65 ++++++++++++++++++-------------------------- 4 files changed, 36 insertions(+), 52 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 494081dda5fc66..638eed9023492e 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -789,17 +789,16 @@ static bool btree_dirty_folio(struct address_space *mapping, ASSERT(subpage->dirty_bitmap); while (cur_bit < BTRFS_SUBPAGE_BITMAP_SIZE) { - unsigned long flags; u64 cur; u16 tmp = (1 << cur_bit); - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); if (!(tmp & subpage->dirty_bitmap)) { - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); cur_bit++; continue; } - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); cur = page_start + cur_bit * fs_info->sectorsize; eb = find_extent_buffer(fs_info, cur); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 1221f699ffc596..b0f74c741aa7a9 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -1385,7 +1385,6 @@ static void find_next_dirty_byte(struct btrfs_fs_info *fs_info, struct btrfs_subpage_info *spi = fs_info->subpage_info; u64 orig_start = *start; /* Declare as unsigned long so we can use bitmap ops */ - unsigned long flags; int range_start_bit; int range_end_bit; @@ -1403,10 +1402,10 @@ static void find_next_dirty_byte(struct btrfs_fs_info *fs_info, (offset_in_page(orig_start) >> fs_info->sectorsize_bits); /* We should have the page locked, but just in case */ - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); bitmap_next_set_region(subpage->bitmaps, &range_start_bit, &range_end_bit, spi->dirty_offset + spi->bitmap_nr_bits); - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); range_start_bit -= spi->dirty_offset; range_end_bit -= spi->dirty_offset; @@ -2080,7 +2079,6 @@ static int submit_eb_subpage(struct page *page, struct btrfs_bio_ctrl *bio_ctrl) while (bit_start < fs_info->subpage_info->bitmap_nr_bits) { struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private; struct extent_buffer *eb; - unsigned long flags; u64 start; /* @@ -2092,10 +2090,10 @@ static int submit_eb_subpage(struct page *page, struct btrfs_bio_ctrl *bio_ctrl) spin_unlock(&page->mapping->private_lock); break; } - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); if (!test_bit(bit_start + fs_info->subpage_info->dirty_offset, subpage->bitmaps)) { - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); spin_unlock(&page->mapping->private_lock); bit_start++; continue; @@ -2109,7 +2107,7 @@ static int submit_eb_subpage(struct page *page, struct btrfs_bio_ctrl *bio_ctrl) * spin locks, so call find_extent_buffer_nolock(). */ eb = find_extent_buffer_nolock(fs_info, start); - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); spin_unlock(&page->mapping->private_lock); /* diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 33f0ec14703a3d..cccaab4aa9cd91 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7900,8 +7900,8 @@ static void wait_subpage_spinlock(struct page *page) * Here we just acquire the spinlock so that all existing callers * should exit and we're safe to release/invalidate the page. */ - spin_lock_irq(&subpage->lock); - spin_unlock_irq(&subpage->lock); + spin_lock(&subpage->lock); + spin_unlock(&subpage->lock); } static bool __btrfs_release_folio(struct folio *folio, gfp_t gfp_flags) diff --git a/fs/btrfs/subpage.c b/fs/btrfs/subpage.c index dd46b978ac2cfc..3a47aeed419503 100644 --- a/fs/btrfs/subpage.c +++ b/fs/btrfs/subpage.c @@ -415,13 +415,12 @@ void btrfs_subpage_set_uptodate(const struct btrfs_fs_info *fs_info, struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private; unsigned int start_bit = subpage_calc_start_bit(fs_info, page, uptodate, start, len); - unsigned long flags; - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); bitmap_set(subpage->bitmaps, start_bit, len >> fs_info->sectorsize_bits); if (subpage_test_bitmap_all_set(fs_info, subpage, uptodate)) SetPageUptodate(page); - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); } void btrfs_subpage_clear_uptodate(const struct btrfs_fs_info *fs_info, @@ -430,12 +429,11 @@ void btrfs_subpage_clear_uptodate(const struct btrfs_fs_info *fs_info, struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private; unsigned int start_bit = subpage_calc_start_bit(fs_info, page, uptodate, start, len); - unsigned long flags; - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); bitmap_clear(subpage->bitmaps, start_bit, len >> fs_info->sectorsize_bits); ClearPageUptodate(page); - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); } void btrfs_subpage_set_error(const struct btrfs_fs_info *fs_info, @@ -444,12 +442,11 @@ void btrfs_subpage_set_error(const struct btrfs_fs_info *fs_info, struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private; unsigned int start_bit = subpage_calc_start_bit(fs_info, page, error, start, len); - unsigned long flags; - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); bitmap_set(subpage->bitmaps, start_bit, len >> fs_info->sectorsize_bits); SetPageError(page); - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); } void btrfs_subpage_clear_error(const struct btrfs_fs_info *fs_info, @@ -458,13 +455,12 @@ void btrfs_subpage_clear_error(const struct btrfs_fs_info *fs_info, struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private; unsigned int start_bit = subpage_calc_start_bit(fs_info, page, error, start, len); - unsigned long flags; - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); bitmap_clear(subpage->bitmaps, start_bit, len >> fs_info->sectorsize_bits); if (subpage_test_bitmap_all_zero(fs_info, subpage, error)) ClearPageError(page); - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); } void btrfs_subpage_set_dirty(const struct btrfs_fs_info *fs_info, @@ -473,11 +469,10 @@ void btrfs_subpage_set_dirty(const struct btrfs_fs_info *fs_info, struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private; unsigned int start_bit = subpage_calc_start_bit(fs_info, page, dirty, start, len); - unsigned long flags; - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); bitmap_set(subpage->bitmaps, start_bit, len >> fs_info->sectorsize_bits); - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); set_page_dirty(page); } @@ -497,14 +492,13 @@ bool btrfs_subpage_clear_and_test_dirty(const struct btrfs_fs_info *fs_info, struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private; unsigned int start_bit = subpage_calc_start_bit(fs_info, page, dirty, start, len); - unsigned long flags; bool last = false; - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); bitmap_clear(subpage->bitmaps, start_bit, len >> fs_info->sectorsize_bits); if (subpage_test_bitmap_all_zero(fs_info, subpage, dirty)) last = true; - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); return last; } @@ -524,12 +518,11 @@ void btrfs_subpage_set_writeback(const struct btrfs_fs_info *fs_info, struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private; unsigned int start_bit = subpage_calc_start_bit(fs_info, page, writeback, start, len); - unsigned long flags; - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); bitmap_set(subpage->bitmaps, start_bit, len >> fs_info->sectorsize_bits); set_page_writeback(page); - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); } void btrfs_subpage_clear_writeback(const struct btrfs_fs_info *fs_info, @@ -538,15 +531,14 @@ void btrfs_subpage_clear_writeback(const struct btrfs_fs_info *fs_info, struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private; unsigned int start_bit = subpage_calc_start_bit(fs_info, page, writeback, start, len); - unsigned long flags; - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); bitmap_clear(subpage->bitmaps, start_bit, len >> fs_info->sectorsize_bits); if (subpage_test_bitmap_all_zero(fs_info, subpage, writeback)) { ASSERT(PageWriteback(page)); end_page_writeback(page); } - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); } void btrfs_subpage_set_ordered(const struct btrfs_fs_info *fs_info, @@ -555,12 +547,11 @@ void btrfs_subpage_set_ordered(const struct btrfs_fs_info *fs_info, struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private; unsigned int start_bit = subpage_calc_start_bit(fs_info, page, ordered, start, len); - unsigned long flags; - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); bitmap_set(subpage->bitmaps, start_bit, len >> fs_info->sectorsize_bits); SetPageOrdered(page); - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); } void btrfs_subpage_clear_ordered(const struct btrfs_fs_info *fs_info, @@ -569,13 +560,12 @@ void btrfs_subpage_clear_ordered(const struct btrfs_fs_info *fs_info, struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private; unsigned int start_bit = subpage_calc_start_bit(fs_info, page, ordered, start, len); - unsigned long flags; - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); bitmap_clear(subpage->bitmaps, start_bit, len >> fs_info->sectorsize_bits); if (subpage_test_bitmap_all_zero(fs_info, subpage, ordered)) ClearPageOrdered(page); - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); } void btrfs_subpage_set_checked(const struct btrfs_fs_info *fs_info, @@ -584,13 +574,12 @@ void btrfs_subpage_set_checked(const struct btrfs_fs_info *fs_info, struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private; unsigned int start_bit = subpage_calc_start_bit(fs_info, page, checked, start, len); - unsigned long flags; - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); bitmap_set(subpage->bitmaps, start_bit, len >> fs_info->sectorsize_bits); if (subpage_test_bitmap_all_set(fs_info, subpage, checked)) SetPageChecked(page); - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); } void btrfs_subpage_clear_checked(const struct btrfs_fs_info *fs_info, @@ -599,12 +588,11 @@ void btrfs_subpage_clear_checked(const struct btrfs_fs_info *fs_info, struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private; unsigned int start_bit = subpage_calc_start_bit(fs_info, page, checked, start, len); - unsigned long flags; - spin_lock_irqsave(&subpage->lock, flags); + spin_lock(&subpage->lock); bitmap_clear(subpage->bitmaps, start_bit, len >> fs_info->sectorsize_bits); ClearPageChecked(page); - spin_unlock_irqrestore(&subpage->lock, flags); + spin_unlock(&subpage->lock); } /* @@ -618,13 +606,12 @@ bool btrfs_subpage_test_##name(const struct btrfs_fs_info *fs_info, \ struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private; \ unsigned int start_bit = subpage_calc_start_bit(fs_info, page, \ name, start, len); \ - unsigned long flags; \ bool ret; \ \ - spin_lock_irqsave(&subpage->lock, flags); \ + spin_lock(&subpage->lock); \ ret = bitmap_test_range_all_set(subpage->bitmaps, start_bit, \ len >> fs_info->sectorsize_bits); \ - spin_unlock_irqrestore(&subpage->lock, flags); \ + spin_unlock(&subpage->lock); \ return ret; \ } IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(uptodate); From patchwork Tue Mar 14 16:59:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13174789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9408BC05027 for ; Tue, 14 Mar 2023 17:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230325AbjCNQ77 (ORCPT ); Tue, 14 Mar 2023 12:59:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230266AbjCNQ7u (ORCPT ); Tue, 14 Mar 2023 12:59:50 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3862D7B11C for ; Tue, 14 Mar 2023 09:59:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=BcjEzbtEYe+Ipj3b+3Rqt252o7K1fZlwoxt8sZ9a1B0=; b=oVzxC0CA2lChOjxLHTIZVWNdZr fhQAU3m2Q6EqrAzJOFJni8JGna2OS75cYkGtIFnOg5LF4dK+piBHL55aebDR1D+1mWkbxRje3mM7R GlJ5l1UluDbeah237xIjxgkYvKk0GX2XiH+LdjyGI4UzSK/WSJqyHTcP6JKmpyxncbIksmn9ovyX5 gaAEMQsPw3XuPT64R7GXJBCBN8nJ1bcGd+MrlfjInoolrACVeGsqRJSNuZmAZw54f08Yq+01u4TMP xvLq9uU0DlJwROTh5ghcSU5YOJYsvtuNM/t9urLaBimv1Ql7DqY5mj8N8JJEavS/U6GaGe0zgTgeC vBvTpiVw==; Received: from [2001:4bb8:182:2e36:91ea:d0e2:233a:8356] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pc802-00Avrf-11; Tue, 14 Mar 2023 16:59:47 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org Subject: [PATCH 07/10] btrfs: remove irq disabling for leak_lock Date: Tue, 14 Mar 2023 17:59:07 +0100 Message-Id: <20230314165910.373347-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314165910.373347-1-hch@lst.de> References: <20230314165910.373347-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org None of the extent state leak tracking is called from irq context, so remove the irq disabling. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/extent-io-tree.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index 29a225836e286e..caf11a10da71a0 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -21,20 +21,16 @@ static DEFINE_SPINLOCK(leak_lock); static inline void btrfs_leak_debug_add_state(struct extent_state *state) { - unsigned long flags; - - spin_lock_irqsave(&leak_lock, flags); + spin_lock(&leak_lock); list_add(&state->leak_list, &states); - spin_unlock_irqrestore(&leak_lock, flags); + spin_unlock(&leak_lock); } static inline void btrfs_leak_debug_del_state(struct extent_state *state) { - unsigned long flags; - - spin_lock_irqsave(&leak_lock, flags); + spin_lock(&leak_lock); list_del(&state->leak_list); - spin_unlock_irqrestore(&leak_lock, flags); + spin_unlock(&leak_lock); } static inline void btrfs_extent_state_leak_debug_check(void) From patchwork Tue Mar 14 16:59:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13174790 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E1D6C6FD1F for ; Tue, 14 Mar 2023 17:00:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231145AbjCNRAA (ORCPT ); Tue, 14 Mar 2023 13:00:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230484AbjCNQ7y (ORCPT ); Tue, 14 Mar 2023 12:59:54 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 650CC7B11C for ; Tue, 14 Mar 2023 09:59:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=o9Kw7bNIJnG6kNx9bMLQaGSLCTJJ+3sDB7djyQZ1PKE=; b=hH0Lbs7UkTEhP4+UjHy1JELShi mOSkRY3ZtSCRBqSTFPU/RWUpnuMCGXyKst+EAa3d159GR1pX5GMZriutmpR6Wm2Wvf8NfO785ZbfC 8L23ChYGxISRRVggMXIqU6WXXQP8XWfnzNFXn9359v79dnX95leOT0z76F/jbzBBLJGXWnAVzm8EZ bD51KPsT8aXpiTpwFkm0H6JW4lmsV0DS/8Gz0BGXENH0MMkgwo3zT/kkleQZ8923rw2waI3ZsFAs4 Z4e9uQAkeS03+E6laNydVVpG0Yj1iK/Z2jy8pFA3hAavkTiISXUiUt5QVj9PWtBCRdW0H7m/KbZbV Cl3sMYCw==; Received: from [2001:4bb8:182:2e36:91ea:d0e2:233a:8356] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pc806-00Avsv-1L; Tue, 14 Mar 2023 16:59:51 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org Subject: [PATCH 08/10] btrfs: remove irq disabling for fs_info.ebleak_lock Date: Tue, 14 Mar 2023 17:59:08 +0100 Message-Id: <20230314165910.373347-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314165910.373347-1-hch@lst.de> References: <20230314165910.373347-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org None of the extent_buffer leak tracking is called from irq context, so remove the irq disabling. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/extent_io.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index b0f74c741aa7a9..8e1ad6d1c7ccca 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -44,27 +44,24 @@ static struct kmem_cache *extent_buffer_cache; static inline void btrfs_leak_debug_add_eb(struct extent_buffer *eb) { struct btrfs_fs_info *fs_info = eb->fs_info; - unsigned long flags; - spin_lock_irqsave(&fs_info->eb_leak_lock, flags); + spin_lock(&fs_info->eb_leak_lock); list_add(&eb->leak_list, &fs_info->allocated_ebs); - spin_unlock_irqrestore(&fs_info->eb_leak_lock, flags); + spin_unlock(&fs_info->eb_leak_lock); } static inline void btrfs_leak_debug_del_eb(struct extent_buffer *eb) { struct btrfs_fs_info *fs_info = eb->fs_info; - unsigned long flags; - spin_lock_irqsave(&fs_info->eb_leak_lock, flags); + spin_lock(&fs_info->eb_leak_lock); list_del(&eb->leak_list); - spin_unlock_irqrestore(&fs_info->eb_leak_lock, flags); + spin_unlock(&fs_info->eb_leak_lock); } void btrfs_extent_buffer_leak_debug_check(struct btrfs_fs_info *fs_info) { struct extent_buffer *eb; - unsigned long flags; /* * If we didn't get into open_ctree our allocated_ebs will not be @@ -74,7 +71,7 @@ void btrfs_extent_buffer_leak_debug_check(struct btrfs_fs_info *fs_info) return; WARN_ON(!list_empty(&fs_info->allocated_ebs)); - spin_lock_irqsave(&fs_info->eb_leak_lock, flags); + spin_lock(&fs_info->eb_leak_lock); while (!list_empty(&fs_info->allocated_ebs)) { eb = list_first_entry(&fs_info->allocated_ebs, struct extent_buffer, leak_list); @@ -85,7 +82,7 @@ void btrfs_extent_buffer_leak_debug_check(struct btrfs_fs_info *fs_info) list_del(&eb->leak_list); kmem_cache_free(extent_buffer_cache, eb); } - spin_unlock_irqrestore(&fs_info->eb_leak_lock, flags); + spin_unlock(&fs_info->eb_leak_lock); } #else #define btrfs_leak_debug_add_eb(eb) do {} while (0) From patchwork Tue Mar 14 16:59:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13174791 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B536C7618A for ; Tue, 14 Mar 2023 17:00:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229853AbjCNRAB (ORCPT ); Tue, 14 Mar 2023 13:00:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231139AbjCNQ77 (ORCPT ); Tue, 14 Mar 2023 12:59:59 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEA2A84815 for ; Tue, 14 Mar 2023 09:59:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=1FWaZ42lR63RfGcScR12OQ6/dDufBLi4LjxtCLWyXHc=; b=DW+kEpKV8LC0lKc8vvu2IB2cn4 +Oqt6CrUTdAqJphBEGUmG1UN0dGhL9T1M/oUR/5/UcL3e4R61VOHPpAh+Q0BHtivg6XvJpZ9K2Jyj y8HW3gyZ5bI4fGd+tn9/b6SzG+mo7Kx6DnXaqZlBbUkxWAWNp0NR7IvqYRd77uDro3pvplk/pntTh LmUQ4Go2lBYSXVP1yt++/Jj4YnUO7r4GLhyKWS98Pc/fs0wfBJ6F9uaR4ukcZxjccORwJq1mIVQky dWCpG0Etg36wuVEztGDljrZzNlKsFlQBjW6gCGhA9NTmUKvMQk3l3s9cd3LF0Yh8L7S+749mr2AEV 1r4lYvBg==; Received: from [2001:4bb8:182:2e36:91ea:d0e2:233a:8356] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pc80A-00Avtl-1c; Tue, 14 Mar 2023 16:59:54 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org Subject: [PATCH 09/10] btrfs: remove irq_disabling for ordered_tree.lock Date: Tue, 14 Mar 2023 17:59:09 +0100 Message-Id: <20230314165910.373347-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314165910.373347-1-hch@lst.de> References: <20230314165910.373347-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The per-inode ordered extent list is not only accessed from process context, so remove the irq disabling. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/inode.c | 4 ++-- fs/btrfs/ordered-data.c | 51 +++++++++++++++++++---------------------- fs/btrfs/tree-log.c | 4 ++-- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index cccaab4aa9cd91..afa564f46c6452 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8050,11 +8050,11 @@ static void btrfs_invalidate_folio(struct folio *folio, size_t offset, EXTENT_LOCKED | EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, &cached_state); - spin_lock_irq(&inode->ordered_tree.lock); + spin_lock(&inode->ordered_tree.lock); set_bit(BTRFS_ORDERED_TRUNCATED, &ordered->flags); ordered->truncated_len = min(ordered->truncated_len, cur - ordered->file_offset); - spin_unlock_irq(&inode->ordered_tree.lock); + spin_unlock(&inode->ordered_tree.lock); /* * If the ordered extent has finished, we're safe to delete all diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index 48c7510df80a0d..4c913d1cf21b1d 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -228,14 +228,14 @@ struct btrfs_ordered_extent *btrfs_alloc_ordered_extent( trace_btrfs_ordered_extent_add(inode, entry); - spin_lock_irq(&tree->lock); + spin_lock(&tree->lock); node = tree_insert(&tree->tree, file_offset, &entry->rb_node); if (node) btrfs_panic(fs_info, -EEXIST, "inconsistency in ordered tree at offset %llu", file_offset); - spin_unlock_irq(&tree->lock); + spin_unlock(&tree->lock); spin_lock(&root->ordered_extent_lock); list_add_tail(&entry->root_extent_list, @@ -298,9 +298,9 @@ void btrfs_add_ordered_sum(struct btrfs_ordered_extent *entry, struct btrfs_ordered_inode_tree *tree; tree = &BTRFS_I(entry->inode)->ordered_tree; - spin_lock_irq(&tree->lock); + spin_lock(&tree->lock); list_add_tail(&sum->list, &entry->list); - spin_unlock_irq(&tree->lock); + spin_unlock(&tree->lock); } /* @@ -324,14 +324,13 @@ void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode, struct btrfs_fs_info *fs_info = inode->root->fs_info; struct rb_node *node; struct btrfs_ordered_extent *entry = NULL; - unsigned long flags; u64 cur = file_offset; if (page) ASSERT(page->mapping && page_offset(page) <= file_offset && file_offset + num_bytes <= page_offset(page) + PAGE_SIZE); - spin_lock_irqsave(&tree->lock, flags); + spin_lock(&tree->lock); while (cur < file_offset + num_bytes) { u64 entry_end; u64 end; @@ -424,13 +423,13 @@ void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode, cond_wake_up(&entry->wait); refcount_inc(&entry->refs); trace_btrfs_ordered_extent_mark_finished(inode, entry); - spin_unlock_irqrestore(&tree->lock, flags); + spin_unlock(&tree->lock); btrfs_finish_ordered_io(entry); - spin_lock_irqsave(&tree->lock, flags); + spin_lock(&tree->lock); } cur += len; } - spin_unlock_irqrestore(&tree->lock, flags); + spin_unlock(&tree->lock); } /* @@ -457,10 +456,9 @@ bool btrfs_dec_test_ordered_pending(struct btrfs_inode *inode, struct btrfs_ordered_inode_tree *tree = &inode->ordered_tree; struct rb_node *node; struct btrfs_ordered_extent *entry = NULL; - unsigned long flags; bool finished = false; - spin_lock_irqsave(&tree->lock, flags); + spin_lock(&tree->lock); if (cached && *cached) { entry = *cached; goto have_entry; @@ -497,7 +495,7 @@ bool btrfs_dec_test_ordered_pending(struct btrfs_inode *inode, refcount_inc(&entry->refs); trace_btrfs_ordered_extent_dec_test_pending(inode, entry); } - spin_unlock_irqrestore(&tree->lock, flags); + spin_unlock(&tree->lock); return finished; } @@ -567,7 +565,7 @@ void btrfs_remove_ordered_extent(struct btrfs_inode *btrfs_inode, fs_info->delalloc_batch); tree = &btrfs_inode->ordered_tree; - spin_lock_irq(&tree->lock); + spin_lock(&tree->lock); node = &entry->rb_node; rb_erase(node, &tree->tree); RB_CLEAR_NODE(node); @@ -575,7 +573,7 @@ void btrfs_remove_ordered_extent(struct btrfs_inode *btrfs_inode, tree->last = NULL; set_bit(BTRFS_ORDERED_COMPLETE, &entry->flags); pending = test_and_clear_bit(BTRFS_ORDERED_PENDING, &entry->flags); - spin_unlock_irq(&tree->lock); + spin_unlock(&tree->lock); /* * The current running transaction is waiting on us, we need to let it @@ -837,10 +835,9 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct btrfs_inode *ino struct btrfs_ordered_inode_tree *tree; struct rb_node *node; struct btrfs_ordered_extent *entry = NULL; - unsigned long flags; tree = &inode->ordered_tree; - spin_lock_irqsave(&tree->lock, flags); + spin_lock(&tree->lock); node = tree_search(tree, file_offset); if (!node) goto out; @@ -853,7 +850,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct btrfs_inode *ino trace_btrfs_ordered_extent_lookup(inode, entry); } out: - spin_unlock_irqrestore(&tree->lock, flags); + spin_unlock(&tree->lock); return entry; } @@ -868,7 +865,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_range( struct btrfs_ordered_extent *entry = NULL; tree = &inode->ordered_tree; - spin_lock_irq(&tree->lock); + spin_lock(&tree->lock); node = tree_search(tree, file_offset); if (!node) { node = tree_search(tree, file_offset + len); @@ -895,7 +892,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_range( refcount_inc(&entry->refs); trace_btrfs_ordered_extent_lookup_range(inode, entry); } - spin_unlock_irq(&tree->lock); + spin_unlock(&tree->lock); return entry; } @@ -911,7 +908,7 @@ void btrfs_get_ordered_extents_for_logging(struct btrfs_inode *inode, ASSERT(inode_is_locked(&inode->vfs_inode)); - spin_lock_irq(&tree->lock); + spin_lock(&tree->lock); for (n = rb_first(&tree->tree); n; n = rb_next(n)) { struct btrfs_ordered_extent *ordered; @@ -925,7 +922,7 @@ void btrfs_get_ordered_extents_for_logging(struct btrfs_inode *inode, refcount_inc(&ordered->refs); trace_btrfs_ordered_extent_lookup_for_logging(inode, ordered); } - spin_unlock_irq(&tree->lock); + spin_unlock(&tree->lock); } /* @@ -940,7 +937,7 @@ btrfs_lookup_first_ordered_extent(struct btrfs_inode *inode, u64 file_offset) struct btrfs_ordered_extent *entry = NULL; tree = &inode->ordered_tree; - spin_lock_irq(&tree->lock); + spin_lock(&tree->lock); node = tree_search(tree, file_offset); if (!node) goto out; @@ -949,7 +946,7 @@ btrfs_lookup_first_ordered_extent(struct btrfs_inode *inode, u64 file_offset) refcount_inc(&entry->refs); trace_btrfs_ordered_extent_lookup_first(inode, entry); out: - spin_unlock_irq(&tree->lock); + spin_unlock(&tree->lock); return entry; } @@ -972,7 +969,7 @@ struct btrfs_ordered_extent *btrfs_lookup_first_ordered_range( struct rb_node *next; struct btrfs_ordered_extent *entry = NULL; - spin_lock_irq(&tree->lock); + spin_lock(&tree->lock); node = tree->tree.rb_node; /* * Here we don't want to use tree_search() which will use tree->last @@ -1027,7 +1024,7 @@ struct btrfs_ordered_extent *btrfs_lookup_first_ordered_range( trace_btrfs_ordered_extent_lookup_first_range(inode, entry); } - spin_unlock_irq(&tree->lock); + spin_unlock(&tree->lock); return entry; } @@ -1134,7 +1131,7 @@ int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre, trace_btrfs_ordered_extent_split(BTRFS_I(inode), ordered); - spin_lock_irq(&tree->lock); + spin_lock(&tree->lock); /* Remove from tree once */ node = &ordered->rb_node; rb_erase(node, &tree->tree); @@ -1155,7 +1152,7 @@ int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pre, "zoned: inconsistency in ordered tree at offset %llu", ordered->file_offset); - spin_unlock_irq(&tree->lock); + spin_unlock(&tree->lock); if (pre) ret = clone_ordered_extent(ordered, 0, pre); diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 9ab793b638a7b9..8cb0b700bf535b 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -4950,12 +4950,12 @@ static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans, set_bit(BTRFS_ORDERED_LOGGED, &ordered->flags); if (!test_bit(BTRFS_ORDERED_COMPLETE, &ordered->flags)) { - spin_lock_irq(&inode->ordered_tree.lock); + spin_lock(&inode->ordered_tree.lock); if (!test_bit(BTRFS_ORDERED_COMPLETE, &ordered->flags)) { set_bit(BTRFS_ORDERED_PENDING, &ordered->flags); atomic_inc(&trans->transaction->pending_ordered); } - spin_unlock_irq(&inode->ordered_tree.lock); + spin_unlock(&inode->ordered_tree.lock); } btrfs_put_ordered_extent(ordered); } From patchwork Tue Mar 14 16:59:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13174792 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9C28C6FD1F for ; Tue, 14 Mar 2023 17:00:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230174AbjCNRAE (ORCPT ); Tue, 14 Mar 2023 13:00:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbjCNRAD (ORCPT ); Tue, 14 Mar 2023 13:00:03 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1780A02A7 for ; Tue, 14 Mar 2023 10:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=QyRndG+zkZ6ZZX/US0MinBnC97PmMnphDiTJKayrtHU=; b=jJuJAKllta3tVSW2vPsHxeQ2X3 S3RqZkQzOfI8eQkUBuHG8wSxHK81axTUf4aQHZ8JZFB/bdABsTihPIKTDgaSOKlgwUmZtAyT7chCN tX3a/cpDS5k861yfIXusN4uH+UQpOVWwtYPCtNkqF27FxjUy7qeUOcOqYB78J7+o6YVl6edRPk3+Y P5y5x8UvTfqSUbjG6rm69axYRKDMyZ6mmbr8IHcMhhfYwTl4DY6s0edtS7MPIR5lrouZNBXoSqSh5 imbf2oTVVqPkTB/FKTfOJ/hOSdcXwNOttDTXBMmZAQie0X4kXkkT9tk3wC4GRZxXDBs4jlvafcHNn /JfK8Ekg==; Received: from [2001:4bb8:182:2e36:91ea:d0e2:233a:8356] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pc80F-00Avuh-0M; Tue, 14 Mar 2023 17:00:00 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org Subject: [PATCH 10/10] btrfs: remove confusing comments Date: Tue, 14 Mar 2023 17:59:10 +0100 Message-Id: <20230314165910.373347-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314165910.373347-1-hch@lst.de> References: <20230314165910.373347-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org As far as I can tell there is no such thing as set_bit and test_bit hooks, and there also isn't any irq disabling near the data structures used here. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/inode.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index afa564f46c6452..e26ba7104c2b2a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2402,11 +2402,7 @@ void btrfs_set_delalloc_extent(struct btrfs_inode *inode, struct extent_state *s if ((bits & EXTENT_DEFRAG) && !(bits & EXTENT_DELALLOC)) WARN_ON(1); - /* - * set_bit and clear bit hooks normally require _irqsave/restore - * but in this case, we are only testing for the DELALLOC - * bit, which is only set or cleared with irqs on - */ + if (!(state->state & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { struct btrfs_root *root = inode->root; u64 len = state->end + 1 - state->start; @@ -2458,11 +2454,6 @@ void btrfs_clear_delalloc_extent(struct btrfs_inode *inode, spin_unlock(&inode->lock); } - /* - * set_bit and clear bit hooks normally require _irqsave/restore - * but in this case, we are only testing for the DELALLOC - * bit, which is only set or cleared with irqs on - */ if ((state->state & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { struct btrfs_root *root = inode->root; bool do_list = !btrfs_is_free_space_inode(inode);