From patchwork Thu Oct 3 15:43:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13821178 Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 799A31A7AF7 for ; Thu, 3 Oct 2024 15:43:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970203; cv=none; b=GrAD0QUscEeySzy0StGpflHFK5Bbgk1+ynX7URApYM25WjJMe6ognKwc1zOOYpszI5q8UqWBwPjjXhcg9ERlTthnFmk2AMHNIVDeLjzwfn0NkmpdamWH3vJ6Ub+wnvBOB9/+Pc8VVSm9v0vG2ahvyKAYuSZhviXMZA4BzdL2s+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970203; c=relaxed/simple; bh=ZWAo77Cg01PM4hpmTcBlgxLPVdDt+UMKii47LVzjMZg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WlMSMfyG0mTOlxC8GZaM65gTcDmrJLL0MlXTD2lHbaBxbT2XAkkgV+A5/84nTA2MA7QF84wFOxIcYc4aZYNNhxxuf7E71oxTV368C7ZIGXI0OM6W3CzbGVAgA7yDldanHTmflzY/mL/stawNv5NiZc5idEwVMShox2c6jQAgsR8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=Ma+VlN7z; arc=none smtp.client-ip=209.85.160.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="Ma+VlN7z" Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-4581ee65b46so9500981cf.3 for ; Thu, 03 Oct 2024 08:43:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1727970200; x=1728575000; darn=vger.kernel.org; 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=zGuzAj+AZwW5RVj2QGieSQk3YM0J+fHoDbIspTtORCo=; b=Ma+VlN7zDDMB2ZIj2PMQraMNFRxo6bMmLAz16OI8Rc7j6GG8UQsG+Yo6aM6oXsELU9 HjfKOJ0cFOCmw3RB7Bm3zEpvxfRXszRJ+v9Ea/utlVzg2FtH2tY/QE9yaNMZXdqZt3l3 wWMaZd9hQVWR24rgK1vqOgUERe+oJRKgj61D9cAUyiwGUwdl573nlg8XIxCDW25xTSfD vKsC+GItO6T3jZOfN3wXwTM5OzGBBd+X7kVQU1g71pfxGMh3jg1bO1fDIis0LEfv1bw1 6duZ+g56T7DlsjJNQWsdetYUl9FAD80vh+yHZLsJ2VYzjx+G+obFXTTxFm0yhVG04Cyl dfeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727970200; x=1728575000; 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=zGuzAj+AZwW5RVj2QGieSQk3YM0J+fHoDbIspTtORCo=; b=eMepwG1DZRALp0u3zeCWg9VsQxFCjYGq+SxEPKoc5xteTOth+xFkz31WdRlsJ8uMrQ cqLDHj5cQlTd+sl00m4nlVPtqbcRVwmuKeh3yuwecbrrd8/iW47MWjQkWM0m6JSTSggF +uQT501UjRlDWH0jbxFdfxaHWBZx5h0rRYQ4nTzdUPClFZVljpMl26nqWP+r7pQSddfz t8GI7lGUCo/gF8bS3476ThsUSy0sfcxWrlnFYiS2+MZ3fxs1cTwLwgY4hF8UJ8ckeug6 cEwBhzX5psnVt/Yl/+DL/35nz6RzrozEMoBvqTNrMrji3d5Ev898+ZPkQ1FPAMvoccVp rGXA== X-Gm-Message-State: AOJu0YwKjr1Z+hChZNgs1Yvp5ATe5rWnQ5CWtCTh0rX9y9cWpDWMlk/a ilSOA06VyI3QQvGp9osL85iYOMOfMUJtmEvEHkctsZXqPeHCaVLxL97BzA/SZh8hJ5kQzUYrxSy g X-Google-Smtp-Source: AGHT+IEJfg/yDaWiBBuwQzjF8wK4YJBRz9BhYti1cfQwan4pte3F12rdaCa708PNoVcJuEdEc/6jww== X-Received: by 2002:a05:622a:3ce:b0:458:59bb:74f6 with SMTP id d75a77b69052e-45d80559c67mr115998771cf.52.1727970199802; Thu, 03 Oct 2024 08:43:19 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45d92f0262asm6579981cf.80.2024.10.03.08.43.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 08:43:18 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 01/10] btrfs: convert BUG_ON in btrfs_reloc_cow_block to proper error handling Date: Thu, 3 Oct 2024 11:43:03 -0400 Message-ID: <8f6d53a745813c8267a20b1dc1caa4fb722423bb.1727970062.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This BUG_ON is meant to catch backref cache problems, but these can arise from either bugs in the backref cache or corruption in the extent tree. Fix it to be a proper error and change it to an ASSERT() so that developers notice problems. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index f3834f8d26b4..3c89e79d0259 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -4399,8 +4399,20 @@ int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, WARN_ON(!first_cow && level == 0); node = rc->backref_cache.path[level]; - BUG_ON(node->bytenr != buf->start && - node->new_bytenr != buf->start); + + /* + * If node->bytenr != buf->start and node->new_bytenr != + * buf->start then we've got the wrong backref node for what we + * expected to see here and the cache is incorrect. + */ + if (node->bytenr != buf->start && + node->new_bytenr != buf->start) { + btrfs_err(fs_info, +"bytenr %llu was found but our backref cache was expecting %llu or %llu", + buf->start, node->bytenr, node->new_bytenr); + ASSERT(0); + return -EUCLEAN; + } btrfs_backref_drop_node_buffer(node); atomic_inc(&cow->refs); From patchwork Thu Oct 3 15:43:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13821179 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22F551A704C for ; Thu, 3 Oct 2024 15:43:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970204; cv=none; b=FdaNOXnb5rcnxbkYmx3tlsSoF8+4ols5aB0uWiqP2q5u80v293W1xOxLt2wPODJEoDYuHh2gc2Sk10Q5I4jdYiD6I3/rN0dETr7wnHByB7wM+1ZpyIC/m449MMtZ+ryu5kpnN80zzZ+ogD4dfnefJAml9nnD5m7v6tI0RwzButM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970204; c=relaxed/simple; bh=5gD+B7AbEDeZXrWFRBaQb41DQ04mzuC1RXm031w6V/Q=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MuxnQUTus8MpzTtocg9jVGPregj64206Xox6lr5XTWT+vDu1PX9x0jd0KdoZZ4i+G8mYaDOV196ABBH7nPM2/xslb2duD+KpBpJWToYvM/IV+x/ZsGepSMKHKw7fTaGidonyZWEiE51T9miWPvO2qO55BAk60DlkVk0AmdTRdi4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=MkGJ4i1M; arc=none smtp.client-ip=209.85.219.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="MkGJ4i1M" Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-6cb399056b4so9034086d6.0 for ; Thu, 03 Oct 2024 08:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1727970201; x=1728575001; darn=vger.kernel.org; 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=2wdPQAB1FTb7S1tvD/OywsaJyCqlsWezBshNy8mjVi0=; b=MkGJ4i1MvuuVh6DhJfH/uy+LvVv7VoQ6eC9k7xGCibfw0bFMALvEGGW1aqHcjrtfF7 MzM05Yo/VbDLUmAFRtNr6HLiFueSWJAk3v+DxeNDNjICFXrb0BJd9L8JtvJenV/au/kM EaM6Ckq+sL7p8MMiqtLpfPwmt1gKwA8/f57v3LcKFR2zoDH8oBexLTxQ3HUP9zdA+FHP reyt9pJmrn80rYyax80tQ/ok+XUe15i7zS8pX9HAIfRobDfwiXZkzMlKqBoSFHgvsv5K j/cSxzDyq17+5Da1jnW73pNZPikLtjXkLUeL0/a7fhDXzDsXlHFkUfdM1m6DTO9YzEHi r8Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727970201; x=1728575001; 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=2wdPQAB1FTb7S1tvD/OywsaJyCqlsWezBshNy8mjVi0=; b=aYRzpWthLFkl1d3dDjVByzbWAJdGJQBQOGvArCIO1hnhK7alM4lXZLozxyPgE8n0/q NXqxZXz7tEryjjzsB2RlSBDfu1JGSVuz1oV2rmR8z/1wImo32XmzRgK8GXTXdw+2s0JJ mJZ2vq374JtmoonHleC/n2+NsFr/ilCCtr4tNJgni2e3mYXi1DqFY1pCgA/eeXBgp7Ns iUjlwXOanw04/IWZGWudYr04p0B93ensMqIBmG57XBR3w2AOokrFnC4rg6zCE6x67en2 Bi6+NZptZpFVYaRbktS0qmOyjaK7Z+ZZfqatu9lSiKKi1rZmo8pVGFOhhFNM08WCQfQY QkgA== X-Gm-Message-State: AOJu0YwlPvPRtWQBUliFImkUNT9dW86PeGOwJeoiCV+U8CODabeuh5v0 vVucDBOuI9+J+aGT41vQ79yHVRvKDlnR5qey9MUSaLAXfxyct7CCGhvGOWD2PRlU/d+tROC4Pmd j X-Google-Smtp-Source: AGHT+IHlJRsvfPRk2Xh7gYxAx3lTw0eZM0zDxnO+XS8f8nA+hFkk4xVtiR4NTFmepM07+dhyF8zOxA== X-Received: by 2002:a05:6214:5408:b0:6cb:5aa6:97a with SMTP id 6a1803df08f44-6cb81a37809mr113703956d6.24.1727970201521; Thu, 03 Oct 2024 08:43:21 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6cb93825f60sm7345276d6.140.2024.10.03.08.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 08:43:20 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 02/10] btrfs: remove the changed list for backref cache Date: Thu, 3 Oct 2024 11:43:04 -0400 Message-ID: <53461c08f218c675481446a79c242b687dea345f.1727970063.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that we're not updating the backref cache when we switch transids we can remove the changed list. We're going to keep the new_bytenr field because it serves as a good sanity check for the backref cache and relocation, and can prevent us from making extent tree corruption worse. Signed-off-by: Josef Bacik --- fs/btrfs/backref.c | 2 -- fs/btrfs/backref.h | 2 -- fs/btrfs/relocation.c | 22 ++++++++-------------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index f8e1d5b2c512..881bb5600b55 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -3021,7 +3021,6 @@ void btrfs_backref_init_cache(struct btrfs_fs_info *fs_info, cache->rb_root = RB_ROOT; for (i = 0; i < BTRFS_MAX_LEVEL; i++) INIT_LIST_HEAD(&cache->pending[i]); - INIT_LIST_HEAD(&cache->changed); INIT_LIST_HEAD(&cache->detached); INIT_LIST_HEAD(&cache->leaves); INIT_LIST_HEAD(&cache->pending_edge); @@ -3189,7 +3188,6 @@ void btrfs_backref_release_cache(struct btrfs_backref_cache *cache) } ASSERT(list_empty(&cache->pending_edge)); ASSERT(list_empty(&cache->useless_node)); - ASSERT(list_empty(&cache->changed)); ASSERT(list_empty(&cache->detached)); ASSERT(RB_EMPTY_ROOT(&cache->rb_root)); ASSERT(!cache->nr_nodes); diff --git a/fs/btrfs/backref.h b/fs/btrfs/backref.h index e8c22cccb5c1..a810253d7b8a 100644 --- a/fs/btrfs/backref.h +++ b/fs/btrfs/backref.h @@ -393,8 +393,6 @@ struct btrfs_backref_cache { struct list_head pending[BTRFS_MAX_LEVEL]; /* List of backref nodes with no child node */ struct list_head leaves; - /* List of blocks that have been COWed in current transaction */ - struct list_head changed; /* List of detached backref node. */ struct list_head detached; diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 3c89e79d0259..ac3658dce6a3 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2113,14 +2113,13 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans, if (next->new_bytenr != root->node->start) { /* * We just created the reloc root, so we shouldn't have - * ->new_bytenr set and this shouldn't be in the changed - * list. If it is then we have multiple roots pointing - * at the same bytenr which indicates corruption, or - * we've made a mistake in the backref walking code. + * ->new_bytenr set yet. If it is then we have multiple + * roots pointing at the same bytenr which indicates + * corruption, or we've made a mistake in the backref + * walking code. */ ASSERT(next->new_bytenr == 0); - ASSERT(list_empty(&next->list)); - if (next->new_bytenr || !list_empty(&next->list)) { + if (next->new_bytenr) { btrfs_err(trans->fs_info, "bytenr %llu possibly has multiple roots pointing at the same bytenr %llu", node->bytenr, next->bytenr); @@ -2131,8 +2130,6 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans, btrfs_put_root(next->root); next->root = btrfs_grab_root(root); ASSERT(next->root); - list_add_tail(&next->list, - &rc->backref_cache.changed); mark_block_processed(rc, next); break; } @@ -2442,7 +2439,7 @@ static int do_relocation(struct btrfs_trans_handle *trans, if (!ret && node->pending) { btrfs_backref_drop_node_buffer(node); - list_move_tail(&node->list, &rc->backref_cache.changed); + list_del_init(&node->list); node->pending = 0; } @@ -2605,8 +2602,7 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, /* * This block was the root block of a root, and this is * the first time we're processing the block and thus it - * should not have had the ->new_bytenr modified and - * should have not been included on the changed list. + * should not have had the ->new_bytenr modified. * * However in the case of corruption we could have * multiple refs pointing to the same block improperly, @@ -2616,8 +2612,7 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, * normal user in the case of corruption. */ ASSERT(node->new_bytenr == 0); - ASSERT(list_empty(&node->list)); - if (node->new_bytenr || !list_empty(&node->list)) { + if (node->new_bytenr) { btrfs_err(root->fs_info, "bytenr %llu has improper references to it", node->bytenr); @@ -2640,7 +2635,6 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, btrfs_put_root(node->root); node->root = btrfs_grab_root(root); ASSERT(node->root); - list_add_tail(&node->list, &rc->backref_cache.changed); } else { path->lowest_level = node->level; if (root == root->fs_info->chunk_root) From patchwork Thu Oct 3 15:43:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13821180 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C06E1A76B5 for ; Thu, 3 Oct 2024 15:43:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970205; cv=none; b=c6xq4QawCP7HCaf5fBWcE5b8RF69V5M4+vTgC6LUeswcsMP4SBsUg8Md4KYJyez00V+L2iANQV84hiXQmASKl4RaOaiW331Vt48qXzRlCIT2XJX4peLXl8i2SyNueFdVfOJW0YAY9o8+9rTdTpgIXkMMRYAMfhjRI7Igysu25ic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970205; c=relaxed/simple; bh=rZ0K1S06D0ZkgY3M86y+HVET91qr6B7cqJeFgH75ZiU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c9jS9NSLfFWrAeRrMjs5MoVkprX94iM9SY7W5cC/YKrWfCXofmAVfR6/aYs/EYBMoFWaUWyjuFILip7vGapUmj4zB0SZ/lYJYC08MEBa1eC5MPOHX8YStklYgyNQh2I1UVyuS8gYX+St5epMn8LmFFbG+ZfKfmfbcthMVlKopZQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=BsDiO23c; arc=none smtp.client-ip=209.85.222.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="BsDiO23c" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-7a99e8d5df1so112410385a.2 for ; Thu, 03 Oct 2024 08:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1727970203; x=1728575003; darn=vger.kernel.org; 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=ZgO8EnbrLbNOXx/ZvzWXsMt6+6Or5rDE5/d/2+5E+7M=; b=BsDiO23cTvymTkaguef7ibue5/Us1ndOl75ZzaF9PWCIuKpn6s6p7lxXrNxACikrkd 1VbCZLPBsb3ozxbbaklcUE7OR+XF/vtPdP/AjopSwpE1p+KBxCXGQJAqHsA4mJvjnMR/ CX5dQPwrZWcfQdaSCAFllAgrVYAGnF1xSwC8dRLtXDmt0KhjaK+Qxo/8/BaVsqONPaIU JaHOTvXpMl9H8A8xPYHnIUZdl8Npzr8kCI4cm7gJEzwhgp4Prlk2J0kOfjDNnw2FzpZF QWRE4YrnJJJQlRDaddT+ihNZnaLR5myiVjzCuSEXn1+NV0A2E/KiP/kBVShfb4oBye0S xTrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727970203; x=1728575003; 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=ZgO8EnbrLbNOXx/ZvzWXsMt6+6Or5rDE5/d/2+5E+7M=; b=YEAz5utImpCL4JW3NtZ79FvqJ9o2VUGmaJPWpPyn0EBI8uL/vV7S9kQ+nk1KUMaMJ8 ZlAVhWguDLtGUIkBTw6Qqo7Zzv1jwrNiUgWLVx7PeMYjQUiTB6F/jqCvrDl+qUTVKt9c OinEvXVV5OGU/32SlWwlG2/65SG2/tUaJBIVN9cRFX6Yly2vvLgE1dshnw2baW7F5lFY efn0Z3U/x9CSSjJCvpmjRANwhqmV7osKI1XQC249/AjLEuXnArzJICqMAc0Ocwl8I8NP 3guJ9PldZf//dWv5toViNee9Ozla8bJbJrBl5fiqOXElk2yNqUT7Tb7ptVjrI7JDngnL BUmg== X-Gm-Message-State: AOJu0YwMzWKYANl3WgxkEg/47HSxCJRtNLD1pd/jM/H94aH1QYsv4Yo0 M1iaXpO4ZdDDUbxWsn6z5B2ZMgVvP2CHOcym7MnXVZibpwAqlktfguBP2x5xJjxMYP/c3BHG8eL C X-Google-Smtp-Source: AGHT+IGdpb/Mcd/vUJKJQkPPtMGHs7p45L+IOanobE3WOqEpZpI4bcKftbN9H2yEVq83JAkY8FAH0w== X-Received: by 2002:a05:620a:1a0d:b0:7a9:c129:5da7 with SMTP id af79cd13be357-7ae626d2df9mr1006563785a.29.1727970202965; Thu, 03 Oct 2024 08:43:22 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7ae6b29e1e3sm60544285a.16.2024.10.03.08.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 08:43:22 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 03/10] btrfs: add a comment for new_bytenr in bacref_cache_node Date: Thu, 3 Oct 2024 11:43:05 -0400 Message-ID: <822af146718551c3f2ba248ba9df9092ba022160.1727970063.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a comment for this field so we know what it is used for. Previously we used it to update the backref cache, so people may mistakenly think it is useless, but in fact exists to make sure the backref cache makes sense. Signed-off-by: Josef Bacik --- fs/btrfs/backref.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/btrfs/backref.h b/fs/btrfs/backref.h index a810253d7b8a..754c71bdc9ce 100644 --- a/fs/btrfs/backref.h +++ b/fs/btrfs/backref.h @@ -318,6 +318,12 @@ struct btrfs_backref_node { u64 bytenr; }; /* Use rb_simple_node for search/insert */ + /* + * This is a sanity check, whenever we cow a block we will update + * new_bytenr with it's current location, and we will check this in + * various places to validate that the cache makes sense, it shouldn't + * be used for anything else. + */ u64 new_bytenr; /* Objectid of tree block owner, can be not uptodate */ u64 owner; From patchwork Thu Oct 3 15:43:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13821181 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF01D1AAE3E for ; Thu, 3 Oct 2024 15:43:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970207; cv=none; b=Ee3fwqwMxIDRTfNcOuUyprubkk1NHw8CwjQrSQssfWMB4SUYlN0k/qgki93iKP5ba3ObhRxsqHw5yXt+pNKJTxEf5QN8hFlNJ/2NQK/T/AVd2eaZzJ6+Z1Eyn9z3flijYSL5apCzL/0Tmhem6wy3NH8xy9SB3I9j7YX/Au2nTmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970207; c=relaxed/simple; bh=xfBNQbUeaoE7dKV2f3J13ceE7gb2BQZJBcJ1lwKDZlc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IIQjzLYqkPhVwxyuc4+wjHPANa2SRNTa8xMUEtCypTB38yVU0P8z/Fi2iAARXwL5ZIMVfdga/zB9SZeThNASMDPQO10zVkE0XE51p5+tI8tsYplBfZ4KIgON+vUvYWnrhw9/U10YuGC+4kl1Ubvvo363vQznmDgEU8N96R9Vp1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=Eq+YLkFc; arc=none smtp.client-ip=209.85.219.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="Eq+YLkFc" Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-6cb2f344dbbso9253126d6.3 for ; Thu, 03 Oct 2024 08:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1727970204; x=1728575004; darn=vger.kernel.org; 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=Wy+0tsqwWv1xYobk+o+FQfC/ycfIC20KW0NSUlx+8/0=; b=Eq+YLkFc5pOrdJX6/55ArJ1IvZpBkqi4AkEhChjBeSdDc3ZNyrzOIkptXhAGB1xxYh XHHlhxl7RC5bER0l12144SlOzIQVMrGndX9oYD0zNeSiTMnETKCooGiAE7gP2edB/rhY YCfaOzhX9U6FNsbVPhnsQWIA6MP9q/PKm0eiZl8uZvRT7KjyssDPyrbV7Eo19iXwhL2X 7qzPXy6//runGwOe6QJTXpGhguMoq86JRRF0F5i32rc55IhlzNrREcxK7DPLPMCy2lwD 074iXDZpi9THY2V+EZ4YhuhBwjygcCX2xNx06hG5bUjA7OgOOtapBc/eR8PjDf4ZAACP 8KYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727970204; x=1728575004; 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=Wy+0tsqwWv1xYobk+o+FQfC/ycfIC20KW0NSUlx+8/0=; b=O7doMUFmGBn+xk6cBvhiG03VwrRhpLojpxNpEwIhykh5iMnJTeXPxgDSkwTsvYlpko S2JwHIGe1OKHjjnnPAtq7KYbaoJKJhMeh2AzdVJ9RCtllwtChul78NARoEzA6VoZt8mN fEgUBw4Tbk30V31eOMk+Ckv5DtILCLZegVDnB9RtBfYnEjSyAghmrZuybB+q1Ik6TVKH v8xbR2qdL4/iVOkXomAfExDOiJkOFvIBeRikzSigWfiyjFbrwmwxUZrEOFzDitZcb8vd Z0QDnWOk+eStElqc2RJYfaeM/rns9zqQdSthLXHBos8wVut8OTcZaDdTao2sCUQoOMPP HFqQ== X-Gm-Message-State: AOJu0YzBdnfRpQDndj8RuGI/AlHt9ZO7l4XhFyJpiDMeMO9J6Icfwa3O KartZbGhZeQyEWWAwT/ediUbQwh/9qrWcdRWIa3oTlsxnET87HQbQ0M5b2Nm4I/TBmWzGyf0tcG 7 X-Google-Smtp-Source: AGHT+IHxgzaCoowcgWQnUF+2p/kC86JfOIcvwz07EA5Wd8JYCnNRwkuuIOxY/wabOg7JjuyG46jHdg== X-Received: by 2002:ad4:5285:0:b0:6cb:8267:4a0e with SMTP id 6a1803df08f44-6cb82674c41mr87390716d6.0.1727970204424; Thu, 03 Oct 2024 08:43:24 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6cb935cd5a3sm7539436d6.43.2024.10.03.08.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 08:43:23 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 04/10] btrfs: cleanup select_reloc_root Date: Thu, 3 Oct 2024 11:43:06 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We have this setup as a loop, but in reality we will never walk back up the backref tree, if we do then it's a bug. Get rid of the loop and handle the case where we have node->new_bytenr set at all. Previous the check was only if node->new_bytenr != root->node->start, but if it did then we would hit the WARN_ON() and walk back up the tree. Instead we want to just freak out if ->new_bytenr is set, and then do the normal updating of the node for the reloc root and carry on. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 144 ++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 83 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index ac3658dce6a3..6b2308671d83 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2058,97 +2058,75 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans, int index = 0; int ret; - next = node; - while (1) { - cond_resched(); - next = walk_up_backref(next, edges, &index); - root = next->root; + next = walk_up_backref(node, edges, &index); + root = next->root; - /* - * If there is no root, then our references for this block are - * incomplete, as we should be able to walk all the way up to a - * block that is owned by a root. - * - * This path is only for SHAREABLE roots, so if we come upon a - * non-SHAREABLE root then we have backrefs that resolve - * improperly. - * - * Both of these cases indicate file system corruption, or a bug - * in the backref walking code. - */ - if (!root) { - ASSERT(0); - btrfs_err(trans->fs_info, - "bytenr %llu doesn't have a backref path ending in a root", - node->bytenr); - return ERR_PTR(-EUCLEAN); - } - if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) { - ASSERT(0); - btrfs_err(trans->fs_info, - "bytenr %llu has multiple refs with one ending in a non-shareable root", - node->bytenr); - return ERR_PTR(-EUCLEAN); - } + /* + * If there is no root, then our references for this block are + * incomplete, as we should be able to walk all the way up to a block + * that is owned by a root. + * + * This path is only for SHAREABLE roots, so if we come upon a + * non-SHAREABLE root then we have backrefs that resolve improperly. + * + * Both of these cases indicate file system corruption, or a bug in the + * backref walking code. + */ + if (!root) { + ASSERT(0); + btrfs_err(trans->fs_info, + "bytenr %llu doesn't have a backref path ending in a root", + node->bytenr); + return ERR_PTR(-EUCLEAN); + } + if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) { + ASSERT(0); + btrfs_err(trans->fs_info, + "bytenr %llu has multiple refs with one ending in a non-shareable root", + node->bytenr); + return ERR_PTR(-EUCLEAN); + } - if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID) { - ret = record_reloc_root_in_trans(trans, root); - if (ret) - return ERR_PTR(ret); - break; - } - - ret = btrfs_record_root_in_trans(trans, root); + if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID) { + ret = record_reloc_root_in_trans(trans, root); if (ret) return ERR_PTR(ret); - root = root->reloc_root; - - /* - * We could have raced with another thread which failed, so - * root->reloc_root may not be set, return ENOENT in this case. - */ - if (!root) - return ERR_PTR(-ENOENT); - - if (next->new_bytenr != root->node->start) { - /* - * We just created the reloc root, so we shouldn't have - * ->new_bytenr set yet. If it is then we have multiple - * roots pointing at the same bytenr which indicates - * corruption, or we've made a mistake in the backref - * walking code. - */ - ASSERT(next->new_bytenr == 0); - if (next->new_bytenr) { - btrfs_err(trans->fs_info, - "bytenr %llu possibly has multiple roots pointing at the same bytenr %llu", - node->bytenr, next->bytenr); - return ERR_PTR(-EUCLEAN); - } - - next->new_bytenr = root->node->start; - btrfs_put_root(next->root); - next->root = btrfs_grab_root(root); - ASSERT(next->root); - mark_block_processed(rc, next); - break; - } - - WARN_ON(1); - root = NULL; - next = walk_down_backref(edges, &index); - if (!next || next->level <= node->level) - break; + goto found; } - if (!root) { - /* - * This can happen if there's fs corruption or if there's a bug - * in the backref lookup code. - */ - ASSERT(0); + + ret = btrfs_record_root_in_trans(trans, root); + if (ret) + return ERR_PTR(ret); + root = root->reloc_root; + + /* + * We could have raced with another thread which failed, so + * root->reloc_root may not be set, return ENOENT in this case. + */ + if (!root) return ERR_PTR(-ENOENT); + + if (next->new_bytenr) { + /* + * We just created the reloc root, so we shouldn't have + * ->new_bytenr set yet. If it is then we have multiple + * roots pointing at the same bytenr which indicates + * corruption, or we've made a mistake in the backref + * walking code. + */ + ASSERT(next->new_bytenr == 0); + btrfs_err(trans->fs_info, + "bytenr %llu possibly has multiple roots pointing at the same bytenr %llu", + node->bytenr, next->bytenr); + return ERR_PTR(-EUCLEAN); } + next->new_bytenr = root->node->start; + btrfs_put_root(next->root); + next->root = btrfs_grab_root(root); + ASSERT(next->root); + mark_block_processed(rc, next); +found: next = node; /* setup backref node path for btrfs_reloc_cow_block */ while (1) { From patchwork Thu Oct 3 15:43:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13821182 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 328ED1A76B5 for ; Thu, 3 Oct 2024 15:43:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970208; cv=none; b=ED6G69rcpgC/As12SNr5dfsh9JuuZO+93KvR8rbwxhObSgkjwuVqhNZffc4mRtwcxLqohyuWg5vRA8rZe1Y7X3SpLCuzYFObJc8oOqgr4yLdLX3cBvAeMuZXbzE/twyVbRccKhOCSi/rUP1qY8r0wssRRs6HhkwDAu7DSbFdGkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970208; c=relaxed/simple; bh=R0JhbifZVieTJpVINcFJY19S3egy1wQ4r1QSogH6fLE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m7Y4EdsKEhw5by1cAbjK16AXyMlx+iVrNtSBTixzeVIF1ieF9TMcB3+C4tMqvgw7EzuNe9IzoVj1JEbaLoYaSFLrsdwXyiu+jkXTNgZLlwBlSXIngZXrpLNt3OKJcxSi8v8JeY5HpPhhZdTmZzdjUQxDApccvFsjN8A5QyMgXMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=q7TzmETC; arc=none smtp.client-ip=209.85.222.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="q7TzmETC" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7a9ae8fc076so114167585a.2 for ; Thu, 03 Oct 2024 08:43:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1727970206; x=1728575006; darn=vger.kernel.org; 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=KhJDB34ReB7dQ/Cso5qNIuVekLq2Z2xP/+XXr3qWEr4=; b=q7TzmETCUFmOyPs1vEBKglLD5s4zveej7SESeihfnlVpmicaHrtT/7sw2eM4GMpX+s WhsXRc7eKCKAjI5hWuxbuZ99JqQ05I1rDn4lXsswA/IuMh6KRwRD+7ieYPcstUSMMQTn ZKEeWJwgatQCZEUdOvOrN/RQwwsJujA2Gawx4k7NOrATnG/FS68NUTxmBgVkV8uxOfWZ usXuGd1Jc43vvii4fuyIcKYkCQCDAiGMhZwVIP1wxG2Fh+YG0jzibS2+tXQCa9hpRSYP xbU5K0h1k5ifyXN1KpiLxxAoXXVsOMY8zxtLqNO3dTIZPf92crXRaDiGj0IvmcsKiDUq 4p5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727970206; x=1728575006; 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=KhJDB34ReB7dQ/Cso5qNIuVekLq2Z2xP/+XXr3qWEr4=; b=m7ys9CL8O+QKY7u5j+i+Dn3a0nSCNUd/CXiLzWCKpE9RWpKfiYcL+I4fMB/nWTHlAL CWx6Oji4NE9z0gMd+JxeaQc8BQUh7FAQaiGC0oQVBgPVyn9wZUqa18Hd5DhAYApFjMtL tfjBrAxNmCPml+0ygyW4oS7W2ATQ7LilNqr2NqLh5UlHjgzK8TwUwF6/c0FQl8DqjSDO GfwW7jlKbZBL62zTFGubo6R1ojo4hEjRjmQXk/yp9+XdAfZl3pyvQcSLYGaB34rAnFHp WN0YsCiW/NJ3yQ24YSXrqfAo7jPWICsTDMFPdLgzMG7Cc2DV0ep1yntGTRRsrhpR1lBJ Aq1w== X-Gm-Message-State: AOJu0YwGgZUw/ycmEDvuCSgp1+4fFResKD2eurX8nzWT42LTDsgRLtm3 q0/kJxS9vKvT/UtprABfP0LssTU76gPpQC4VcR2ebp5g1kfW7U3JYUcJklAyRTKFMEGMZg2SoBR T X-Google-Smtp-Source: AGHT+IEu9HrD2X/GNOroYXnWZn48Om4QT4ecwvuB92VbTAEQyTRU/N3XFFOHYb0KRq9tEc6ZZspnXA== X-Received: by 2002:a05:620a:470c:b0:7a9:bc46:2d13 with SMTP id af79cd13be357-7ae626ac2e3mr1174284685a.7.1727970205757; Thu, 03 Oct 2024 08:43:25 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7ae6b29e3f8sm60207085a.17.2024.10.03.08.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 08:43:25 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 05/10] btrfs: remove clone_backref_node Date: Thu, 3 Oct 2024 11:43:07 -0400 Message-ID: <19a6a6da2ff2bd5a9b55b1e5fbccec346f7daa3a.1727970063.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since we no longer maintain backref cache across transactions, and this is only called when we're creating the reloc root for a newly created snapshot in the transaction critical section, we will end up doing a bunch of work that will just get thrown away when we start the transaction in the relocation loop. Delete this code as it no longer does anything for us. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 91 +------------------------------------------ 1 file changed, 1 insertion(+), 90 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 6b2308671d83..7de94e55234c 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -469,92 +469,6 @@ static noinline_for_stack struct btrfs_backref_node *build_backref_tree( return node; } -/* - * helper to add backref node for the newly created snapshot. - * the backref node is created by cloning backref node that - * corresponds to root of source tree - */ -static int clone_backref_node(struct btrfs_trans_handle *trans, - struct reloc_control *rc, - const struct btrfs_root *src, - struct btrfs_root *dest) -{ - struct btrfs_root *reloc_root = src->reloc_root; - struct btrfs_backref_cache *cache = &rc->backref_cache; - struct btrfs_backref_node *node = NULL; - struct btrfs_backref_node *new_node; - struct btrfs_backref_edge *edge; - struct btrfs_backref_edge *new_edge; - struct rb_node *rb_node; - - rb_node = rb_simple_search(&cache->rb_root, src->commit_root->start); - if (rb_node) { - node = rb_entry(rb_node, struct btrfs_backref_node, rb_node); - if (node->detached) - node = NULL; - else - BUG_ON(node->new_bytenr != reloc_root->node->start); - } - - if (!node) { - rb_node = rb_simple_search(&cache->rb_root, - reloc_root->commit_root->start); - if (rb_node) { - node = rb_entry(rb_node, struct btrfs_backref_node, - rb_node); - BUG_ON(node->detached); - } - } - - if (!node) - return 0; - - new_node = btrfs_backref_alloc_node(cache, dest->node->start, - node->level); - if (!new_node) - return -ENOMEM; - - new_node->lowest = node->lowest; - new_node->checked = 1; - new_node->root = btrfs_grab_root(dest); - ASSERT(new_node->root); - - if (!node->lowest) { - list_for_each_entry(edge, &node->lower, list[UPPER]) { - new_edge = btrfs_backref_alloc_edge(cache); - if (!new_edge) - goto fail; - - btrfs_backref_link_edge(new_edge, edge->node[LOWER], - new_node, LINK_UPPER); - } - } else { - list_add_tail(&new_node->lower, &cache->leaves); - } - - rb_node = rb_simple_insert(&cache->rb_root, new_node->bytenr, - &new_node->rb_node); - if (rb_node) - btrfs_backref_panic(trans->fs_info, new_node->bytenr, -EEXIST); - - if (!new_node->lowest) { - list_for_each_entry(new_edge, &new_node->lower, list[UPPER]) { - list_add_tail(&new_edge->list[LOWER], - &new_edge->node[LOWER]->upper); - } - } - return 0; -fail: - while (!list_empty(&new_node->lower)) { - new_edge = list_entry(new_node->lower.next, - struct btrfs_backref_edge, list[UPPER]); - list_del(&new_edge->list[UPPER]); - btrfs_backref_free_edge(cache, new_edge); - } - btrfs_backref_free_node(cache, new_node); - return -ENOMEM; -} - /* * helper to add 'address of tree root -> reloc tree' mapping */ @@ -4484,10 +4398,7 @@ int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans, return ret; } new_root->reloc_root = btrfs_grab_root(reloc_root); - - if (rc->create_reloc_tree) - ret = clone_backref_node(trans, rc, root, reloc_root); - return ret; + return 0; } /* From patchwork Thu Oct 3 15:43:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13821183 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8F781AAE10 for ; Thu, 3 Oct 2024 15:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970210; cv=none; b=SlZZ1aqPGdfv5luiJ8RzSRQ7wW8JDhK3XjNZG2FyoK5x4ZWWmrTOjfGfwt+FO4HAxfcm7XHU1uPuRsVGV+iLyPqjkcRyl4KmevJazjZLo3EPOuzc/t0bsKg6RzEiA0lmTTcy70XPh6h3MeHRUFP+ZcaD/6b2bWtZZhjhx3X8iaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970210; c=relaxed/simple; bh=V24IqdDBUYn2fM6CVto6YgnppgMse5k/u1p/OwFGx7E=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EoMXKI82BW7uSp2wdOXR67+LXkLIPtdMogZcRb8wGhHJbqAu1yj4gphbGmYo5b+aMxAwHH4MZgo2umTb/iFR6hGRHvfwV0ldl3ihZ61H0fM9Mhy3ZkWdFx33iMYscVP17gnCLVNbV47KnatcTuciNS1E80+L9IOyrsPAKhsFgjU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=uTDSbkQW; arc=none smtp.client-ip=209.85.128.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="uTDSbkQW" Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-6e21ac45b70so9703247b3.1 for ; Thu, 03 Oct 2024 08:43:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1727970207; x=1728575007; darn=vger.kernel.org; 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=rhx3NGH5C3TspfJhJ+Fa6gcCNwulVq5I0DMntDidSMk=; b=uTDSbkQWB4uyUP/AH0YKIduoaF5CiQFxgU4SG6mMpsgL6aixvWppzdX3l0JC4mOYj4 rkrGUjqfSJnWmn2qZQzL1D0zrx87l9iJw/4SCGw9eWb2022vWTVTzZFfE2llNp63gmRc 4Gj+C8IpT8v1vD2ntdcKDtU3O51wLgJdHgP7WG7I5kh3UM1pOTR5mX6Pm7VTmriXJoR4 fNksSb8iGJBXaffjSg6lMtK9mubqmBKtLnfycuxSnr+mxdh9mdiy2yJqSn+bMynkyxjZ qZCS1rd2357MOlaEF4DquWzmrNADgu33fzYFJm2pgxrvNRRA4V9XlJNGg0vFkxbW1iz4 eyiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727970207; x=1728575007; 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=rhx3NGH5C3TspfJhJ+Fa6gcCNwulVq5I0DMntDidSMk=; b=XgMiqO+AhnlSY2YXqm5DrEyK1WdH9nk0TU1EEzs/wypYW5AQh3TcfI8r7TfwTsT52a mxECy9TlpUgJYyeVpBbY+gl4Te3hMn0SEhvH2eXo5sPpgJcyK7sZ+sAThm4+n43jBk/n /E7GGAtn5OJWA2mCVoHHIwN8wFhOkXG6h7UAMt/sb8MUKFvdeCJcyYzUx6lH6m+Reknf PnxlF2O23gh655H5uDEr09BcZ99bMc/BL/k5EjotVD5OK+/PO28B6mXOBEBX2xG8kKkz enQnFCswwkXldCf/bW502Lr1MqwKW0qE9w1VMaaYd5aM8zvnrygGs+PLOTyAtsQSegcE uFQg== X-Gm-Message-State: AOJu0YxXbGenb6gyeVlFb9DBfc0fuzlyWjrnkBkF1o5Xa1jBfpAE3tbk heuEy07fDDVkWOZSb6RI00gAtniHVSKR7mZjv7B2/iOlCk0lAvbQb01SYfxTyduCYYMopQt/iCF z X-Google-Smtp-Source: AGHT+IHy4vQ50hubOvToBMFsuahUqF52FDe5zhgYKxA4xZHGvZ2LS0neksMgQyxD6RkJ2y43lj8glg== X-Received: by 2002:a05:690c:6710:b0:6b1:735c:a2fc with SMTP id 00721157ae682-6e2a2b61896mr70489007b3.27.1727970207320; Thu, 03 Oct 2024 08:43:27 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6cb937d1b86sm7506636d6.77.2024.10.03.08.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 08:43:26 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 06/10] btrfs: don't build backref tree for cowonly blocks Date: Thu, 3 Oct 2024 11:43:08 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We already determine the owner for any blocks we find when we're relocating, and for cowonly blocks (and the data reloc tree) we cow down to the block and call it good enough. However we still build a whole backref tree for them, even though we're not going to use it, and then just don't put these blocks in the cache. Rework the code to check if the block belongs to a cowonly root or the data reloc root, and then just cow down to the block, skipping the backref cache generation. Signed-off-by: Josef Bacik --- fs/btrfs/relocation.c | 89 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 7de94e55234c..db5f6bda93c9 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2136,17 +2136,11 @@ static noinline_for_stack u64 calcu_metadata_size(struct reloc_control *rc, return num_bytes; } -static int reserve_metadata_space(struct btrfs_trans_handle *trans, - struct reloc_control *rc, - struct btrfs_backref_node *node) +static int refill_metadata_space(struct btrfs_trans_handle *trans, + struct reloc_control *rc, u64 num_bytes) { - struct btrfs_root *root = rc->extent_root; - struct btrfs_fs_info *fs_info = root->fs_info; - u64 num_bytes; + struct btrfs_fs_info *fs_info = trans->fs_info; int ret; - u64 tmp; - - num_bytes = calcu_metadata_size(rc, node) * 2; trans->block_rsv = rc->block_rsv; rc->reserved_bytes += num_bytes; @@ -2159,7 +2153,7 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans, ret = btrfs_block_rsv_refill(fs_info, rc->block_rsv, num_bytes, BTRFS_RESERVE_FLUSH_LIMIT); if (ret) { - tmp = fs_info->nodesize * RELOCATION_RESERVED_NODES; + u64 tmp = fs_info->nodesize * RELOCATION_RESERVED_NODES; while (tmp <= rc->reserved_bytes) tmp <<= 1; /* @@ -2177,6 +2171,16 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans, return 0; } +static int reserve_metadata_space(struct btrfs_trans_handle *trans, + struct reloc_control *rc, + struct btrfs_backref_node *node) +{ + u64 num_bytes; + + num_bytes = calcu_metadata_size(rc, node) * 2; + return refill_metadata_space(trans, rc, num_bytes); +} + /* * relocate a block tree, and then update pointers in upper level * blocks that reference the block to point to the new location. @@ -2528,15 +2532,11 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, node->root = btrfs_grab_root(root); ASSERT(node->root); } else { - path->lowest_level = node->level; - if (root == root->fs_info->chunk_root) - btrfs_reserve_chunk_metadata(trans, false); - ret = btrfs_search_slot(trans, root, key, path, 0, 1); - btrfs_release_path(path); - if (root == root->fs_info->chunk_root) - btrfs_trans_release_chunk_metadata(trans); - if (ret > 0) - ret = 0; + btrfs_err(root->fs_info, + "bytenr %llu resolved to a non-shareable root", + node->bytenr); + ret = -EUCLEAN; + goto out; } if (!ret) update_processed_blocks(rc, node); @@ -2549,6 +2549,43 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, return ret; } +static noinline_for_stack +int relocate_cowonly_block(struct btrfs_trans_handle *trans, + struct reloc_control *rc, struct tree_block *block, + struct btrfs_path *path) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_root *root; + u64 num_bytes; + int nr_levels; + int ret; + + root = btrfs_get_fs_root(fs_info, block->owner, true); + if (IS_ERR(root)) + return PTR_ERR(root); + + nr_levels = max(btrfs_header_level(root->node) - block->level, 0) + 1; + + num_bytes = fs_info->nodesize * nr_levels; + ret = refill_metadata_space(trans, rc, num_bytes); + if (ret) { + btrfs_put_root(root); + return ret; + } + path->lowest_level = block->level; + if (root == root->fs_info->chunk_root) + btrfs_reserve_chunk_metadata(trans, false); + ret = btrfs_search_slot(trans, root, &block->key, path, 0, 1); + path->lowest_level = 0; + btrfs_release_path(path); + if (root == root->fs_info->chunk_root) + btrfs_trans_release_chunk_metadata(trans); + if (ret > 0) + ret = 0; + btrfs_put_root(root); + return ret; +} + /* * relocate a list of blocks */ @@ -2588,6 +2625,20 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans, /* Do tree relocation */ rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) { + /* + * For cowonly blocks, or the data reloc tree, we only need to + * cow down to the block, there's no need to generate a backref + * tree. + */ + if (block->owner && + (!is_fstree(block->owner) || + block->owner == BTRFS_DATA_RELOC_TREE_OBJECTID)) { + ret = relocate_cowonly_block(trans, rc, block, path); + if (ret) + break; + continue; + } + node = build_backref_tree(trans, rc, &block->key, block->level, block->bytenr); if (IS_ERR(node)) { From patchwork Thu Oct 3 15:43:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13821184 Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EA1919C54F for ; Thu, 3 Oct 2024 15:43:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970211; cv=none; b=YGV7dzsC2MDfvCowAlIxpr7FHtMdogFaUk0IBWcka+mr9C4f/ID8mGPl4d6xNHDnmKVlpiULjWtfxJLn3PXNFap+SlLNXhMy4Ggte5l2NjElyrP5NT9AyKpaFlu3/U8uZfjOSQebgUB9Nv4qqo7oBcvmSxCI8FHUxXgYFKQCLNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970211; c=relaxed/simple; bh=I59iBGAsHrSKibdMRzIn8wAX874FGgPIa9VBmNHUJWg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dOrb7E1n0v/RR7HPHavWMPij18CfX0HNzn9Oyk7VOExrUQGY3iq+UTei62IIQLcxyVkEZ6/JH+ZVIJZbPiHi57ArfDiJMNKShyMslyfA8Qjmop/BMuw6j7NI/UBgcxIJDbJT2kYghzaoOqcHut0k0jAtWHACPueYp7cXu/QgHmk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=Kc844qN3; arc=none smtp.client-ip=209.85.161.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="Kc844qN3" Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5e5568f1baaso565881eaf.2 for ; Thu, 03 Oct 2024 08:43:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1727970209; x=1728575009; darn=vger.kernel.org; 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=ASkxMtmiEpJxg83Wz3eOxS/S1cbVACE0l9mdDOdbESk=; b=Kc844qN3BYhgbwW23p8qQiTndUc+oGBwP3VNnUB6+c9btJXEsZmW2ywni/DCmnIhq+ 8fSGQo6FW1Naf5SjOZfZ146UN/68W1oPwTFHCnDMmy4LB2a57/8bAyueGvQmurJDrowW dhUCWhpz8/HhVtvwslWYq7QzCnWRFTcj4LxRKwaJDZcWsJLWLgBNYRC+tq1hrqbmNCQ7 T7yqDBhiXtGJAImC82EKoot+/iqnti6yaeek1WrsNPRTlbKfJddS+HhTGso4Jj74mW2T BsIP/zRiszBwyO2vflWy+0+4SoPipZRsnrKzGSMaO8iMC0Tn08ZOW/HwKAF9iPauS+5o CqyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727970209; x=1728575009; 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=ASkxMtmiEpJxg83Wz3eOxS/S1cbVACE0l9mdDOdbESk=; b=ZU8N5Uq8hiz3PLh1yPPaZiVhCDNCML9wEd+1sfPwizONEvuexaWZGaElUmNPw+3tx/ RUHdb8dpMbqyhqeaDSFwKCruySIG3OvnlXqdT3Bt2nibW+kedjyIsdAIavApV5CGs4RF myDE2AemLP6cKz1gnAV/FZxsyCYoSXzhwzsFtPSBwDJMKOp0eGaBLsGmcyN4hHo7Rz1h LY1miZj6nvoAfBst3hKXczxn8tWsJ+RVwuQjapqoYyy4CI+KdmRNtCU6bR/Poj7PFs9c aumzC3GkHoTQwoeG6OYJd2+jonePLGcT/OJpVwA3qFP4OOsLyVxUv6e/XthBx+rpiPES OPtA== X-Gm-Message-State: AOJu0YyS0QY0HL9HJ3JGZzGB9CZ/oQCtexQC5g2D5ZPcDlOPbm5i8I4y i46hD7gWV1HcKtP1rg6fc3yb35UYZNSpjCR4oV/sUTap8/lunCcU/IrfsnPMGFvbJlegqewcreo J X-Google-Smtp-Source: AGHT+IFRBusUy4M/8ZtJ0mwQPEKGYiozagmtAPJFEQ7kBZQLXLhc+/Ma/nU2O6WsaCszXRDus2hA+w== X-Received: by 2002:a05:6359:5f8c:b0:1b1:a666:2bba with SMTP id e5c5f4694b2df-1c0cee929edmr543286055d.24.1727970208921; Thu, 03 Oct 2024 08:43:28 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7ae6b3d3d19sm59580985a.84.2024.10.03.08.43.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 08:43:28 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 07/10] btrfs: do not handle non-shareable roots in backref cache Date: Thu, 3 Oct 2024 11:43:09 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that we handle relocation for non-shareable roots without using the backref cache, remove the ->cowonly field from the backref nodes and update the handling to throw an ASSERT()/error. Signed-off-by: Josef Bacik --- fs/btrfs/backref.c | 62 ++++++++++++++++++++++++------------------- fs/btrfs/backref.h | 2 -- fs/btrfs/relocation.c | 2 +- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 881bb5600b55..9c011ccd7209 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -3313,8 +3313,16 @@ static int handle_indirect_tree_backref(struct btrfs_trans_handle *trans, root = btrfs_get_fs_root(fs_info, ref_key->offset, false); if (IS_ERR(root)) return PTR_ERR(root); - if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) - cur->cowonly = 1; + + /* + * We shouldn't be using backref cache for non shareable roots, ASSERT + * for developers, return -EUCLEAN for users. + */ + if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) { + btrfs_put_root(root); + ASSERT(0); + return -EUCLEAN; + } if (btrfs_root_level(&root->root_item) == cur->level) { /* Tree root */ @@ -3400,8 +3408,20 @@ static int handle_indirect_tree_backref(struct btrfs_trans_handle *trans, goto out; } upper->owner = btrfs_header_owner(eb); - if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) - upper->cowonly = 1; + + /* + * We shouldn't be using backref cache for non shareable + * roots, ASSERT for developers, return -EUCLEAN for + * users. + */ + if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) { + btrfs_put_root(root); + btrfs_backref_free_edge(cache, edge); + btrfs_backref_free_node(cache, upper); + ASSERT(0); + ret = -EUCLEAN; + goto out; + } /* * If we know the block isn't shared we can avoid @@ -3592,15 +3612,12 @@ int btrfs_backref_finish_upper_links(struct btrfs_backref_cache *cache, ASSERT(start->checked); - /* Insert this node to cache if it's not COW-only */ - if (!start->cowonly) { - rb_node = rb_simple_insert(&cache->rb_root, start->bytenr, - &start->rb_node); - if (rb_node) - btrfs_backref_panic(cache->fs_info, start->bytenr, - -EEXIST); - list_add_tail(&start->lower, &cache->leaves); - } + rb_node = rb_simple_insert(&cache->rb_root, start->bytenr, + &start->rb_node); + if (rb_node) + btrfs_backref_panic(cache->fs_info, start->bytenr, + -EEXIST); + list_add_tail(&start->lower, &cache->leaves); /* * Use breadth first search to iterate all related edges. @@ -3654,23 +3671,14 @@ int btrfs_backref_finish_upper_links(struct btrfs_backref_cache *cache, return -EUCLEAN; } - /* Sanity check, COW-only node has non-COW-only parent */ - if (start->cowonly != upper->cowonly) { - ASSERT(0); + rb_node = rb_simple_insert(&cache->rb_root, upper->bytenr, + &upper->rb_node); + if (rb_node) { + btrfs_backref_panic(cache->fs_info, + upper->bytenr, -EEXIST); return -EUCLEAN; } - /* Only cache non-COW-only (subvolume trees) tree blocks */ - if (!upper->cowonly) { - rb_node = rb_simple_insert(&cache->rb_root, upper->bytenr, - &upper->rb_node); - if (rb_node) { - btrfs_backref_panic(cache->fs_info, - upper->bytenr, -EEXIST); - return -EUCLEAN; - } - } - list_add_tail(&edge->list[UPPER], &upper->lower); /* diff --git a/fs/btrfs/backref.h b/fs/btrfs/backref.h index 754c71bdc9ce..6c27c070025a 100644 --- a/fs/btrfs/backref.h +++ b/fs/btrfs/backref.h @@ -341,8 +341,6 @@ struct btrfs_backref_node { struct extent_buffer *eb; /* Level of the tree block */ unsigned int level:8; - /* Is the block in a non-shareable tree */ - unsigned int cowonly:1; /* 1 if no child node is in the cache */ unsigned int lowest:1; /* Is the extent buffer locked */ diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index db5f6bda93c9..507fcc3f56e6 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2544,7 +2544,7 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, ret = do_relocation(trans, rc, node, key, path, 1); } out: - if (ret || node->level == 0 || node->cowonly) + if (ret || node->level == 0) btrfs_backref_cleanup_node(&rc->backref_cache, node); return ret; } From patchwork Thu Oct 3 15:43:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13821185 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D76F61AAE16 for ; Thu, 3 Oct 2024 15:43:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970213; cv=none; b=sY6A6moXFZkO/xiGOvtnDmC+ar2HPLrRM6EMIVrHavdUqpSVt4By8nA2aYftSqOr9Z34ah55bxzTYrk3ezFOYju+17jmZrSR8aN2TynMEciNFzMzUwqXL0uRKrwsfvfUiJSibfC1UcwuNos7Fel58diRk3cDOjMLCfI4Dck3hoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970213; c=relaxed/simple; bh=Lk4wDPgCaqJdBkq4KjXEaWvM8/p5eXEcoYEqgLXSWDU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MutPwDh04g6LUUezl0t+knTVLXhqQz6W+FsaA1zIJpp1JGwcRruvW3Kys+vGeUdnsG2bToHkj2oneddDtByA/PgMeOximcHsJnDfuhT+ajgIsFUPptTq+JIbajwk+8n1wsnyGeoZY2xEU1X72Wdktb6C9jibgUg6JPMpVowYinw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=UipRfLA+; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="UipRfLA+" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-7a99eee4a5bso83225785a.0 for ; Thu, 03 Oct 2024 08:43:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1727970210; x=1728575010; darn=vger.kernel.org; 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=U2vw2q9Lj3ia4Ysl9JdLS/BhRI3oAC18Kr8Zfp6lBUg=; b=UipRfLA+bIivFNfxwOZRJxyidIz5fLhgiUcYFsSTaocbMyafnCeIU1GSBIPHUjt3KQ SJsuNwBxDXfeMHgevcwi4/kyriDagDUvkC6vbBlYEJVgXFCQcSrGdFU3DCxzd5nnbdH+ UFQJa/XZavTO9yZEVTSOs5VJUJ4zhKPpN6P3bCiU75mmGL/q9+XIvvbGK+l+vj5kFhHZ Gw7XVSw65z+oSTMtrN0vYoaa9vCsZymDPfQguNck/QIZYz/SYjO1oq7ht2novWmSzShM CwtbnRaJ0DXPGdZ7x9PtV17pBD8s0zmSSmpVBmupitlfVqS53NbcDUVc9+zgWAx9zqsN W8oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727970210; x=1728575010; 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=U2vw2q9Lj3ia4Ysl9JdLS/BhRI3oAC18Kr8Zfp6lBUg=; b=Fq4qsnCJNFDk74n+2V2tEJddeXnftAV05lTonmGhAvuyDoQVtlsv8W4n5TCbaX+b1s 99ZGuBXUaWftsttw5Zqa6SQJmkL3+j6bIgAO7ttDJ0cGfv3sRiHyShjOoxRyb70kbpnl c03q+YKHAFxHGYIxsx2DX7+tcmRBKCqh2VusnkCCGo2lWf/r6iN2AcTaBwMtvOJVlKuP 1pHwpETN18RheqqRF/7KumQgplaKGUi5VJiex89CYH0/UudHjHW7Jl+epW+nf+/hSJIm 0tMW34YU8U746zEUR9ggPES0BBDelCYrm9CFuub6ld+rMgkkmepGJFYkLY1kNU8+ifY2 PzOA== X-Gm-Message-State: AOJu0Yxq8biRT5Clmll2LWD8FiuXIQlptCvjERKRb03CengcTFWpKjKb /77Vmq5iEXU7080fSq+mNsNYn/P85BnfIbP7Zmv1IVGV7X850Risk4NkjF1LH5GkPiLOv52IVrN T X-Google-Smtp-Source: AGHT+IGv3vFMRd5ChFRbvLLErvHCyCQ6uNo/O2kR+CvtlbrpMhS4ss5YbhMWequW7MWIeauHVL2Qjw== X-Received: by 2002:a05:620a:4004:b0:7a3:524f:7ef7 with SMTP id af79cd13be357-7ae626b23ccmr924779285a.12.1727970210526; Thu, 03 Oct 2024 08:43:30 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7ae6b3d55basm60076185a.86.2024.10.03.08.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 08:43:29 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 08/10] btrfs: simplify btrfs_backref_release_cache Date: Thu, 3 Oct 2024 11:43:10 -0400 Message-ID: <4f7e20a5e41c837f05cc88f3f2e4942ca18f8154.1727970063.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We rely on finding all our nodes on the various lists in the backref cache, when they are all also in the rbtree. Instead just search through the rbtree and free everything. Signed-off-by: Josef Bacik --- fs/btrfs/backref.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 9c011ccd7209..a7462d7f2531 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -3164,32 +3164,14 @@ void btrfs_backref_cleanup_node(struct btrfs_backref_cache *cache, void btrfs_backref_release_cache(struct btrfs_backref_cache *cache) { struct btrfs_backref_node *node; - int i; - while (!list_empty(&cache->detached)) { - node = list_entry(cache->detached.next, - struct btrfs_backref_node, list); + while ((node = rb_entry_safe(rb_first(&cache->rb_root), + struct btrfs_backref_node, rb_node))) btrfs_backref_cleanup_node(cache, node); - } - while (!list_empty(&cache->leaves)) { - node = list_entry(cache->leaves.next, - struct btrfs_backref_node, lower); - btrfs_backref_cleanup_node(cache, node); - } - - for (i = 0; i < BTRFS_MAX_LEVEL; i++) { - while (!list_empty(&cache->pending[i])) { - node = list_first_entry(&cache->pending[i], - struct btrfs_backref_node, - list); - btrfs_backref_cleanup_node(cache, node); - } - } ASSERT(list_empty(&cache->pending_edge)); ASSERT(list_empty(&cache->useless_node)); ASSERT(list_empty(&cache->detached)); - ASSERT(RB_EMPTY_ROOT(&cache->rb_root)); ASSERT(!cache->nr_nodes); ASSERT(!cache->nr_edges); } From patchwork Thu Oct 3 15:43:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13821186 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A7D11AB522 for ; Thu, 3 Oct 2024 15:43:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970214; cv=none; b=Pm4HWhiE086o24RJuzOib+nqRALcfJS8iAL4YlEwk10PBnzPb05i0gM2VY6EmidZ88FKv5LLzfUHvnekcB4iI+EVpnN1bR0Ij+FEmaLf+rX+tHFlVAUm+Z2BYhITAExMO3rgUePnVyaTdHgvG53oTNn6MpW4KaV6tVVU/jMaK1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970214; c=relaxed/simple; bh=SmO24r4D/24sLPqKI8euNDgKL7G5ZQuKKA4EjRnLq8g=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=svqIZZWELT107bh9n1Bh2cO61wmlnz/RIwaOwlS/fN+yess+8Cfebq1WDwp8LMHdLQRfcsirZnflrCIjTFbtRjB1uJ1hZYiHjOKdkqBBPMtW6AyD0nRz5H5cSaiCWcyz5CSXIWN/3C4CYjRmqpm6UvBLwMGzbiIANxJfL0GNrds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=kV1y60cM; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="kV1y60cM" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-7a9af813f6cso95058785a.3 for ; Thu, 03 Oct 2024 08:43:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1727970212; x=1728575012; darn=vger.kernel.org; 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=Q+5SgY6eSSkSzB7yxei3Tn7MALUZ5NKccDpnwrg0yUs=; b=kV1y60cMg51TnCsPBq7TEL3WrsjY67fGreisWQHM/OzBrN/IR1EobLkZhYLHmqxX/L z9xkcXdeeGdRZHqlYB9m/PxWiIpAK+pqc6Jx7YDdqPUmBRMahp37DL27HBDzZrreLWHb 64VWKbrsHmcmZuj6wRHsuXJnB35t45grCwNHRZ2LfTgqGeuHeSpngHNbrNwZtvV9MxZ7 oJWwp8RT7Lkeol9vVwhfLDXBGbl0y0Oe6cWeFhTqn5LVoNWw7Nzp2UQQqsx9wHD3dkMT kskp/mMG5lZlPiXpT/RMKBHb0MdHT4LsLrSZ5pWZwo/NHZkmgaOawe0B9Pzkg0Sg5IKK 1E7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727970212; x=1728575012; 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=Q+5SgY6eSSkSzB7yxei3Tn7MALUZ5NKccDpnwrg0yUs=; b=Hc43PhB/CaeGk+5N6cqGHtjVQxObxDJJracDUnQSJX/nOVQ3f7ZUI7ag/zv5mvP5Cg fg58YP5+VOLPYBA3XeW23V0HcpWq6atcq0IFKjI8AXPdFYBKIF4JuNgUpdDv7ciSIODp BvXLAH+tJ6N5T5Bazl00qKeDkB/Xz9WNbwsDl7OBcJY7Tw6HnWLReNEniuhHAWqwq9qM a7N49Mrn14XZksBp9JB+l+Uy6kxjh9rk3q6trJGqjDWE44HF9uDj/YGmsfr3MW5UGVSu d3mHd0zUu8p96yFP1Es5bPk4BNXCn5AA0va0sybExHzr10Cgf1YHi6V1mzHskmCAnNAb A98Q== X-Gm-Message-State: AOJu0YyewRLmLpojnEHZn6DNtSVCv3t7/D5NaJODWBdnNJTlXN7nxJyn KeLIGjqR5svnWnXrrPrOkzDVRMh0Qf93Xr8m+zdkCzTN4KuOEz0hJL+3PeaL0SadDRCtnvAgNH+ a X-Google-Smtp-Source: AGHT+IER3caYw6PmOVv6UmiGMvY1zJ35IgGbZShYLQ/03F59R274GvBOXoatCRSClM8Oj6GsEbRfaw== X-Received: by 2002:a05:620a:2496:b0:7ac:e879:1a20 with SMTP id af79cd13be357-7ae626af7d1mr1177321285a.1.1727970211958; Thu, 03 Oct 2024 08:43:31 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7ae6b3dc587sm59683685a.111.2024.10.03.08.43.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 08:43:31 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 09/10] btrfs: remove the ->lowest and ->leaves members from backref cache Date: Thu, 3 Oct 2024 11:43:11 -0400 Message-ID: <28f56ec3b86951cdae8fa94822bda7a898f6ffbc.1727970063.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Before we were keeping all of our nodes on various lists in order to make sure everything got cleaned up correctly. We used node->lowest to indicate that node->lower was linked into the cache->leaves list. Now that we do cleanup based on the rb tree both the list and the flag are useless, so delete them both. Signed-off-by: Josef Bacik --- fs/btrfs/backref.c | 19 ------------------- fs/btrfs/backref.h | 4 ---- fs/btrfs/relocation.c | 7 ------- 3 files changed, 30 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index a7462d7f2531..5e7d41a8efdb 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -3022,7 +3022,6 @@ void btrfs_backref_init_cache(struct btrfs_fs_info *fs_info, for (i = 0; i < BTRFS_MAX_LEVEL; i++) INIT_LIST_HEAD(&cache->pending[i]); INIT_LIST_HEAD(&cache->detached); - INIT_LIST_HEAD(&cache->leaves); INIT_LIST_HEAD(&cache->pending_edge); INIT_LIST_HEAD(&cache->useless_node); cache->fs_info = fs_info; @@ -3130,29 +3129,17 @@ void btrfs_backref_drop_node(struct btrfs_backref_cache *tree, void btrfs_backref_cleanup_node(struct btrfs_backref_cache *cache, struct btrfs_backref_node *node) { - struct btrfs_backref_node *upper; struct btrfs_backref_edge *edge; if (!node) return; - BUG_ON(!node->lowest && !node->detached); while (!list_empty(&node->upper)) { edge = list_entry(node->upper.next, struct btrfs_backref_edge, list[LOWER]); - upper = edge->node[UPPER]; list_del(&edge->list[LOWER]); list_del(&edge->list[UPPER]); btrfs_backref_free_edge(cache, edge); - - /* - * Add the node to leaf node list if no other child block - * cached. - */ - if (list_empty(&upper->lower)) { - list_add_tail(&upper->lower, &cache->leaves); - upper->lowest = 1; - } } btrfs_backref_drop_node(cache, node); @@ -3599,7 +3586,6 @@ int btrfs_backref_finish_upper_links(struct btrfs_backref_cache *cache, if (rb_node) btrfs_backref_panic(cache->fs_info, start->bytenr, -EEXIST); - list_add_tail(&start->lower, &cache->leaves); /* * Use breadth first search to iterate all related edges. @@ -3638,11 +3624,6 @@ int btrfs_backref_finish_upper_links(struct btrfs_backref_cache *cache, * parents have already been linked. */ if (!RB_EMPTY_NODE(&upper->rb_node)) { - if (upper->lowest) { - list_del_init(&upper->lower); - upper->lowest = 0; - } - list_add_tail(&edge->list[UPPER], &upper->lower); continue; } diff --git a/fs/btrfs/backref.h b/fs/btrfs/backref.h index 6c27c070025a..13c9bc33095a 100644 --- a/fs/btrfs/backref.h +++ b/fs/btrfs/backref.h @@ -341,8 +341,6 @@ struct btrfs_backref_node { struct extent_buffer *eb; /* Level of the tree block */ unsigned int level:8; - /* 1 if no child node is in the cache */ - unsigned int lowest:1; /* Is the extent buffer locked */ unsigned int locked:1; /* Has the block been processed */ @@ -395,8 +393,6 @@ struct btrfs_backref_cache { * level blocks may not reflect the new location */ struct list_head pending[BTRFS_MAX_LEVEL]; - /* List of backref nodes with no child node */ - struct list_head leaves; /* List of detached backref node. */ struct list_head detached; diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 507fcc3f56e6..7fb021dd0e67 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -342,12 +342,6 @@ static bool handle_useless_nodes(struct reloc_control *rc, if (cur == node) ret = true; - /* The node is the lowest node */ - if (cur->lowest) { - list_del_init(&cur->lower); - cur->lowest = 0; - } - /* Cleanup the lower edges */ while (!list_empty(&cur->lower)) { struct btrfs_backref_edge *edge; @@ -426,7 +420,6 @@ static noinline_for_stack struct btrfs_backref_node *build_backref_tree( goto out; } - node->lowest = 1; cur = node; /* Breadth-first search to build backref cache */ From patchwork Thu Oct 3 15:43:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13821187 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A1681AB533 for ; Thu, 3 Oct 2024 15:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970216; cv=none; b=JDUcuwS13JRzl5tLI+w+qpdND/fyb1f7UU05evjXjpeDDKo9f+nS+0cTIj0rnKitVVjwKMHzOXjiqYrYXmQn3yj2An4qPY/7fo1utbNh5CSbFBwhHa+1FYkD7sv18S7E5V0azrftF9YlajpHODYfj5XJWh5rwGX3QHo38aGbfik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727970216; c=relaxed/simple; bh=5FyJ9F7y2B0r5D4V85DtrUmwwKrmFCqX1gC147U9iDo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fdo/QngJ//0r3ccytLoeId8sUOzIUADq0WSo1JsYSxFjFXpDDhNA7T9KCW1u1H7F4mCPlQMG5FQ2zYiu4dLWBoQdMyeA5O8GER+fLWldlkN+9vQSdGqqN0XzHl4j4ZRVl8620X/1FekjRpEQpu2fUYpwZZg0e4UYfrAal8c2aQs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=RD6H29Hu; arc=none smtp.client-ip=209.85.219.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="RD6H29Hu" Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-6cb2dffcdbbso10001426d6.1 for ; Thu, 03 Oct 2024 08:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1727970214; x=1728575014; darn=vger.kernel.org; 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=tDSVkZ2EBt445h2p1JvHxEyE96llUbKZPMr/ondzwG8=; b=RD6H29HuR/t51qWBPLIOc3K5HKmxFod89IkHAxCVM6SEbUHHlm1aWc66Jh+0qsGiUA s8L/HuB39/QByK5dAIHEZw3kMwFILXdwG32XPy/VkNsTTgAy+veoW+hcD3u2OwpbtAMy iI6ahtTSiNmbtI4+FKyMVvwfjijaehpy8k/zJJjKAjbVMZN683AoAJ3wz6V4mA1tugAh 2g/6dlcogEdf/gicVK++XjT6EEslei3T6p2pEX/fnlrGE2an1WuR5eYUb1ZODXJ3zUJb yPB4mEd8h0kxP8C9pxSM3fSEiS9wXYjqcd/Cldguy0AwFp+z//ofjZjfpysB6NM0VI+5 CjaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727970214; x=1728575014; 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=tDSVkZ2EBt445h2p1JvHxEyE96llUbKZPMr/ondzwG8=; b=VC8yLPBnzEDaipceacGoerfJ/JviDcpzaBvWRH2IPjHHmJIHvzW8NqJsL8Kk2gIeAW mv3zXmcFhJI2daWAX+nf3nuPrd89tWXV3Bifewvx3C7BunK3hYaGmYga6Ii6QsH8zpEh C5dWfQj0r/n1+Q+qn4H9m0eXoU/0A0zHNr2V0js63WaZRyhnOaScRALD4uaeD/Xtz0yB //ux5zjLzSsBr01kBy6Ibed520HvjGCZP33JRLgAT0qHAPnHGwjX7TIxaJBPCcmpou+E uMNAvW8t0w3fKeuoUDwr7fsxVphaLsDuzSVCqyM3RefUlUT1taqbgyLach2319bS73Ux qoGQ== X-Gm-Message-State: AOJu0Yx7O53MLp1cuUl1Twjr3vk6owIVS1+8h0vKAh8m9qvJ0UKhj1es zKbyPxk4z/E2dsp4L5kuuQQIp5wJiJeVaecOyuJKG9UEw6wUAsVO+bI1MvFSBUL84Bd1jIDGkcT c X-Google-Smtp-Source: AGHT+IEF16Hu2oy7hTpo4ej+e/e9fLzDGsPNWNITWvGmspoaX4e5XKdDNDjehKT4FuEFvk3P6LHDdQ== X-Received: by 2002:a05:6214:2c08:b0:6cb:7396:ee37 with SMTP id 6a1803df08f44-6cb81bbab15mr117990006d6.42.1727970213726; Thu, 03 Oct 2024 08:43:33 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6cb937d3415sm7482326d6.78.2024.10.03.08.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 08:43:33 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 10/10] btrfs: remove detached list from btrfs_backref_cache Date: Thu, 3 Oct 2024 11:43:12 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We don't ever look at this list, remove it. Signed-off-by: Josef Bacik --- fs/btrfs/backref.c | 2 -- fs/btrfs/backref.h | 2 -- fs/btrfs/relocation.c | 1 - 3 files changed, 5 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 5e7d41a8efdb..a8257755e1d0 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -3021,7 +3021,6 @@ void btrfs_backref_init_cache(struct btrfs_fs_info *fs_info, cache->rb_root = RB_ROOT; for (i = 0; i < BTRFS_MAX_LEVEL; i++) INIT_LIST_HEAD(&cache->pending[i]); - INIT_LIST_HEAD(&cache->detached); INIT_LIST_HEAD(&cache->pending_edge); INIT_LIST_HEAD(&cache->useless_node); cache->fs_info = fs_info; @@ -3158,7 +3157,6 @@ void btrfs_backref_release_cache(struct btrfs_backref_cache *cache) ASSERT(list_empty(&cache->pending_edge)); ASSERT(list_empty(&cache->useless_node)); - ASSERT(list_empty(&cache->detached)); ASSERT(!cache->nr_nodes); ASSERT(!cache->nr_edges); } diff --git a/fs/btrfs/backref.h b/fs/btrfs/backref.h index 13c9bc33095a..2317380d2b1c 100644 --- a/fs/btrfs/backref.h +++ b/fs/btrfs/backref.h @@ -393,8 +393,6 @@ struct btrfs_backref_cache { * level blocks may not reflect the new location */ struct list_head pending[BTRFS_MAX_LEVEL]; - /* List of detached backref node. */ - struct list_head detached; u64 last_trans; diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 7fb021dd0e67..bd86769de66a 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -367,7 +367,6 @@ static bool handle_useless_nodes(struct reloc_control *rc, * cache to avoid unnecessary backref lookup. */ if (cur->level > 0) { - list_add(&cur->list, &cache->detached); cur->detached = 1; } else { rb_erase(&cur->rb_node, &cache->rb_root);