From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 B1166171B1 for ; Sat, 22 Aug 2026 22:11:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787436662; cv=none; b=aVyGQmngs0AFvpC36Si6FOWmYJ7cSk+WtiaLfEaVkzTQM9OwFbOA5wV5NUZJHnVOfaxbaPt8qbU2iqvRTIdmYAa/10o47DT6d3lmSB/SF7ufP75nBdV3tzPneZA+D5JrAElLKt7BKfzQj534rlHrYVjmJS+z3DtN8C3+dP/IMo0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787436662; c=relaxed/simple; bh=xGHlJN0d2A4rk8ZTy3GhhpbBSJTFsDN3YyLexF1PMcw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=jIvkv+nZK0vAW06tLN2udR12ivwG5qUFrnvFShMutJWwlTbKrfzzdwywGlVRK70bD2CB/4o1uPnJ6jW9C5bdtxVOjcIZ6rG/DeqtTeCw/dp7UAxysFJEetWqUwLn4zJXuGDfepAFblpd3B/gCIs2tHnUHoYOCTLXF4+8mXnsbm8= 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=b6qUjo/m; arc=none smtp.client-ip=209.85.218.43 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="b6qUjo/m" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-c20e70a0962so333625366b.2 for ; Sat, 22 Aug 2026 15:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1787436659; x=1788041459; 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=6sO7WfhAIJ1nbuSFCtyRgBBYLF8hs1ePKr0RCA4N/Wo=; b=b6qUjo/mMFOdF2jWo+NslLvHCullHnj4C2NLyJlrGdcO77Jxb/MCXYuZv8QVeM2NlA /oyghwdZmUSMulZuLan6Gjd6q4jlCqxpvZA3d27VmuP3s7M9OnxNJSZwH41tBt9neFA2 Yq13+p9ZNjJWvYzb6kaxkzLofRJof7fFs19jpgr098mT/LXXVatLXvhkhsJp8+pSdz13 3BK2+qXSzdwzqkxnCFT/zxWxCseftsBQ7bihF324okXIanSDSbBO814Pqvy8tNdx8yQC YbAL7gwPpkOACnyEApavSZsxWLZema2CofAJV40YbCc5BaxBjFUXEdVtbfUKdx5eM8wt nG4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787436659; x=1788041459; 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=6sO7WfhAIJ1nbuSFCtyRgBBYLF8hs1ePKr0RCA4N/Wo=; b=qXnKgHRUTver/XUDNFMrzUAFHJgQgqvu4kZLwkcUONkOuHQVYLAoP2z1u711iICm56 Z9UyOGG/06oa8pUiSpBf0GEkN9hhuvyPZyCcbEGzS8oilkAZWJs/sEFiwpNvO8nIRrGS DTmLaj7hd9n/YaICTnScSkQbann3X+KOMv6QaQOzl30lv1bKqMwqPf6zCPDy2keH0tg9 j7fY7+0nuJbMvqV3wVrBAl4IiEz7gZ7hYMwdu4xosfeTNLDOIJI1fAxRcza9bxLDENaZ dhijPyM1JbJDvlgI4kW3Mkpn87SJLiailECsQRewlXEkDLlCmRQBpI+KxWxm+LMMHwkT RXlQ== X-Gm-Message-State: AFuF++mpxS5VZmevDTv32KpXBD8kntlDztbAIGxddqXthj3soplLWPY5 E0f8RLYQo9h2gcpy29aX8uj9IwoXFXeAoEF3DS/snaQHg+FeCHkBBvZskgq5XTMsoN4= X-Gm-Gg: AR+sD10JNBnf99gKM4wRcCKYyANEQFfYdsIu4jX/tpEZd7mBBjv1x/IKBYRrp2t1pES sOhrxjl1Yq7ORBncqit6pzkGrYeAjU/fBmZyVAXQ4fsNQPdYr2rCncJOVClx4AQsSQTqp+QkrJS MqbHx+y4UINB2Df1o9tsSq7O13KqurJwewAxHsFbO79mYAtxC0thXr1/MBWH0oLnQ4EAXmSXh2D 7yV2uj0XIonEq+FptQscD8ZPnBTNf322A2fImumhjXTTD9NkRApZgZzczkimZzBCl8AgOh0OgN+ qGm6ei3+gcrE3SG7NlGnf/4pPatZDkifmYhv2H+FSYFSn8Zrs61X+Mzpl9ZcPXndYm9AsBb0zMj RlsNIZKmZGwzcc6Nl946ZNVfFtkjY5D3fSZxSEFX1n1OZNl+B3DPU2TbML0uznKDMQ2MBzIokSX xONtBNof9+emtSEjdePABSPXTAGta6JTti/HnPBFPtl69t/PuyRvAM2A== X-Received: by 2002:a17:907:e00c:20b0:c20:23f8:99a5 with SMTP id a640c23a62f3a-c246a6a402cmr1255924666b.15.1787436658917; Sat, 22 Aug 2026 15:10:58 -0700 (PDT) Received: from [172.16.0.229] ([159.196.52.54]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-395e4b46518sm3939114a91.17.2026.08.22.15.10.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 22 Aug 2026 15:10:57 -0700 (PDT) Message-ID: Date: Sun, 23 Aug 2026 07:40:53 +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: zstd: keep the last max level workspace out of reclaim To: fy15309206903@gmail.com, David Sterba , Nick Terrell , Chris Mason Cc: linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org References: <20260822-btrfs-zstd-max-level-reclaim-v1-1-0eb13c127480@gmail.com> 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+KQFTSZnkFxnbsQ+VY fvtWBHGt8WfHcNmfjdejmy9si2jyy8smQV2jiB60a8iqQXGmsrkuR+AM2V360oEbMF3gVvim 2VSX2IiW9KERuhifjseNV1HLk0SHw5NnXiWh1THTqtvFFY+CwnLN2GqiMaSLF6gATW05/sEd V17MdI1z4+WSk7D57FlLjp50F3ow2WJtXwG8yG8d6S40dytZpH9iFuk12Sbg7lrtQxPPOIEU rpmZLfCNJJoZj603613w/M8EiZw6MohzikTWcFc55RLYJPBWQ+9puZtx1DopW2jOwE0EWdWB rwEIAKpT62HgSzL9zwGe+WIUCMB+nOEjXAfvoUPUwk+YCEDcOdfkkM5FyBoJs8TCEuPXGXBO Cl5P5B8OYYnkHkGWutAVlUTV8KESOIm/KJIA7jJA+Ss9VhMjtePfgWexw+P8itFRSRrrwyUf E+0WcAevblUi45LjWWZgpg3A80tHP0iToOZ5MbdYk7YFBE29cDSleskfV80ZKxFv6koQocq0 vXzTfHvXNDELAuH7Ms/WJcdUzmPyBf3Oq6mKBBH8J6XZc9LjjNZwNbyvsHSrV5bgmu/THX2n g/3be+iqf6OggCiy3I1NSMJ5KtR0q2H2Nx2Vqb1fYPOID8McMV9Ll6rh8S8AEQEAAcLAfAQY AQgAJgIbDBYhBC3fcuWlpVuonapC4cI9kfOhJf6oBQJnEXWBBQkQ/lrSAAoJEMI9kfOhJf6o cakH+QHwDszsoYvmrNq36MFGgvAHRjdlrHRBa4A1V1kzd4kOUokongcrOOgHY9yfglcvZqlJ qfa4l+1oxs1BvCi29psteQTtw+memmcGruKi+YHD7793zNCMtAtYidDmQ2pWaLfqSaryjlzR /3tBWMyvIeWZKURnZbBzWRREB7iWxEbZ014B3gICqZPDRwwitHpH8Om3eZr7ygZck6bBa4MU o1XgbZcspyCGqu1xF/bMAY2iCDcq6ULKQceuKkbeQ8qxvt9hVxJC2W3lHq8dlK1pkHPDg9wO JoAXek8MF37R8gpLoGWl41FIUb3hFiu3zhDDvslYM4BmzI18QgQTQnotJH8= In-Reply-To: <20260822-btrfs-zstd-max-level-reclaim-v1-1-0eb13c127480@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 在 2026/8/22 22:15, FAN YE via B4 Relay 写道: > From: FAN YE > > zstd_put_workspace() makes the "hide this workspace from the reclaim timer" > decision only when the workspace is returned at its own level. > Decompression always asks for level 0, so a max level workspace borrowed by > a read skips the whole block and the test for being the last max level > workspace is never made: it goes back to idle_ws[] still linked on the lru. > A read borrowing one while a write holds the other is enough to leave every > max level workspace on the lru, where the reclaim timer can then free them > all and clear the level bit. > > Once no max level workspace is left, zstd_put_workspace() never reaches > cond_wake_up() and a task sleeping in zstd_get_workspace() after a failed > allocation has no possible waker. Make the decision on every put of a max > level workspace and unlink it from the lru when it is the last one; > list_del_init() in zstd_find_workspace() keeps the entry usable for that. > The test also no longer hides workspaces of other levels, which it did > whenever no max level workspace happened to be idle. > > Fixes: 3f93aef535c8 ("btrfs: add zstd compression level support") > Assisted-by: Claude:claude-opus-5 > Signed-off-by: FAN YE Sashiko found a high level problem: https://sashiko.dev/#/patchset/20260822-btrfs-zstd-max-level-reclaim-v1-1-0eb13c127480%40gmail.com > --- > Reproduced under QEMU/TCG. Both arms are the same kernel with the reclaim > interval shortened to 100ms and a module param picking the old or the new > zstd_put_workspace(); the workload is compress-force=zstd:15, three rounds > of four concurrent writers followed by drop_caches, four readers and two > writers. "unprotected" counts puts of a max level workspace after which > nothing left in idle_ws[] is off the lru; "borrowed" counts a max level > workspace taken and returned by a lower level request, the path this patch > changes. > > borrowed unprotected timer cleared the level bit > current code 245/339 118/216 1/0 > this patch 300/379 0/0 0/0 > > borrowed is of the same order in both arms, so the zeroes are not "the code > was never reached". The last column needs the reclaim timer to tick inside > the window, so it is a coincidence rather than the criterion. > > Compile-tested (W=1, x86_64 defconfig + CONFIG_BTRFS_FS=y). Independent of > and applies without my lost wakeup fix for zstd_get_workspace(), > 20260821-btrfs-zstd-lost-wakeup-v1-1-84f358d4ea67@gmail.com. > --- > fs/btrfs/zstd.c | 25 ++++++++++++------------- > 1 file changed, 12 insertions(+), 13 deletions(-) > > diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c > index 86919293fd54..8abc4e456f32 100644 > --- a/fs/btrfs/zstd.c > +++ b/fs/btrfs/zstd.c > @@ -260,7 +260,7 @@ static struct list_head *zstd_find_workspace(struct btrfs_fs_info *fs_info, int > /* keep its place if it's a lower level using this */ > workspace->req_level = level; > if (clip_level(level) == workspace->level) > - list_del(&workspace->lru_list); > + list_del_init(&workspace->lru_list); > if (list_empty(&zwsm->idle_ws[i])) > clear_bit(i, &zwsm->active_map); > spin_unlock_bh(&zwsm->lock); > @@ -335,18 +335,17 @@ void zstd_put_workspace(struct btrfs_fs_info *fs_info, struct list_head *ws) > ASSERT(zwsm); > spin_lock_bh(&zwsm->lock); > > - /* A node is only taken off the lru if we are the corresponding level */ > - if (clip_level(workspace->req_level) == workspace->level) { > - /* Hide a max level workspace from reclaim */ > - if (list_empty(&zwsm->idle_ws[ZSTD_BTRFS_MAX_LEVEL - 1])) { > - INIT_LIST_HEAD(&workspace->lru_list); > - } else { > - workspace->last_used = jiffies; > - list_add(&workspace->lru_list, &zwsm->lru_list); > - if (!timer_pending(&zwsm->timer)) > - mod_timer(&zwsm->timer, > - jiffies + ZSTD_BTRFS_RECLAIM_JIFFIES); > - } > + /* Forward progress depends on always keeping one max level workspace */ > + if (workspace->level == clip_level(ZSTD_BTRFS_MAX_LEVEL) && > + list_empty(&zwsm->idle_ws[ZSTD_BTRFS_MAX_LEVEL - 1])) { > + list_del_init(&workspace->lru_list); > + } else if (clip_level(workspace->req_level) == workspace->level) { > + /* A node is only taken off the lru if we are the corresponding level */ > + workspace->last_used = jiffies; > + list_add(&workspace->lru_list, &zwsm->lru_list); > + if (!timer_pending(&zwsm->timer)) > + mod_timer(&zwsm->timer, > + jiffies + ZSTD_BTRFS_RECLAIM_JIFFIES); > } > > set_bit(workspace->level, &zwsm->active_map); > > --- > base-commit: 26260251022fbc2f248a3d747a9b2b961b18d2d8 > change-id: 20260822-btrfs-zstd-max-level-reclaim-5ab59a71f83e > > Best regards, > -- > FAN YE > > >