From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5966BC25B78 for ; Tue, 4 Jun 2024 21:39:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DE636B0085; Tue, 4 Jun 2024 17:39:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88DAF6B008A; Tue, 4 Jun 2024 17:39:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72E1E6B0092; Tue, 4 Jun 2024 17:39:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5523D6B0085 for ; Tue, 4 Jun 2024 17:39:28 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2EB5AA01C3 for ; Tue, 4 Jun 2024 21:39:27 +0000 (UTC) X-FDA: 82194522774.24.437C8B8 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) by imf18.hostedemail.com (Postfix) with ESMTP id C875B1C0010 for ; Tue, 4 Jun 2024 21:39:23 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=fastmail.fm header.s=fm1 header.b="1czc91/q"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b="j SLz8vE"; dmarc=pass (policy=none) header.from=fastmail.fm; spf=pass (imf18.hostedemail.com: domain of bernd.schubert@fastmail.fm designates 64.147.123.156 as permitted sender) smtp.mailfrom=bernd.schubert@fastmail.fm ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717537164; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8FTZrhL5Hr7uLOv6uusR/yWGu0GdibkgC7VFGtSazy0=; b=FrbLhwLd+Iy0atz0A+yUrRxW/ImQJpIKPPzN7tSeB1WHI3TvoIdJgtUyveYmzrfWajfJAS uepKiSe+5PKcXOlCnWQdwrT9/cIKbI5axHUXd1BO/POpBD3/sWhxdqxPa8wWzrWe/MRbsU A0RZ9ea/sQJ680pzqOnDiF/t0PDwzcc= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=fastmail.fm header.s=fm1 header.b="1czc91/q"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b="j SLz8vE"; dmarc=pass (policy=none) header.from=fastmail.fm; spf=pass (imf18.hostedemail.com: domain of bernd.schubert@fastmail.fm designates 64.147.123.156 as permitted sender) smtp.mailfrom=bernd.schubert@fastmail.fm ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717537164; a=rsa-sha256; cv=none; b=ZsHW29SfMrF0irwLR8qdxMPk3HT4he1rQvO0pBGLDEuROn2arBtB/mCHS2f2Ff+XOciCwy QKu8Z3TGog8LKTnhLsWxuong+BclFrlJYDwrjZAp5Wkc2efZR7PcJBua2lQzbqd0DqJEeG 56CQGrS7t0uC0NRfsAfClzCon7eIiK8= Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.west.internal (Postfix) with ESMTP id B42161800093; Tue, 4 Jun 2024 17:39:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Tue, 04 Jun 2024 17:39:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1717537161; x=1717623561; bh=8FTZrhL5Hr7uLOv6uusR/yWGu0GdibkgC7VFGtSazy0=; b= 1czc91/qSzWR89UNSrj52sQNn9kg4zhZamDdkuTYeroP4MnmaExdx/bWLzo4OUaZ A81aNKUMTCJYG92zkOkRXCe6o+zo6g9Rms8L36Wxj3M2VAGEUXefMRDzmTn7WwNQ B8Nr+ug5c0zBd0rrREZTi1taLgBQCUlnJ3RlIJna9fx7yvXiEk1tK57r5W7ic0jd Cul3EVxyziqfoPryw1ZZC/tb9XNumEvZx3mD0pUzfPjGzaI5NzkxKAYuI5qneRFz QSq5kYmKmAd2S9WY3Wp7cBypi5LjPawvkQ5T1x5qh5aBEPfSLW1Z9gHVcA/s2gME Ku2eBw8QhUxUVbWmhRXiXA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717537161; x= 1717623561; bh=8FTZrhL5Hr7uLOv6uusR/yWGu0GdibkgC7VFGtSazy0=; b=j SLz8vEy1bBe90HbBGaMe8KPR8U9wLeEkfESPwG//70oNTdccdNH2gjhecaJtqwiq HKCS/WMj2a18IzWWshiC5v5BhSA//MjUZ+uqTtH6EzjVkxgeydBd/LVZdVkTURx9 eYWc9PiQLrxAJu1sAbHs/UFNU6Qy+n+s7diC8NeLeDnBE5/snqZsQBeQaNplG5D9 DJ8yqOp3upO3r0iodSgiXDzkeGXKn7UL0zB/Ip5TZYfUIEEKRX6SoNuQaekqj5zw 2CYbld4btI3uDQ8GOPzet4Wv2n3OXeGQgTpsKwWr5YOksjMyyIhP0Bg05tnPXDz4 CmQJ+K1HZT3Mx6USnwshA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelhecutefuodetggdotefrodftvfcurf hrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefkffggfgfuvfevfhfhjggtgfesthejredttddvjeenucfhrhhomhepuegvrhhnugcu ufgthhhusggvrhhtuceosggvrhhnugdrshgthhhusggvrhhtsehfrghsthhmrghilhdrfh hmqeenucggtffrrghtthgvrhhnpeevhffgvdeltddugfdtgfegleefvdehfeeiveejieef veeiteeggffggfeulefgjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegsvghrnhgurdhstghhuhgsvghrthesfhgrshhtmhgrihhlrdhfmh X-ME-Proxy: Feedback-ID: id8a24192:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 4 Jun 2024 17:39:18 -0400 (EDT) Message-ID: <6853a389-031b-4bd6-a300-dea878979d8c@fastmail.fm> Date: Tue, 4 Jun 2024 23:39:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [HELP] FUSE writeback performance bottleneck To: Josef Bacik Cc: Miklos Szeredi , Jingbo Xu , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , lege.wang@jaguarmicro.com, "Matthew Wilcox (Oracle)" , "linux-mm@kvack.org" References: <495d2400-1d96-4924-99d3-8b2952e05fc3@linux.alibaba.com> <67771830-977f-4fca-9d0b-0126abf120a5@fastmail.fm> <2f834b5c-d591-43c5-86ba-18509d77a865@fastmail.fm> <21741978-a604-4054-8af9-793085925c82@fastmail.fm> <20240604165319.GG3413@localhost.localdomain> From: Bernd Schubert Content-Language: en-US, de-DE, fr In-Reply-To: <20240604165319.GG3413@localhost.localdomain> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: C875B1C0010 X-Stat-Signature: ekpq1hbgz9girdr5u7zdi3iky4g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AmuJc2ggwUCFpOcdYnKnPWeD0yRDfcW420UPINtDJ9VnfN14jx0d8QGm/RIOwdctfirTKdksC7KJs2xSlZK5fX+HeRtldG03S1/dA6Gv1xCL+GN1nLrA/oem8VooBvVrutrucK5c5+xqoXUNOlN/AsDGwpvCQSEXZ3Ee+gZP5y7MhPfgFGpcqDK5leRiHzTEf5NCNCi/Yalh7ed/ckMK864HdLclRq7Yv9HXn7nvy+6693W9NL6nABxMQG+9ExdqKpy61fuqvqvjKbUIdLh6m1MP0zI3T8Wzf+IOO24Tl5tK8SDTyh/xd4SC+CTb9+V7Ye7i0sFAGWIpRqNmxcsMKfsSt+UMsE335tXGBTbyNijIqlS X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 6/4/24 18:53, Josef Bacik wrote: > On Tue, Jun 04, 2024 at 04:13:25PM +0200, Bernd Schubert wrote: >> >> >> On 6/4/24 12:02, Miklos Szeredi wrote: >>> On Tue, 4 Jun 2024 at 11:32, Bernd Schubert wrote: >>> >>>> Back to the background for the copy, so it copies pages to avoid >>>> blocking on memory reclaim. With that allocation it in fact increases >>>> memory pressure even more. Isn't the right solution to mark those pages >>>> as not reclaimable and to avoid blocking on it? Which is what the tmp >>>> pages do, just not in beautiful way. >>> >>> Copying to the tmp page is the same as marking the pages as >>> non-reclaimable and non-syncable. >>> >>> Conceptually it would be nice to only copy when there's something >>> actually waiting for writeback on the page. >>> >>> Note: normally the WRITE request would be copied to userspace along >>> with the contents of the pages very soon after starting writeback. >>> After this the contents of the page no longer matter, and we can just >>> clear writeback without doing the copy. >>> >>> But if the request gets stuck in the input queue before being copied >>> to userspace, then deadlock can still happen if the server blocks on >>> direct reclaim and won't continue with processing the queue. And >>> sync(2) will also block in that case.> >>> So we'd somehow need to handle stuck WRITE requests. I don't see an >>> easy way to do this "on demand", when something actually starts >>> waiting on PG_writeback. Alternatively the page copy could be done >>> after a timeout, which is ugly, but much easier to implement. >> >> I think the timeout method would only work if we have already allocated >> the pages, under memory pressure page allocation might not work well. >> But then this still seems to be a workaround, because we don't take any >> less memory with these copied pages. >> I'm going to look into mm/ if there isn't a better solution. > > I've thought a bit about this, and I still don't have a good solution, so I'm > going to throw out my random thoughts and see if it helps us get to a good spot. > > 1. Generally we are moving away from GFP_NOFS/GFP_NOIO to instead use > memalloc_*_save/memalloc_*_restore, so instead the process is marked being in > these contexts. We could do something similar for FUSE, tho this gets hairy > with things that async off request handling to other threads (which is all of > the FUSE file systems we have internally). We'd need to have some way to > apply this to an entire process group, but this could be a workable solution. > I'm not sure how either of of both (GFP_ and memalloc_) would work for userspace allocations. Wouldn't we basically need to have a feature to disable memory allocations for fuse userspace tasks? Hmm, maybe through mem_cgroup. Although even then, the file system might depend on other kernel resources (backend file system or block device or even network) that might do allocations on their own without the knowledge of the fuse server. > 2. Per-request timeouts. This is something we're planning on tackling for other > reasons, but it could fit nicely here to say "if this fuse fs has a > per-request timeout, skip the copy". That way we at least know we're upper > bound on how long we would be "deadlocked". I don't love this approach > because it's still a deadlock until the timeout elapsed, but it's an idea. Hmm, how do we know "this fuse fs has a per-request timeout"? I don't think we could trust initialization flags set by userspace. > > 3. Since we're limiting writeout per the BDI, we could just say FUSE is special, > only one memory reclaim related writeout at a time. We flag when we're doing > a write via memory reclaim, and then if we try to trigger writeout via memory > reclaim again we simply reject it to avoid the deadlock. This has the > downside of making it so non-fuse related things that may be triggering > direct reclaim through FUSE means they'll reclaim something else, and if the > dirty pages from FUSE are the ones causing the problem we could spin a bunch > evicting pages that we don't care about and thrashing a bit. Isn't that what we have right now? Reclaim basically ignores fuse tmp pages. Thanks, Bernd