From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.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 EAC4A2652A2 for ; Fri, 21 Aug 2026 11:13:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787310791; cv=none; b=mjnNaryKbRnWetCWruf9ls4Jg8uIfNvzQcsyYrehIzQz8C0Pr5JFNDZsUfT87viabF4GweB8aLPBYR66h9/H9ITd2iGFXrlhgyUgOuvfZpwJPKQve5W78Lz4NtG7OfJHlNxfwl6eWAc8ZxZCQ26iJJeWOBMHAqJisWvxy8VXFC4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787310791; c=relaxed/simple; bh=8Jrm/f8DHRj9cbmAogBnHWR2sNS/Kw6ZQic7MFLRDuo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=hBStAupd/a5WdN47gz5s0o/1M1/O5HnipctX79pnyZUYfD/D+TEGNFhQKbqP6qfMyQmEazsFrgNLSRYgipQY5v3fdZv9iQTXAAoLdhNxR/Y00Y5SLkJfjH5CL0RKInDcrapYqx4AOaZuahJifsvO1rCtQEslsSqI1B+K8VMthaM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=JzEXn1cw; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="JzEXn1cw" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-c1677c91969so106522366b.1 for ; Fri, 21 Aug 2026 04:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1787310788; x=1787915588; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=aKdNPfvm3vDBif6gcbUEsOW/ZRihQHs7bDrXqPv+r9o=; b=JzEXn1cwK1qhlCTHGr0MAT6dTAmczPkVismy3CXp/kCbIzaBb73kJgYt90gtFw666J SjwrJbEYQ2cak7DKsNlN5izwT/ka+DnLok53DE1bRiSflNSp3i8RQ75cOEVfC3yzY/K7 282yp1l7Q1/LzEZD5m6Chi/7t5rG7Nbh4xVufDZDpF1hqPu79vKidU9Ktk8Wjwz54FEU IzzwjHaMUJQQIDOXIazN0/aeynERVgSZQcXelrdPS/TPPVVpdobdBXDoYNxOu4slMxwe PhBVnyDKrA1FY2aiaKvmW23OQW43k99gfSuVbTJfQ4531UDbbbmqcKS/DXNq5PA0aHzw I8eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787310788; x=1787915588; h=content-transfer-encoding:content-type:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=aKdNPfvm3vDBif6gcbUEsOW/ZRihQHs7bDrXqPv+r9o=; b=U8dYav/p53q5zO+lOf5PXquO3Uz7xlgGuKwXFk36Gs73sghiZ1sfEHMSNdKBKMaE6V g0/mg76cU7lhmFx+8sMR4EzeHWWCp56xtzqom6dsnGDfOWCb53I7oufzQkaV4um532iX wNONJjpfEHJVjfkZh8/jFwKPftZekeNaSB4NrseAMy4pXrXu6rDXfKSUpACzEqNRz9YC pBMRRQBUSV8862Iw6NW1WkTkHfhU8HipvUM/zmlIyyYOEbZU0PcSLr18UHKMzc0a6WL4 yco0xhd+F1mxqjHLtywrApi8Wlywt7dnMgqM6YvSEjv/bhViMMbahGJp6Ru+pJAr7pMv WpoQ== X-Forwarded-Encrypted: i=1; AHgh+Rp+Qrq7uhrpkoKWDykSR0Meh5a0uM8kQ/SQJFdHP7kHYWo7NWpEnsqAMtGeg+FNx/vQ0EAwisUChc2cHnE=@vger.kernel.org X-Gm-Message-State: AFuF++n3FjbDenROgE+wPMIneDu2pNZ+fJlKm83fd8ZD9RZ3zmqSs6qW NtRKO//dcDWOhr60unadTTf/sA+MqLS5DS7Eb06KTdHDuZ0qj+aosCq/+RDLiCX42CLj71+Jz9K kAc55JfE= X-Gm-Gg: AR+sD10gEedQOYV/IqLIusjfyBTHXyDV/v9RStTQnMoG/62T93qZgbK6eWIh0Y9+IfC fe40A4SvyeKWshlmNhgdzVfWDpJT4wh2PzKvrhHcKFT5flRkROr614eWygoYwnx/0A5cDS4y4Z7 tkW82jivh2hJ5QsBPmMY7LDaLbdSPjKHq0+BKvgL6WSZw0jc8jdVLLQ4CE6UjdxwV9TTjjq8O7b hXcJJpmtpUbuEfvt96q+msJX7OQZN+ebvijBmmm5/ZrXeHw0s8fTsCSrNOTjl6hdKRYsmwXvkc+ DA/qhCHl1NBkkJl93azTDjvZR5qpd0/M0qzQDMJQJ3+0cw2vIk1FImQJrE99uh9JTK+oz11OdRr TJvkjIqgBHASuEFE/ggQwrrxe47g8emFprvY8AMq/xdhR0eeuT6bMz58+ljX8BGiqpqpcgj4HD9 RIPJm9jpXTWiw5kY04PaIVa0WwY81FzKGs5D7ZIzEDWmJoIq7/LXmlVQ== X-Received: by 2002:a17:906:4796:b0:c20:83b0:92d8 with SMTP id a640c23a62f3a-c2469f9a37dmr595221866b.0.1787310788075; Fri, 21 Aug 2026 04:13:08 -0700 (PDT) Received: from [172.16.0.229] ([159.196.52.54]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1416ad564bcsm27727673c88.5.2026.08.21.04.13.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Aug 2026 04:13:07 -0700 (PDT) Message-ID: Date: Fri, 21 Aug 2026 20:43:00 +0930 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] btrfs: skip the extent map tree lock for inodes without extent maps To: Breno Leitao , Chris Mason , David Sterba , fdmanana@suse.com Cc: boris@bur.io, layton@kernel.org, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com References: <20260821-b4-btrfs-em-shrinker-v1-1-286f3fb15873@debian.org> Content-Language: en-US From: Qu Wenruo Autocrypt: addr=wqu@suse.com; keydata= xsBNBFnVga8BCACyhFP3ExcTIuB73jDIBA/vSoYcTyysFQzPvez64TUSCv1SgXEByR7fju3o 8RfaWuHCnkkea5luuTZMqfgTXrun2dqNVYDNOV6RIVrc4YuG20yhC1epnV55fJCThqij0MRL 1NxPKXIlEdHvN0Kov3CtWA+R1iNN0RCeVun7rmOrrjBK573aWC5sgP7YsBOLK79H3tmUtz6b 9Imuj0ZyEsa76Xg9PX9Hn2myKj1hfWGS+5og9Va4hrwQC8ipjXik6NKR5GDV+hOZkktU81G5 gkQtGB9jOAYRs86QG/b7PtIlbd3+pppT0gaS+wvwMs8cuNG+Pu6KO1oC4jgdseFLu7NpABEB AAHNGFF1IFdlbnJ1byA8d3F1QHN1c2UuY29tPsLAlAQTAQgAPgIbAwULCQgHAgYVCAkKCwIE FgIDAQIeAQIXgBYhBC3fcuWlpVuonapC4cI9kfOhJf6oBQJnEXVgBQkQ/lqxAAoJEMI9kfOh Jf6o+jIH/2KhFmyOw4XWAYbnnijuYqb/obGae8HhcJO2KIGcxbsinK+KQFTSZnkFx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4-btrfs-em-shrinker-v1-1-286f3fb15873@debian.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 在 2026/8/21 20:08, Breno Leitao 写道: > The shrinker (find_first_inode_to_shrink()) takes inode->extent_tree.lock in write > mode on every inode it walks, only to find out whether that inode has > any extent maps. > > Most have none, from what I understand, so, avoid the lock by testing the > tree with a plain read before taking the lock. tree->root is only > modified with the tree lock held for write, so the unlocked read is > a benign race: a false negative just defers the inode to a later scan. > > On my tests, find_first_inode_to_shrink() was a bit faster, so, if this > patch is correct, I think it is worth having to reduce lock contention. How much faster? We are using write_trylock() already, meaning if it's not locked we should get the lock immediately, otherwise we skip the inode. So the lock contention should be low already. Furthermore, if there are some hidden concurrency bugs, it will be very hard to debug. I strongly prefer to stick to the existing locking scheme, unless you have a very strong argument not to. > > Signed-off-by: Breno Leitao > --- > fs/btrfs/extent_map.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c > index 6ad7b39ae358b..cdcd2b779050d 100644 > --- a/fs/btrfs/extent_map.c > +++ b/fs/btrfs/extent_map.c > @@ -1219,6 +1219,9 @@ static struct btrfs_inode *find_first_inode_to_shrink(struct btrfs_root *root, > > tree = &inode->extent_tree; > > + if (!READ_ONCE(tree->root.rb_node)) > + goto next; > + > /* > * We want to be fast so if the lock is busy we don't want to > * spend time waiting for it (some task is about to do IO for > > --- > base-commit: 6a746cd265aed59107ebdaa9ce039bb832922969 > change-id: 20260820-b4-btrfs-em-shrinker-7382d7f0dd05 > > Best regards, > -- > Breno Leitao >