Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8832036E496 for ; Sat, 31 Jan 2026 21:59:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.22 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769896784; cv=none; b=m9F8IBArhSJsqDhKax+mfzodMLT44JbPOZSWYhNMvK5XyOtx1x2/tRwa/WMoB5btz252cvq019BN05PaKVT9wzu4YBonrMqZS2fIxbFfk8sXQM4s5idTsRtAzoro2itb8giiIoJgdh7pJM7hkegv0NiOws98uAi8qNCD+g78u1c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769896784; c=relaxed/simple; bh=11d/MhfCkGYhJwQHHoWid8b78optb2QBnsiAyrNXzps=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=QQXa1g20dj0Ja1iLoBr9PiMn80MiklqBxLjadZsTamCBeCcejRCJ7PRlHjkao1dIklfTTlbagOiDeSBJAMt+80eVkJ9SjjDIkbsE8sxMOEHkAHqMTvkBdxGMxOqa1m8SuIg82V2t+YfxOdOSX/09cN6VZyCjPr7gjYK1AhgBBcc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.com; spf=pass smtp.mailfrom=gmx.com; dkim=pass (2048-bit key) header.d=gmx.com header.i=quwenruo.btrfs@gmx.com header.b=X2m/jtV0; arc=none smtp.client-ip=212.227.17.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.com header.i=quwenruo.btrfs@gmx.com header.b="X2m/jtV0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.com; s=s31663417; t=1769896769; x=1770501569; i=quwenruo.btrfs@gmx.com; bh=0uQ68HfURRU+sagOhSpv9PAVCwENo/MuXeVVKjR13Dw=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:To:Cc: References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=X2m/jtV0Q6aBJKHI7+aZCwVlQKLk8yznsXuRrTpLdGwnKD5P8N0Ap/NEDkSk4lAA ccQe5o+B1G5DEXmHR6uS7LhiCkcB9nnMG8hYMohyMipjNxK2dlzfe1/ppqs2FDLsZ /LGVKHVgH47jc0ImlZr70cLIXbOe7Ypgr7WFtJiKVNDgTVlr6rKyOq638eUx4MZQL aq7D2X8NYYmd1+MtBtTdfmEOFNDP58uOC0H4WqbbP8H65DKERiQOiCHSrR8WDf4Ei +eKTM5uI2pNdxp8Te6R6FQ6kbiKPqXiTnxZ/aoq9sbLF54UOtmg4CchnEkTfhCtkU NnHrV+D4VC1T6dj91w== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [172.16.0.229] ([159.196.52.54]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1Mbir8-1wHmjn0a8E-00b7cj; Sat, 31 Jan 2026 22:59:29 +0100 Message-ID: <2946b081-4016-45e2-9bc2-75a1b7b4dd32@gmx.com> Date: Sun, 1 Feb 2026 08:29:25 +1030 Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] btrfs: prevent COW amplification during btrfs_search_slot To: Boris Burkov Cc: Qu Wenruo , Leo Martins , Filipe Manana , linux-btrfs@vger.kernel.org, kernel-team@fb.com References: <20260130214319.3714908-1-loemra.dev@gmail.com> <4bff1e42-57de-4169-b3c0-a2085182cbb3@suse.com> <20260131001118.GA1432933@zen.localdomain> <94167ea3-8174-4d35-a316-1f9e46fdb988@gmx.com> <20260131171630.GA2030728@zen.localdomain> Content-Language: en-US From: Qu Wenruo Autocrypt: addr=quwenruo.btrfs@gmx.com; keydata= xsBNBFnVga8BCACyhFP3ExcTIuB73jDIBA/vSoYcTyysFQzPvez64TUSCv1SgXEByR7fju3o 8RfaWuHCnkkea5luuTZMqfgTXrun2dqNVYDNOV6RIVrc4YuG20yhC1epnV55fJCThqij0MRL 1NxPKXIlEdHvN0Kov3CtWA+R1iNN0RCeVun7rmOrrjBK573aWC5sgP7YsBOLK79H3tmUtz6b 9Imuj0ZyEsa76Xg9PX9Hn2myKj1hfWGS+5og9Va4hrwQC8ipjXik6NKR5GDV+hOZkktU81G5 gkQtGB9jOAYRs86QG/b7PtIlbd3+pppT0gaS+wvwMs8cuNG+Pu6KO1oC4jgdseFLu7NpABEB AAHNIlF1IFdlbnJ1byA8cXV3ZW5ydW8uYnRyZnNAZ214LmNvbT7CwJQEEwEIAD4CGwMFCwkI BwIGFQgJCgsCBBYCAwECHgECF4AWIQQt33LlpaVbqJ2qQuHCPZHzoSX+qAUCZxF1YAUJEP5a sQAKCRDCPZHzoSX+qF+mB/9gXu9C3BV0omDZBDWevJHxpWpOwQ8DxZEbk9b9LcrQlWdhFhyn xi+l5lRziV9ZGyYXp7N35a9t7GQJndMCFUWYoEa+1NCuxDs6bslfrCaGEGG/+wd6oIPb85xo naxnQ+SQtYLUFbU77WkUPaaIU8hH2BAfn9ZSDX9lIxheQE8ZYGGmo4wYpnN7/hSXALD7+oun tZljjGNT1o+/B8WVZtw/YZuCuHgZeaFdhcV2jsz7+iGb+LsqzHuznrXqbyUQgQT9kn8ZYFNW 7tf+LNxXuwedzRag4fxtR+5GVvJ41Oh/eygp8VqiMAtnFYaSlb9sjia1Mh+m+OBFeuXjgGlG VvQFzsBNBFnVga8BCACqU+th4Esy/c8BnvliFAjAfpzhI1wH76FD1MJPmAhA3DnX5JDORcga CbPEwhLj1xlwTgpeT+QfDmGJ5B5BlrrQFZVE1fChEjiJvyiSAO4yQPkrPVYTI7Xj34FnscPj /IrRUUka68MlHxPtFnAHr25VIuOS41lmYKYNwPNLRz9Ik6DmeTG3WJO2BQRNvXA0pXrJH1fN GSsRb+pKEKHKtL1803x71zQxCwLh+zLP1iXHVM5j8gX9zqupigQR/Cel2XPS44zWcDW8r7B0 q1eW4Jrv0x19p4P923voqn+joIAostyNTUjCeSrUdKth9jcdlam9X2DziA/DHDFfS5eq4fEv ABEBAAHCwHwEGAEIACYCGwwWIQQt33LlpaVbqJ2qQuHCPZHzoSX+qAUCZxF1gQUJEP5a0gAK CRDCPZHzoSX+qHGpB/kB8A7M7KGL5qzat+jBRoLwB0Y3Zax0QWuANVdZM3eJDlKJKJ4HKzjo B2Pcn4JXL2apSan2uJftaMbNQbwotvabLXkE7cPpnppnBq7iovmBw++/d8zQjLQLWInQ5kNq Vmi36kmq8o5c0f97QVjMryHlmSlEZ2Wwc1kURAe4lsRG2dNeAd4CAqmTw0cMIrR6R/Dpt3ma +8oGXJOmwWuDFKNV4G2XLKcghqrtcRf2zAGNogg3KulCykHHripG3kPKsb7fYVcSQtlt5R6v HZStaZBzw4PcDiaAF3pPDBd+0fIKS6BlpeNRSFG94RYrt84Qw77JWDOAZsyNfEIEE0J6LSR/ In-Reply-To: <20260131171630.GA2030728@zen.localdomain> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:usWwQKXlGtMkGGxDFd5yE1y1/1Xf1LdL+qNHsJU1zDVp8933Uvk YfvzdmDBcB8UI9/Sd4RGGQEccy/FudkMfyDS1SXNMqXvI4Ebz35wwSuPvCPOgsCpo+tFq7G l+NYEwxha33xUK7tUcFilLvtRLaAWg+Rvp6UoBP5i819wWhkbwjEcm4DtBx0qVj0MwsymPh vikO5XyACAmU3C0T8L9o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e6o0o468Eb1XWsLCtxNusPMOSjBOy+h8Low= =E5=9C=A8 2026/2/1 03:46, Boris Burkov =E5=86=99=E9=81=93: > On Sat, Jan 31, 2026 at 11:36:54AM +1030, Qu Wenruo wrote: >> >> >> =E5=9C=A8 2026/1/31 10:41, Boris Burkov =E5=86=99=E9=81=93: >>> On Sat, Jan 31, 2026 at 09:04:03AM +1030, Qu Wenruo wrote: >>>> >>>> >>>> =E5=9C=A8 2026/1/31 08:13, Leo Martins =E5=86=99=E9=81=93: >>>>> On Fri, 30 Jan 2026 12:49:55 +0000 Filipe Manana wrote: >>>>> >>>> [...] >>>>> >>>>>> >>>>>> This was before a recent refactoring of should_cow_block(), but you >>>>>> should get the ideia. >>>>>> IIRC all fstests were passing back then, except for one or two whic= h I >>>>>> never spent time debugging. >>>>>> >>>>>> And as that attempt was before the tree checker existed, we would n= eed >>>>>> to make sure we don't change and eb while the tree checker is >>>>>> verifying it - making sure the tree checker read locks the eb shoul= d >>>>>> be enough. >>>> >>>> That may still be racy not just to tree-checker, but with the extent = buffer >>>> writeback path. >>>> >>>> Even we locked the eb for tree-checker, but someone still modified th= e the >>>> eb after tree-checker but before submission, it can still be very >>>> problematic. >>> >>> Agreed that it feels very fishy, like we can write an eb with bad csum= , >>> much like DIO and unstable pages. But do we think it *actually* matter= s? >>> >>> In principle, if I buffered an eb, wrote total garbage to the disk dur= ing >>> the transaction, but then during the commit wrote out the correct eb, = I >>> think that is still OK. If we crash, that bad eb isn't reachable from >>> any root when we mount again, right? >> >> Yes, that's correct, however still I'd prefer a more consistent behavio= r >> that doesn't introduce any bad csum at any timing. >> >> Causing temporary unreachable bad csum seems harmless, but it brings a = much >> bigger opening, that may or may not lead to bad csums for valid tree bl= ocks >> in the future. >> >> [...] >>>> Although before all the new ideas/attempts, I'm wondering the followi= ng two >>>> points: >>>> >>>> - With the AS_KERNEL_FILE flag, how frequent we're re-dirtying COWed = ebs >>>> We need extra benchmarks on this first. >>> >>> As far as I am concerned, any amount more than zero is a bug when you >>> consider it from the perspective of the transaction block_rsv. If you >>> had an 8 deep tree doing splitting, then a single re-cow you didn't pl= an >>> on will use space not in the block_rsv. >> >> I also have one question related to the exhausted block_rsv. >> >> If we COWed a tree block (the old is eb A, older than the current trans= ), >> write the new one (eb B) back to disk, the space of eb A will not be >> available until a full transaction is committed. >> >> But if we need to re-dirty eb B and COW it to eb C, shouldn't the space= of >> eb B be available again? >=20 > Eventually, yes. I think the details depend on exactly what happens with > delayed refs. I haven't looked into this angle super closely yet. >=20 > Unfortunately, Leo and I could not think of a robust way to wire the > re-dirty cows to the block_rsv in a way that does not double dip from > the block_rsv. (See my reply to your next question for why I am so > obsessed with this...) >=20 > How do you tell apart this sequence: > I start a transaction that reserves num_items=3D1 (reserving for <=3D16 = cows) > I am doing cow in root R (cows=3D1) > I cow down through node N (cows=3D2) > I cow down to leaf L (cows=3D3) > someone in direct reclaim evicts clean page of L > I need to read L so I release the locks and loop > someone in direct reclaim writes back N > I cow down through N and re-dirty it because WRITTEN=3Dtrue (cows=3D4, W= RONG) >=20 > from this one: > someone cows N > someone in direct reclaim writes back N > I start a transaction that reserves num_items=3D1 (reserving for <=3D16 = cows) > I am doing cow in root R (cows=3D1) > I cow down through node N because WRITTEN=3Dtrue (cows=3D2, CORRECT) > I cow down to leaf L (cows=3D3) >=20 > You can't just save the "last cow-er trans_handle" or whatever, > because after you release the locks and loop, some other writer can cow > down through that path and it could get written back before you get > another shot, so you wouldn't see that you were the last writer. >=20 > You would have to track which ebs a search_slot has already cowed, but I > fear that these "track the ebs" things run into the same issue Filipe > raised about Leo's log_transid in the eb idea. >=20 > Probably worth exploring this family of fixes a bit more though. >=20 > We could consider an array/xarray on the block_rsv for ebs that block_rs= v > has cow-ed? I will have to think some more about that. (linked list is n= o > good because one eb might go on multiple such lists) We could > preallocate the storage when we size the block_rsv too, which is a > much better time to get an ENOMEM (start_transaction) than search_slot. >=20 >> >> So from the perspective of space usage, re-dirtying a COWed block (in t= he >> current transaction, except log trees) should not cause extra space usa= ge >> except the temporary usage before freeing eb B and copy its content to = eb C. >> >> It should always be the space of the original old on-disk eb, and the n= ew >> COWed eb, no matter how many times we redirtied it. >> >> Or is the problem exactly at the space reservation for such eb B? >> >=20 > Yes, the problem is the reservation done at start_transaction() is not > properly accounted. See Leo's original email for a good explanation of > the details, but tl;dr: > btrfs_insert_delayed_dir_index was seeing an ENOSPC migrating items from > a transaction block_rsv that had been exhausted by re-dirtying > accounting an arbitrary number of cows to that block_rsv. OK, I see the problem in my idea now. It's focusing on the pinned bytes of the space info (aka, global pinned=20 bytes), not helping the block_rsv of the transaction. And I can not find any way to improve my current idea to handle such=20 situation at all. In that case I'm afraid breaking metadata COW is the only solution. Thanks, Qu