From patchwork Wed Dec 7 22:28:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13067714 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 1119EC63708 for ; Wed, 7 Dec 2022 22:28:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229662AbiLGW2T (ORCPT ); Wed, 7 Dec 2022 17:28:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbiLGW2R (ORCPT ); Wed, 7 Dec 2022 17:28:17 -0500 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4EB854762 for ; Wed, 7 Dec 2022 14:28:16 -0800 (PST) Received: by mail-qt1-x834.google.com with SMTP id a16so2206382qtw.10 for ; Wed, 07 Dec 2022 14:28:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=HwdnYcIiWi7wHi2bXU/Fk7/olRy/K+ncT86VsG5nZ9o=; b=rXWQYi0/l1e9oDvb0YhtJsffigGqAs1c1dqEZ4WmH+llMZOWFxl1wo3CiT5JChFpA2 lHP/SwLscUjkE9iMkfTa9uxg0fRCDiNO1qFIYWyFChbR0kqtM53REEIPLzE21jtN+kFv iXQFLEgzvIP+Y8C+T+QrA29Wt4TRtajS0oc5CgOvFRG1czHQf9qtNp7rFeoZGtB1iX6M 88NuT+8im2ZtNTtZTi5VrmhvPNVha15Xt/3sMyTuDhhnELcpqG2QR5wH6xNeFKxk2Gf3 +j6CRAvnBA30ZjFP/JGZZ1evSMIbxVjVYgDD5gksUUkUrRLieP36lRDvowgC1+jwxaca BbSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HwdnYcIiWi7wHi2bXU/Fk7/olRy/K+ncT86VsG5nZ9o=; b=ur71kwwKT13sATvcwO78k8dgEZCe12dvAnHh9mjy55fe4icMIXHvMrBpM0OCLnhhSb sfWfH9NmLZpdytOK4TsqIguThKHh0Vc7Zx66iAtTr59U2j7qdxJdGLOXZG/UUMw0isK7 DxpVU5b+hmvlvYShLdFdOLv6amT3FU9adlsgy7GXP9pcRKkEHj0fv2f8Tzaa1HKohltN VwdKFekfoEfxb/p+q84KKOGRXBfClcGfGPOxxcn9QthphZCcIcFfspoinpUiBYRc3yps 87ayIpq8Cq15P6bX0RMg+61LHNyEvy+qAXz/9JSgjB0jVc/56ldc64ptZbCJ5gxmt61q Bf7A== X-Gm-Message-State: ANoB5pnX81UP3FcC8f0YrtJlYN0iiikUFhGQyryNlu8gyF+CBpLqhkqo HrHdPyBV4EIak/D8OBrf6wYmE9jyzhqob5Yt X-Google-Smtp-Source: AA0mqf5+JI1xZ4gy8NdnFrYROfdEWjr6t+BXLZZttDIEvCNePqMiRZgzjNkoyV1uAnvk7iBXG4XIwg== X-Received: by 2002:ac8:7305:0:b0:3a6:9cca:67e4 with SMTP id x5-20020ac87305000000b003a69cca67e4mr1600624qto.60.1670452095896; Wed, 07 Dec 2022 14:28:15 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id j11-20020ac8550b000000b003434d3b5938sm14245048qtq.2.2022.12.07.14.28.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 14:28:15 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 1/8] btrfs: always lock the block before calling btrfs_clean_tree_block Date: Wed, 7 Dec 2022 17:28:04 -0500 Message-Id: <1882118e87ae105bcbc5a94744b98c4b67207567.1670451918.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We want to clean up the dirty handling for extent buffers so it's a little more consistent, so skip the check for generation == transid and simply always lock the extent buffer before calling btrfs_clean_tree_block. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 876bea67f9a1..c85af644e353 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5534,8 +5534,7 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans, } } /* make block locked assertion in btrfs_clean_tree_block happy */ - if (!path->locks[level] && - btrfs_header_generation(eb) == trans->transid) { + if (!path->locks[level]) { btrfs_tree_lock(eb); path->locks[level] = BTRFS_WRITE_LOCK; } From patchwork Wed Dec 7 22:28:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13067715 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 76ADBC63705 for ; Wed, 7 Dec 2022 22:28:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229521AbiLGW2V (ORCPT ); Wed, 7 Dec 2022 17:28:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229623AbiLGW2U (ORCPT ); Wed, 7 Dec 2022 17:28:20 -0500 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5BFA42F64 for ; Wed, 7 Dec 2022 14:28:18 -0800 (PST) Received: by mail-qt1-x82f.google.com with SMTP id j16so1910493qtv.4 for ; Wed, 07 Dec 2022 14:28:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=lXIbIDcurwlxm0mOrA0RAfX0zhSSMBXnUrjrgo+hop8=; b=0pgFRIoYBSqioedMltu9EIkN99bxKw/eYviQT6Bg5tHGf1QpyytKofpdKE4EDyn0qK AgXASfYfj/RZtygC/qCUBuODM4Kzd1zBgENnJy9jzIdiPpw2Ys/ETqc424EDBgLoiOAV 0xDqBahRmMBsCyBE0FAyD8j7L+cfduV0uNjabmb72xB77Y9mfYsnYu8vZSjNb67L6wdh PpHP18oNM7RlOdRLuGIrRTvglOSBC57Pl2grEZBIJ8It1/aKUf0am0O5Vzvd3X8zi32D /ZpZVpLVAd0c4OHsuw5X9lQiR1DbGtRXxJ0DiuofTlkKkEInYCwKkQ5KVxNhxMsT5iPr jgQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lXIbIDcurwlxm0mOrA0RAfX0zhSSMBXnUrjrgo+hop8=; b=OBVR/dI4CsK0wwn3FGgMOGm9+F5206Rjkafvxc7tyUhgtQIIEE328WlJnIn+vp8UIH DYaGW44J+SzQYtAVCbduAwYcyQ5nPNC0vCUFZPBlkWI8qC8C3R3aXEPwIsggAPeKJ/1Y 5RwyIeEkDTsv3GGqGXt75vNzL5c6Xlb2f5gscKmOwTPPX3UwgC1uqFR2N9qjvM64wR2f dcA0se0B3vQeYkIFZdPGoR/8lqV50M30IHc9cH9JH/NQu66a/oL5dCMATS8lfwD9EReM KlIc7AdRd2WsAJqA1dEs7o51WFGb9JR0rQussCD7TXZXPy8bAWaz3cXStFtm1xYJiJuR lGxQ== X-Gm-Message-State: ANoB5pmbIZU57Ju+EJKVOhGB44AVKUmGi+S7uxOZBbJEgdbwyiLo0BqZ DG8DcIJQ1IWJja6XuEicoQRRvwHvitBr37CE X-Google-Smtp-Source: AA0mqf7/p4bwGtozlC+z46VvyIFtFMUpBT+RfV2rTNiZNv1sn7iQBbEDa8c0Yv/T0tc7lfHuE4JaLA== X-Received: by 2002:ac8:1481:0:b0:3a7:f091:bf3 with SMTP id l1-20020ac81481000000b003a7f0910bf3mr1392259qtj.59.1670452097424; Wed, 07 Dec 2022 14:28:17 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id d136-20020ae9ef8e000000b006bbc3724affsm881756qkg.45.2022.12.07.14.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 14:28:16 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 2/8] btrfs: do not check header generation in btrfs_clean_tree_block Date: Wed, 7 Dec 2022 17:28:05 -0500 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This check is from an era where we didn't have a per-extent buffer dirty flag, we just messed with the page bits. All the places we call this function are when we have a transaction open, so just skip this check and rely on the dirty flag. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index d0ed52cab304..267163e546a5 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -968,16 +968,13 @@ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, void btrfs_clean_tree_block(struct extent_buffer *buf) { struct btrfs_fs_info *fs_info = buf->fs_info; - if (btrfs_header_generation(buf) == - fs_info->running_transaction->transid) { - btrfs_assert_tree_write_locked(buf); + btrfs_assert_tree_write_locked(buf); - if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &buf->bflags)) { - percpu_counter_add_batch(&fs_info->dirty_metadata_bytes, - -buf->len, - fs_info->dirty_metadata_batch); - clear_extent_buffer_dirty(buf); - } + if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &buf->bflags)) { + percpu_counter_add_batch(&fs_info->dirty_metadata_bytes, + -buf->len, + fs_info->dirty_metadata_batch); + clear_extent_buffer_dirty(buf); } } From patchwork Wed Dec 7 22:28:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13067716 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 06DC2C4708D for ; Wed, 7 Dec 2022 22:28:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229623AbiLGW2X (ORCPT ); Wed, 7 Dec 2022 17:28:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbiLGW2U (ORCPT ); Wed, 7 Dec 2022 17:28:20 -0500 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E9AF5B5B1 for ; Wed, 7 Dec 2022 14:28:20 -0800 (PST) Received: by mail-qt1-x82f.google.com with SMTP id y15so17350594qtv.5 for ; Wed, 07 Dec 2022 14:28:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=5W1ynQebnKH4VSeXjmhH7rt8v41FiS+6N7Vz+CoRsSg=; b=gQHaGS82cTcYh0ahrdR0tSL6c24Nwxh+9+OiydTgX4/qe2NM7jcgps29EGS/oQkBrH vQEBxpbFK28BN8dUf9KJb3E+wM5pIeH5H8UkqoZUn1PQ90pk7WgHxK33VtTTv61qRbrC kmT2xDmfTDZWLwnneTuimXP1oaCB6IRORaZfPaeguFegNe2/9NQW/DYuVIxi+nqp3MuT iwOIUXQC3a6Tsxj71k5o/447XdTjTbkT3oEeAdf6wM+NjjKAGsTvt9jbX4jd3I2Uk6VN BfSV3UL11KoulSa29KCclrl5MURXyCCX3otF800u/pVWM7b2CYTtA8rcwyIUr1pSwOoD e8vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5W1ynQebnKH4VSeXjmhH7rt8v41FiS+6N7Vz+CoRsSg=; b=NZtFFzw6qROr7T32qZU6e446ud47RkxmcvP5a+TaQCsVFPxZvr3pUmV480p1gdi90o xurCzEXrjBgNOu3qbeMpnLOjSqeKPMRHQXZ3nzk4ExgTbMDF4xGoi14tp2IWKuCAst+B SPAGjtLqClgmRy7joEtSQew0K29H6UPki+FqiL1LQ+Q/9R7idOGIXxwJZ4Puc5liweJZ wvDrt2eCWqb4mm/+mdr2p1S3opjIqN6NDMDCzwL5xjK7t50Tfxk8tz45L1fG5OIk2b/N DvOYHMb79VN8H0KGmQZQECTB+deODLs66OSa6luV6fcPhDh5x4YMhk62D3s9CEioRvQS hLDA== X-Gm-Message-State: ANoB5pnoDEVLm3KgCh+ZSy0C5taiMGoRLmpx0bpe/CvPXFGJcMrQG0rt 2oYGZLpU1H51WpRnC99g+Kw+bb4U0TImSKl0 X-Google-Smtp-Source: AA0mqf6Jetuy8HMcwtxDNg1OjoIdjBN49iTfXtwHDVfHqhMUNsnpBaz4xjGVR/deh4nQaNmodBVVvw== X-Received: by 2002:a05:622a:a1a:b0:3a7:e426:2892 with SMTP id bv26-20020a05622a0a1a00b003a7e4262892mr1719589qtb.28.1670452098825; Wed, 07 Dec 2022 14:28:18 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id fp38-20020a05622a50a600b00343057845f7sm14047861qtb.20.2022.12.07.14.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 14:28:18 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 3/8] btrfs: do not set the header generation before btrfs_clean_tree_block Date: Wed, 7 Dec 2022 17:28:06 -0500 Message-Id: <8f9b14a270b3e2e9445ece62962a1f7ee3eae555.1670451918.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We were doing this before to deal with possible uninitialized pages which was reported by syzbot. Now that btrfs_clean_tree_block no longer checks the header generation simply remove this extra init. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index c85af644e353..971b1de50d9e 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4897,9 +4897,6 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root, !test_bit(BTRFS_ROOT_RESET_LOCKDEP_CLASS, &root->state)) lockdep_owner = BTRFS_FS_TREE_OBJECTID; - /* btrfs_clean_tree_block() accesses generation field. */ - btrfs_set_header_generation(buf, trans->transid); - /* * This needs to stay, because we could allocate a freed block from an * old tree into a new tree, so we need to make sure this new block is From patchwork Wed Dec 7 22:28:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13067717 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 82C86C63709 for ; Wed, 7 Dec 2022 22:28:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229671AbiLGW2Y (ORCPT ); Wed, 7 Dec 2022 17:28:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229555AbiLGW2X (ORCPT ); Wed, 7 Dec 2022 17:28:23 -0500 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97D805B5B1 for ; Wed, 7 Dec 2022 14:28:21 -0800 (PST) Received: by mail-qt1-x82b.google.com with SMTP id h24so17325140qta.9 for ; Wed, 07 Dec 2022 14:28:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=+YSJn7uUirpjoq/znkENuFvimDFsQD/Dz7Or9p1ebJg=; b=lTaIA1BbscD2meRYe9hzNfERxFK99oPfu7Zfx9vHuHZCTzJEpO57zn76lEUSc3RQQ+ 8qmZnU2xdt0BsHTkob7mGy6FC8h+zjzUo8OKIuHL2XSPgr5EVul+8r9KO118A6SbiAYZ Su3OdkHp7mceSWMFxdaD9+LeckkOY38qXyMYEPOpPH8yI0yQIhjNeTaakXT1zRk14SJZ eqD8g1df7pvxpZJ3QPf/bg4JM9bFjYZfdccnJ2okpftXHtg+hl4VKqYguW+sc4RHOdA4 dr5DF+hC9UvZYbQzO77nbzfbnu6Fc6LbhFBX5fQR8le2OZ6wYQ7zXRbszaudPPpgaoDu 3W9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+YSJn7uUirpjoq/znkENuFvimDFsQD/Dz7Or9p1ebJg=; b=aphtS+3rab96HkUGxXWJY5Wf0ePflpCu9EWRaUWBrXoyFzrb1H29LhO/8NRfTpwe2x X8DrX3a1eHEe9Aw0ARuQU0ykdKcYqQdvfgnole1Yb57hjZrL7O2I+5HTAW+cHUND+6/C SNZ8NcZq8W2L0Awl2UCWmr3WuEb+hFNaGxnaNkVdc/rRWyjbeqK18ElsVHPWbfM0TpoZ ZoXugBqQTCkS3pRu5C3rNVXpi05rGk+8jCLtFQjkzKhlHhTFXDofxy0nhJhsd1p66OjI ZXTVKtbU6XzryYziUCuZ6zGGF11EeXDd5XN2m8SaxarsMVHyO0NYONXKeazz+lY+2fY8 fb8w== X-Gm-Message-State: ANoB5plSKUkPMQYmWE45YdM6JCvQsP7lWS+gYdkXsdkSfPiYwYQZTT22 5RR2fRBas76J4sOpxGujLRkRwcQMb9R5Vz0Q X-Google-Smtp-Source: AA0mqf54XKocSi1cyWnZEq2tqRte/9JKvDdu48ds616S95X0/qtdtIKv5xfcrC/aqkE1M8NfYMpmaA== X-Received: by 2002:a05:622a:114a:b0:3a7:e1db:2fdb with SMTP id f10-20020a05622a114a00b003a7e1db2fdbmr1667417qty.58.1670452100262; Wed, 07 Dec 2022 14:28:20 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id c3-20020ac81e83000000b003a7ec97c882sm3484605qtm.6.2022.12.07.14.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 14:28:19 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 4/8] btrfs: replace clearing extent buffer dirty bit with btrfs_clean_block Date: Wed, 7 Dec 2022 17:28:07 -0500 Message-Id: <814963dbb8e94fdaaa3092d63bead4305377ec2a.1670451918.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that btrfs_clean_block doesn't care about the transid, we can replace all occurrences of if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &eb->bflags)) clear_extent_buffer_dirty(eb); with btrfs_tree_lock(eb); btrfs_clean_tree_block(eb); btrfs_tree_unlock(eb); We need the lock because if we are actually dirty we need to make sure we aren't racing with anything that's starting writeout currently. This also makes sure that we're accounting fs_info->dirty_metadata_bytes appropriately. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 9 +++++---- fs/btrfs/tree-log.c | 34 +++++++++++++++------------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 267163e546a5..275ba1925eeb 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -5074,11 +5074,12 @@ static int btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info, start += fs_info->nodesize; if (!eb) continue; - wait_on_extent_buffer_writeback(eb); - if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, - &eb->bflags)) - clear_extent_buffer_dirty(eb); + btrfs_tree_lock(eb); + wait_on_extent_buffer_writeback(eb); + btrfs_clean_tree_block(eb); + btrfs_tree_unlock(eb); + free_extent_buffer_stale(eb); } } diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 8fcfaf015a70..73e621df32f7 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -2635,11 +2635,12 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans, return ret; } + btrfs_tree_lock(next); + btrfs_clean_tree_block(next); + btrfs_wait_tree_block_writeback(next); + btrfs_tree_unlock(next); + if (trans) { - btrfs_tree_lock(next); - btrfs_clean_tree_block(next); - btrfs_wait_tree_block_writeback(next); - btrfs_tree_unlock(next); ret = btrfs_pin_reserved_extent(trans, bytenr, blocksize); if (ret) { @@ -2649,8 +2650,6 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans, btrfs_redirty_list_add( trans->transaction, next); } else { - if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags)) - clear_extent_buffer_dirty(next); unaccount_log_buffer(fs_info, bytenr); } } @@ -2705,11 +2704,12 @@ static noinline int walk_up_log_tree(struct btrfs_trans_handle *trans, next = path->nodes[*level]; + btrfs_tree_lock(next); + btrfs_clean_tree_block(next); + btrfs_wait_tree_block_writeback(next); + btrfs_tree_unlock(next); + if (trans) { - btrfs_tree_lock(next); - btrfs_clean_tree_block(next); - btrfs_wait_tree_block_writeback(next); - btrfs_tree_unlock(next); ret = btrfs_pin_reserved_extent(trans, path->nodes[*level]->start, path->nodes[*level]->len); @@ -2718,9 +2718,6 @@ static noinline int walk_up_log_tree(struct btrfs_trans_handle *trans, btrfs_redirty_list_add(trans->transaction, next); } else { - if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags)) - clear_extent_buffer_dirty(next); - unaccount_log_buffer(fs_info, path->nodes[*level]->start); } @@ -2788,19 +2785,18 @@ static int walk_log_tree(struct btrfs_trans_handle *trans, next = path->nodes[orig_level]; + btrfs_tree_lock(next); + btrfs_clean_tree_block(next); + btrfs_wait_tree_block_writeback(next); + btrfs_tree_unlock(next); + if (trans) { - btrfs_tree_lock(next); - btrfs_clean_tree_block(next); - btrfs_wait_tree_block_writeback(next); - btrfs_tree_unlock(next); ret = btrfs_pin_reserved_extent(trans, next->start, next->len); if (ret) goto out; btrfs_redirty_list_add(trans->transaction, next); } else { - if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags)) - clear_extent_buffer_dirty(next); unaccount_log_buffer(fs_info, next->start); } } From patchwork Wed Dec 7 22:28:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13067718 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 70DFDC63705 for ; Wed, 7 Dec 2022 22:28:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229441AbiLGW2Z (ORCPT ); Wed, 7 Dec 2022 17:28:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbiLGW2Y (ORCPT ); Wed, 7 Dec 2022 17:28:24 -0500 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0629B42F64 for ; Wed, 7 Dec 2022 14:28:23 -0800 (PST) Received: by mail-qt1-x82f.google.com with SMTP id fu10so8902649qtb.0 for ; Wed, 07 Dec 2022 14:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=/iqMaeL2/3iIa7APep2tYpwUpwF7cWyXv1iyiMsdJsQ=; b=iVzwwZ5LzPqYgYZWpdWK/ropKSLqFrtYKvi19Zb3wGqtcqM58lFZdeVwhlOTjVZ8Qg cKvyUlDOUUysFjX5XFk3BmYWOSaNrib+cdgR+UqAa8FX8MwCv4VRNxqpZuCnKSqJhs/D DeDbkQcxngVDMw4WChr8nNb/PDbFC8ubcsyYtvBUBQe1gp4IIsIi1eTGVgHJ9ucqph/E 8B57wX35UfsuYIDEQi8k0w3kWBuHLTFti1G2pVlaybc4XX8DStJgvWN72wP2LRQDYTRs ZhewHXu+1O0iqrQqCw5idDOA33XEEgmJr4c58JtCwtfW5evoTTDJHVA72zOn33YST2gj 6CUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/iqMaeL2/3iIa7APep2tYpwUpwF7cWyXv1iyiMsdJsQ=; b=4ejJ6TAqmHyLVLS99ywvA2hkgZiLxqbrhoRPH+gEyOx+80oocjQf2MBQ+T7zwzk73l JM1UkC9rKqZGAy/DiL6zE7mtHr8EhaTd920KS+pXIT3t3AuehmPD/wXMNvCX/K0UJhk3 AR5PFJ/h5K8ikO6cP1QmD39xYwH2Rp6c4cOJSlVqoeo4FerMJdckzaPg/s8sHhIL6Hg/ o0bHBVfRrkpEv4PY33/89B1W83s6n8bV5qIPNacGVvMNuIeOBr7QLbJjdtMtr2Mj1CGy cfET8ixtW68RTOlMhcOrja8YU4tC9/ESHljK58jdYO5UgOlgCE0TbPyjVhQ8Et3iS3MQ P3PA== X-Gm-Message-State: ANoB5pmUkXG7GTczP0Iaq/KBnLf34v4AaNz28P1EwSutQVC48ebyUcIL znNi+FBTIXZiyHi7sF5pyl2sjToSt+XZ4MdA X-Google-Smtp-Source: AA0mqf53TIE0iOrRxVoiZUYmL7IczxYBv1i/xf8JNhANaUIg23pmjML3pHG9729c+UP6+hrwMvkRrw== X-Received: by 2002:ac8:5392:0:b0:3a6:a8fb:245c with SMTP id x18-20020ac85392000000b003a6a8fb245cmr1540930qtp.41.1670452101706; Wed, 07 Dec 2022 14:28:21 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id g9-20020ac80709000000b003a7e8ab2972sm4821200qth.23.2022.12.07.14.28.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 14:28:21 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 5/8] btrfs: do not increment dirty_metadata_bytes in set_btree_ioerr Date: Wed, 7 Dec 2022 17:28:08 -0500 Message-Id: <3e7e31ab27e22d2fbc76c9cd44924b8de88f43b5.1670451918.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We only add if we set the extent buffer dirty, and we subtract when we clear the extent buffer dirty. If we end up in set_btree_ioerr we have already cleared the buffer dirty, and we aren't resetting dirty on the extent buffer, so this is simply wrong. Signed-off-by: Josef Bacik --- fs/btrfs/extent_io.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index c87be46e0663..7cd4065acc82 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2467,13 +2467,6 @@ static void set_btree_ioerr(struct page *page, struct extent_buffer *eb) */ mapping_set_error(page->mapping, -EIO); - /* - * If we error out, we should add back the dirty_metadata_bytes - * to make it consistent. - */ - percpu_counter_add_batch(&fs_info->dirty_metadata_bytes, - eb->len, fs_info->dirty_metadata_batch); - /* * If writeback for a btree extent that doesn't belong to a log tree * failed, increment the counter transaction->eb_write_errors. From patchwork Wed Dec 7 22:28:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13067719 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 CD38FC4708D for ; Wed, 7 Dec 2022 22:28:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229683AbiLGW20 (ORCPT ); Wed, 7 Dec 2022 17:28:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbiLGW2Z (ORCPT ); Wed, 7 Dec 2022 17:28:25 -0500 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEF0D813BC for ; Wed, 7 Dec 2022 14:28:24 -0800 (PST) Received: by mail-qt1-x82d.google.com with SMTP id x28so16251884qtv.13 for ; Wed, 07 Dec 2022 14:28:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=GeWfnq8ATp0i8i1q5rnNpghrfwG+ssx26YvVY84F0Ww=; b=UYn0tYDWnD1Hsxx0jxyUaf6M/f1DkS4SON5Y7rHr18L4H8HRUpWT3LlDGOL1fAOzLs 0sguBnj1Ko1wJIj9Rccwk3Pqobx+goYcqKyoh7D/9KYGK1L7W/BbOUAp3CgP7alk9oVH 26+hz8DdlM0+rnfvZnLbI29nLxlSj18BhdX2ZjJ0DhqgT30CTSviHJBxyIp8KderMj/b QXBlYcvi9CloxKuqPD1gVCDPkY/Ke0aEan1MKEdByweGeD+ALzOHGm0jnYaPdrFHA5Wj UN/wA/o149A0fI89VwPBEP8M/CL2v+Mz4q0AS8P8nF9w/nYQFqzScfS+jhNmxiLqSBkm mWFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GeWfnq8ATp0i8i1q5rnNpghrfwG+ssx26YvVY84F0Ww=; b=NMjWxTAxb8raUJQKW/go7PqWBrzwEabRUGyztHb7HWjpt8MPyHkFjd2hyOGI/pNNxe wUhWPPFthILdzhKuLzMXq/Yy39HS+XqlCDO5RrjWGjgMkH9Dlm9Z0mKqdsEe7+FHtOgn 5jzMOmqsvNwUbfkBW57PO2Mt82TsughQTrdRgWUZJSoAzpvhUQxyyYrkvZN7u4zLi2xn +K3BYTxPq4sPjaag/JLw4CWyADssxGc+dSvjhVjYw0Q42mYm6k8Rkcd5UfBWFhEVf7pl /j4v2inTI8n9VaoOupW1FuEf5xtUz6gbD+TvzggPpYhdy1Ix/rBjJIenVmCLzYwTogiY v13A== X-Gm-Message-State: ANoB5plqUQbM1e+oMxthKln5vX70is0fIEKwy4KzGfHmJqKmRxGYBEXe yFSD3/dVq8JW4cQLYFupQZc78X2+sel1vIxO X-Google-Smtp-Source: AA0mqf6K5+pFJd6ornwa8SblI8i9PHuJ0X8igFIr31c22j7LivNzKpPOZ80rY93P5kXlX0SlCD5ORA== X-Received: by 2002:ac8:465a:0:b0:3a6:9f4e:22b5 with SMTP id f26-20020ac8465a000000b003a69f4e22b5mr1731317qto.20.1670452103315; Wed, 07 Dec 2022 14:28:23 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id bm8-20020a05620a198800b006fa8299b4d5sm18189526qkb.100.2022.12.07.14.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 14:28:22 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 6/8] btrfs: rename btrfs_clean_tree_block => btrfs_clear_buffer_dirty Date: Wed, 7 Dec 2022 17:28:09 -0500 Message-Id: <6edcc266202fc9d4b8ccdf5b9ec8ee4887954edc.1670451918.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_clean_tree_block is a misnomer, it's just clear_extent_buffer_dirty with some extra accounting around it. Rename this to btrfs_clear_buffer_dirty to make it more clear it belongs with it's setter, btrfs_mark_buffer_dirty. Signed-off-by: Josef Bacik --- fs/btrfs/ctree.c | 16 ++++++++-------- fs/btrfs/disk-io.c | 4 ++-- fs/btrfs/disk-io.h | 2 +- fs/btrfs/extent-tree.c | 6 +++--- fs/btrfs/free-space-tree.c | 2 +- fs/btrfs/ioctl.c | 2 +- fs/btrfs/qgroup.c | 2 +- fs/btrfs/tree-log.c | 6 +++--- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 5476d90a76ce..4b7cd5acdaf9 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -459,7 +459,7 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans, if (ret) return ret; } - btrfs_clean_tree_block(buf); + btrfs_clear_buffer_dirty(buf); *last_ref = 1; } return 0; @@ -1026,7 +1026,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, path->locks[level] = 0; path->nodes[level] = NULL; - btrfs_clean_tree_block(mid); + btrfs_clear_buffer_dirty(mid); btrfs_tree_unlock(mid); /* once for the path */ free_extent_buffer(mid); @@ -1087,7 +1087,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, if (wret < 0 && wret != -ENOSPC) ret = wret; if (btrfs_header_nritems(right) == 0) { - btrfs_clean_tree_block(right); + btrfs_clear_buffer_dirty(right); btrfs_tree_unlock(right); del_ptr(root, path, level + 1, pslot + 1); root_sub_used(root, right->len); @@ -1133,7 +1133,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, BUG_ON(wret == 1); } if (btrfs_header_nritems(mid) == 0) { - btrfs_clean_tree_block(mid); + btrfs_clear_buffer_dirty(mid); btrfs_tree_unlock(mid); del_ptr(root, path, level + 1, pslot); root_sub_used(root, mid->len); @@ -3106,7 +3106,7 @@ static noinline int __push_leaf_right(struct btrfs_path *path, if (left_nritems) btrfs_mark_buffer_dirty(left); else - btrfs_clean_tree_block(left); + btrfs_clear_buffer_dirty(left); btrfs_mark_buffer_dirty(right); @@ -3118,7 +3118,7 @@ static noinline int __push_leaf_right(struct btrfs_path *path, if (path->slots[0] >= left_nritems) { path->slots[0] -= left_nritems; if (btrfs_header_nritems(path->nodes[0]) == 0) - btrfs_clean_tree_block(path->nodes[0]); + btrfs_clear_buffer_dirty(path->nodes[0]); btrfs_tree_unlock(path->nodes[0]); free_extent_buffer(path->nodes[0]); path->nodes[0] = right; @@ -3330,7 +3330,7 @@ static noinline int __push_leaf_left(struct btrfs_path *path, int data_size, if (right_nritems) btrfs_mark_buffer_dirty(right); else - btrfs_clean_tree_block(right); + btrfs_clear_buffer_dirty(right); btrfs_item_key(right, &disk_key, 0); fixup_low_keys(path, &disk_key, 1); @@ -4367,7 +4367,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, if (leaf == root->node) { btrfs_set_header_level(leaf, 0); } else { - btrfs_clean_tree_block(leaf); + btrfs_clear_buffer_dirty(leaf); btrfs_del_leaf(trans, root, path, leaf); } } else { diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 275ba1925eeb..b8f1ac54d10c 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -965,7 +965,7 @@ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, } -void btrfs_clean_tree_block(struct extent_buffer *buf) +void btrfs_clear_buffer_dirty(struct extent_buffer *buf) { struct btrfs_fs_info *fs_info = buf->fs_info; btrfs_assert_tree_write_locked(buf); @@ -5077,7 +5077,7 @@ static int btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info, btrfs_tree_lock(eb); wait_on_extent_buffer_writeback(eb); - btrfs_clean_tree_block(eb); + btrfs_clear_buffer_dirty(eb); btrfs_tree_unlock(eb); free_extent_buffer_stale(eb); diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index f2c507fd0e04..8d23746c7660 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -39,7 +39,7 @@ struct extent_buffer *btrfs_find_create_tree_block( struct btrfs_fs_info *fs_info, u64 bytenr, u64 owner_root, int level); -void btrfs_clean_tree_block(struct extent_buffer *buf); +void btrfs_clear_buffer_dirty(struct extent_buffer *buf); void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info); int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info); int btrfs_check_super_csum(struct btrfs_fs_info *fs_info, diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 971b1de50d9e..3f123c3570a9 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4905,7 +4905,7 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root, btrfs_set_buffer_lockdep_class(lockdep_owner, buf, level); __btrfs_tree_lock(buf, nest); - btrfs_clean_tree_block(buf); + btrfs_clear_buffer_dirty(buf); clear_bit(EXTENT_BUFFER_STALE, &buf->bflags); clear_bit(EXTENT_BUFFER_NO_CHECK, &buf->bflags); @@ -5530,12 +5530,12 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans, } } } - /* make block locked assertion in btrfs_clean_tree_block happy */ + /* make block locked assertion in btrfs_clear_buffer_dirty happy */ if (!path->locks[level]) { btrfs_tree_lock(eb); path->locks[level] = BTRFS_WRITE_LOCK; } - btrfs_clean_tree_block(eb); + btrfs_clear_buffer_dirty(eb); } if (eb == root->node) { diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c index c667e878ef1a..e03f58f43719 100644 --- a/fs/btrfs/free-space-tree.c +++ b/fs/btrfs/free-space-tree.c @@ -1283,7 +1283,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info) list_del(&free_space_root->dirty_list); btrfs_tree_lock(free_space_root->node); - btrfs_clean_tree_block(free_space_root->node); + btrfs_clear_buffer_dirty(free_space_root->node); btrfs_tree_unlock(free_space_root->node); btrfs_free_tree_block(trans, btrfs_root_id(free_space_root), free_space_root->node, 0, 1); diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index a64a71d882dc..8048b536c682 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -707,7 +707,7 @@ static noinline int create_subvol(struct user_namespace *mnt_userns, * exists). */ btrfs_tree_lock(leaf); - btrfs_clean_tree_block(leaf); + btrfs_clear_buffer_dirty(leaf); btrfs_tree_unlock(leaf); btrfs_free_tree_block(trans, objectid, leaf, 0, 1); free_extent_buffer(leaf); diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 35856ea28e32..9e22698ea439 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -1303,7 +1303,7 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info) list_del("a_root->dirty_list); btrfs_tree_lock(quota_root->node); - btrfs_clean_tree_block(quota_root->node); + btrfs_clear_buffer_dirty(quota_root->node); btrfs_tree_unlock(quota_root->node); btrfs_free_tree_block(trans, btrfs_root_id(quota_root), quota_root->node, 0, 1); diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 73e621df32f7..15695f505f05 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -2636,7 +2636,7 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans, } btrfs_tree_lock(next); - btrfs_clean_tree_block(next); + btrfs_clear_buffer_dirty(next); btrfs_wait_tree_block_writeback(next); btrfs_tree_unlock(next); @@ -2705,7 +2705,7 @@ static noinline int walk_up_log_tree(struct btrfs_trans_handle *trans, next = path->nodes[*level]; btrfs_tree_lock(next); - btrfs_clean_tree_block(next); + btrfs_clear_buffer_dirty(next); btrfs_wait_tree_block_writeback(next); btrfs_tree_unlock(next); @@ -2786,7 +2786,7 @@ static int walk_log_tree(struct btrfs_trans_handle *trans, next = path->nodes[orig_level]; btrfs_tree_lock(next); - btrfs_clean_tree_block(next); + btrfs_clear_buffer_dirty(next); btrfs_wait_tree_block_writeback(next); btrfs_tree_unlock(next); From patchwork Wed Dec 7 22:28:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13067720 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 49F32C63708 for ; Wed, 7 Dec 2022 22:28:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229733AbiLGW22 (ORCPT ); Wed, 7 Dec 2022 17:28:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229711AbiLGW21 (ORCPT ); Wed, 7 Dec 2022 17:28:27 -0500 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30BFC81D8E for ; Wed, 7 Dec 2022 14:28:26 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id x28so16251930qtv.13 for ; Wed, 07 Dec 2022 14:28:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Qm071SMDR2NnJ115/TnXgUIANBPM1dlkDB4AQkH670Y=; b=2bHM8FM+8otp7seyJOb0vqEuqYQwbZ8TTRACz3T0u98hGtryiWJcv1IDSM3hgLD6Fh 39iaTl/K6K4Sd+pZ7AjNaPWw8P0tK4QaWHxghXSPMKNgojttcf0pviZHI+zf7n5Dz2xf Q8wx/WUGOKpIgmxJzRyOiyBmIlY81asWqRHmczXuIN5hqK/gElPaj524BU7vLFBQa1hS vWRxJGuEecl5xG2ggditdrR/iUuLOiOevDapztBCPhvxN8xBdlVNo+kAeY1dRj/l63nJ soKBsEb4aYKqnawdqcHaEllKP/1uLCywD3gR/u897dBb6JAi312noh+BYwYtl8bmHxi9 7UXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Qm071SMDR2NnJ115/TnXgUIANBPM1dlkDB4AQkH670Y=; b=JLX5XpNbJd9YKrIauepfStsdPATSrAzqeT46a1XqY4jrlaw5JQteRqGN80cLULKxEJ YBsS/GUDDEouOTCp6PzAYCawkkkqvQmPzz+Q4qc8HJ3bhrT6vKSiGFRsRSLYrb6x0qmt REgBGxWeDAnJKx2ZYX8y8eQ+SGxodiDocufMSHq/8TYIjMpL/jyWkeqZtLYWcuTDLMLy Ldv0FQ9ClQwVUrYdW+2bTSPtzp1zmlkBPRPO6d58cvIqqkzjFWgDU394kKMEtPWRn0tg h70GBtZAHqEaYqFqPVzUmWA8PA+zuCS0PGajsYxFEHGdxMmYduHswzMx87BFQS4gjBqB bLcA== X-Gm-Message-State: ANoB5pkqrzOrBA5kSoJ33wRtmzpZ3AusYCO1lJp7jPN291uJTJBDzcIk HbDgEG3zAdad/WEuLXxo7UCG2WIutqFpGk0X X-Google-Smtp-Source: AA0mqf7y0HTwDvBQEEDRIWvRvSOnibUo3bNjQFhPjZjvHNO0PqTd7D7k9uWkQcNRjqXYvERJ/zWjvg== X-Received: by 2002:ac8:1098:0:b0:3a5:3819:51da with SMTP id a24-20020ac81098000000b003a5381951damr1405673qtj.38.1670452104798; Wed, 07 Dec 2022 14:28:24 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id j13-20020a05620a288d00b006fbbdc6c68fsm18467144qkp.68.2022.12.07.14.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 14:28:24 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 7/8] btrfs: combine btrfs_clear_buffer_dirty and clear_extent_buffer_dirty Date: Wed, 7 Dec 2022 17:28:10 -0500 Message-Id: <10d22123b5e1cdbbefab86e0667d81951f537f77.1670451918.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_clear_buffer_dirty just does the test_clear_bit() and then calls clear_extent_buffer_dirty and does the dirty metadata accounting. Combine this into clear_extent_buffer_dirty and make the result btrfs_clear_buffer_dirty. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 13 ------------- fs/btrfs/extent_io.c | 11 ++++++++++- fs/btrfs/extent_io.h | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index b8f1ac54d10c..8edbf73d8707 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -965,19 +965,6 @@ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, } -void btrfs_clear_buffer_dirty(struct extent_buffer *buf) -{ - struct btrfs_fs_info *fs_info = buf->fs_info; - btrfs_assert_tree_write_locked(buf); - - if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &buf->bflags)) { - percpu_counter_add_batch(&fs_info->dirty_metadata_bytes, - -buf->len, - fs_info->dirty_metadata_batch); - clear_extent_buffer_dirty(buf); - } -} - static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info, u64 objectid) { diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 7cd4065acc82..c242aabfa863 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -4813,12 +4813,21 @@ static void clear_subpage_extent_buffer_dirty(const struct extent_buffer *eb) WARN_ON(atomic_read(&eb->refs) == 0); } -void clear_extent_buffer_dirty(const struct extent_buffer *eb) +void btrfs_clear_buffer_dirty(struct extent_buffer *eb) { + struct btrfs_fs_info *fs_info = eb->fs_info; int i; int num_pages; struct page *page; + btrfs_assert_tree_write_locked(eb); + + if (!test_and_clear_bit(EXTENT_BUFFER_DIRTY, &eb->bflags)) + return; + + percpu_counter_add_batch(&fs_info->dirty_metadata_bytes, -eb->len, + fs_info->dirty_metadata_batch); + if (eb->fs_info->nodesize < PAGE_SIZE) return clear_subpage_extent_buffer_dirty(eb); diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index a024655d4237..41fc887d6cfe 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -261,7 +261,6 @@ void extent_buffer_bitmap_set(const struct extent_buffer *eb, unsigned long star void extent_buffer_bitmap_clear(const struct extent_buffer *eb, unsigned long start, unsigned long pos, unsigned long len); -void clear_extent_buffer_dirty(const struct extent_buffer *eb); bool set_extent_buffer_dirty(struct extent_buffer *eb); void set_extent_buffer_uptodate(struct extent_buffer *eb); void clear_extent_buffer_uptodate(struct extent_buffer *eb); @@ -273,6 +272,7 @@ void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end, u32 bits_to_clear, unsigned long page_ops); int extent_invalidate_folio(struct extent_io_tree *tree, struct folio *folio, size_t offset); +void btrfs_clear_buffer_dirty(struct extent_buffer *buf); int btrfs_alloc_page_array(unsigned int nr_pages, struct page **page_array); From patchwork Wed Dec 7 22:28:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13067721 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 1D98FC63709 for ; Wed, 7 Dec 2022 22:28:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229696AbiLGW23 (ORCPT ); Wed, 7 Dec 2022 17:28:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229720AbiLGW22 (ORCPT ); Wed, 7 Dec 2022 17:28:28 -0500 Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA1C681D87 for ; Wed, 7 Dec 2022 14:28:27 -0800 (PST) Received: by mail-qv1-xf34.google.com with SMTP id s14so13672433qvo.11 for ; Wed, 07 Dec 2022 14:28:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=zJjFPZ3bVjCi1soL/NYCpPC55azD6NczF2opwl7HCRI=; b=K/Vex0L6GHrv7qSMqXK1BoHzNkmE+ZWNUb686Yp++Ff+H+B324t9Aj4mJAb2x6Y50r A4PRanlTrOcpyV3HzzsCsCLsP7xcytdfSspKu56Q4TgZUt1k6uyeScpXkqJAZE32hwob eOVO9FtqoVzhDoiiCaP1j8F8qqpl+TRAPNAP0prgaGE5G+aOfZ+/UA/In+6jNoijwWN8 02xNiokeKuhyAAahi2Ew+sP/SVKKhUrreb4z8ekqNqg3X05MLNN16BTszNO97uPETBox EyRxWM7FS9jTQR4+LpDcXReBTpsthMIk/e5E1oO9WkFRzntm20abRKbX8uvZEpnICcNH L5Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zJjFPZ3bVjCi1soL/NYCpPC55azD6NczF2opwl7HCRI=; b=lNiyPtrj/ukH8p1LdA2BvfUCNzqWCZGjNVmq+AEPS41GjgogBhCLfYdG0LgRL0gv59 R1X27anNEff+9j+Gg4wqLSHvuaqPZI/zeNZ31aObOKyFuxlGcHm9CvXfriJBDbbneyqT +NP+/X3Wkj7jxVRvO0bWh1gIknvuKpy00OYnAxG+ff4mbkZZAA4bEVHSMnQTiAai9rkj epnkokar+kGL0QQ0W14jEVPtpnxJnSS+OiE53BXA0Zg/L/5ScS+cZKX8eZYZEXhxpGaK cXrhGR8upu7i+Cg2h0pehMR8BXSjHktcINls09WBc9e4/+y20YCTCKCuBmlDvDf0OvMs ZNkw== X-Gm-Message-State: ANoB5pnLxXnkl+356PvV3up1A25aQmtXW2UTHFgzRKRBiPfY37aPiviU e3JHYCPy/VwKCKiLqIehet7ufgUnTN663VOw X-Google-Smtp-Source: AA0mqf51lcxBgwwfgkHuVfND8lsznY3KbcBdXYf2YAVMcW1z4GelOEE2oCuZUY+XZhdD1DotntsVmQ== X-Received: by 2002:a05:6214:e6c:b0:4c7:7257:68a2 with SMTP id jz12-20020a0562140e6c00b004c7725768a2mr2013758qvb.15.1670452106392; Wed, 07 Dec 2022 14:28:26 -0800 (PST) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id x10-20020a05620a258a00b006bb82221013sm18033073qko.0.2022.12.07.14.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 14:28:25 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 8/8] btrfs: remove btrfs_wait_tree_block_writeback Date: Wed, 7 Dec 2022 17:28:11 -0500 Message-Id: <455b500ef31fc9cc86b181a51bb840086dcc1ade.1670451918.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is used in the tree-log code and is a holdover from previous iterations of extent buffer writeback. We can simply use wait_on_extent_buffer_writeback here, and remove btrfs_wait_tree_block_writeback completely. Signed-off-by: Josef Bacik --- fs/btrfs/tree-log.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 15695f505f05..15f8130d812c 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -278,12 +278,6 @@ void btrfs_end_log_trans(struct btrfs_root *root) } } -static void btrfs_wait_tree_block_writeback(struct extent_buffer *buf) -{ - filemap_fdatawait_range(buf->pages[0]->mapping, - buf->start, buf->start + buf->len - 1); -} - /* * the walk control struct is used to pass state down the chain when * processing the log tree. The stage field tells us which part @@ -2637,7 +2631,7 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans, btrfs_tree_lock(next); btrfs_clear_buffer_dirty(next); - btrfs_wait_tree_block_writeback(next); + wait_on_extent_buffer_writeback(next); btrfs_tree_unlock(next); if (trans) { @@ -2706,7 +2700,7 @@ static noinline int walk_up_log_tree(struct btrfs_trans_handle *trans, btrfs_tree_lock(next); btrfs_clear_buffer_dirty(next); - btrfs_wait_tree_block_writeback(next); + wait_on_extent_buffer_writeback(next); btrfs_tree_unlock(next); if (trans) { @@ -2787,7 +2781,7 @@ static int walk_log_tree(struct btrfs_trans_handle *trans, btrfs_tree_lock(next); btrfs_clear_buffer_dirty(next); - btrfs_wait_tree_block_writeback(next); + wait_on_extent_buffer_writeback(next); btrfs_tree_unlock(next); if (trans) {