From patchwork Thu Nov 7 19:16:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13866966 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 C85FAD5D685 for ; Thu, 7 Nov 2024 19:17:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CE7F6B007B; Thu, 7 Nov 2024 14:17:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2576C6B0083; Thu, 7 Nov 2024 14:17:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D1AC6B0085; Thu, 7 Nov 2024 14:17:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DEDD26B007B for ; Thu, 7 Nov 2024 14:17:24 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 90981160B0E for ; Thu, 7 Nov 2024 19:17:24 +0000 (UTC) X-FDA: 82760256768.05.9879047 Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) by imf15.hostedemail.com (Postfix) with ESMTP id 3057FA0027 for ; Thu, 7 Nov 2024 19:16:46 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OMm9+b8G; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.173 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731006872; a=rsa-sha256; cv=none; b=WZmvzUidkHcroxi6mb1KyxGb1toyTuFT5/yxzWW9+sYWhvwc4Tp04UH/W+N/KSaI6CJNX5 d6MnftYmwQ3UAHqDLcPblP5PWlPPzXn1QqtzKtSVWuvrCrcZYPfPWkSR/BHTetP2ClFtTt TU8pqSUKRfje1hhtcxf+RCV1sVui260= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OMm9+b8G; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.173 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731006872; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=Pxi6yoj64cQ9czpC+D4wrwOjjSzqAojTERl6ENP/U04=; b=Z74hfOwDskOjD4jLcTPuqT5E994DsxrA3LaRUBuiUvdoCDA0G47Kr2RV00nXmaWBuf4kUN uzPu+JrEk+36J18EAkMSfiqRCTeMH1+zIvPt36WJXgEZUVInI40iU6klJvFZWLD13U6RUc VyhXVe7/ZfwBmaxKEEXC4GKVHxODiPc= Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-e290222fdd0so1413875276.2 for ; Thu, 07 Nov 2024 11:17:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731007042; x=1731611842; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Pxi6yoj64cQ9czpC+D4wrwOjjSzqAojTERl6ENP/U04=; b=OMm9+b8GRaYQCN07H0umNQz0R6Z0H3K/XzcrbEXo/GEyJusmY2pFGEV9cCYyw6ptBO AMZ6brvjB7XZFdUzGPeK3NCLQiawLX5f6PjHjNGTGO3XpTt9Q2bAouVE4zoqokJGXlUa +jM0DCUtClgz3N3XDCey28FWLS8bpv1Q3/ahSjRcAeue5Qqet7CRBLdzD7PkN7Hfz7IH xaiG90E3uC2NjyOJ55C/4Z2FlKZwMKxGdHmRmc1DSZl31K2anplNQk6fRUyqBuhqlfzH GVEVUBIdsl7gdH9R2HzVkrKE29PW4heT468L2oN3Ug4wUXo6oUKx2+yNiHlL3irJFbcU w1vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731007042; x=1731611842; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Pxi6yoj64cQ9czpC+D4wrwOjjSzqAojTERl6ENP/U04=; b=i54OpvQx+Fg/pu4G7kNZe8e5RqDWLKnz2G1vTswziz/OfBywtNFeayqX3r4GUw8Hxj HXL1Og/KP4KpefC4jFJlD98+x22aWvg0vI44vS9yJWbVXUhQ8r4ByeNo8ASypCyMwMfq AWdrgMJwy+3XvuBmwzAf697nJcftR5fI21H2lI+RUhUPLF//kGLBK0eVxcplzoUD4ivp uNnBd//hkZlYJeavlSBow4youbGJ4gprDfe6QCAjIzgybDhZRLiOCDOwgH+97WF2cDGB +19Qgil/iFLtmD5kJT+zdQH8NR54hohif0JcdHz4p/9UAoGvVVJX4anwxaQ6gr6kykQJ hnHA== X-Forwarded-Encrypted: i=1; AJvYcCVfMOTX4+sjyuHjj2EC8+RbLT59nKuhGVu/uLssMaXen7tcmPf8vqp7P1X5taqH5d4hjoRiHDg9Qg==@kvack.org X-Gm-Message-State: AOJu0Yxh6UBPBBlxFwIq1QNSlWTpdmoT+vIVjock3DDn2y2AmzubWsuZ DUqraP2nt7xG6kn3Jrt/7lYICgGg8CTfVl7WiPcgSTSbXfFwsQov X-Google-Smtp-Source: AGHT+IG1WGDh4ehAkF86pveSou4rq40tAmvLsS+TVJw87dAgZSm9fauqWKEk7n0I6v+B9dgJSTfFQw== X-Received: by 2002:a05:6902:c0d:b0:e30:cc34:af19 with SMTP id 3f1490d57ef6-e337f8d8ecdmr118363276.44.1731007041892; Thu, 07 Nov 2024 11:17:21 -0800 (PST) Received: from localhost (fwdproxy-nha-112.fbsv.net. [2a03:2880:25ff:70::face:b00c]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e336f1baaefsm369047276.44.2024.11.07.11.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 11:17:21 -0800 (PST) From: Joanne Koong To: miklos@szeredi.hu, linux-fsdevel@vger.kernel.org Cc: shakeel.butt@linux.dev, jefflexu@linux.alibaba.com, josef@toxicpanda.com, linux-mm@kvack.org, bernd.schubert@fastmail.fm, kernel-team@meta.com Subject: [PATCH v3 0/6] fuse: remove temp page copies in writeback Date: Thu, 7 Nov 2024 11:16:11 -0800 Message-ID: <20241107191618.2011146-1-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 MIME-Version: 1.0 X-Stat-Signature: wm1auqqrezu9murujbwfdjrkoh9pmokw X-Rspamd-Queue-Id: 3057FA0027 X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1731007006-889891 X-HE-Meta: U2FsdGVkX18tx5OwuFGM4/TUmLT7lF9kim84WRWUCWdnwmtvFO87TU8YfJI9/Wylc1+2SuoYghe8FMUmeM3ORJ6x8mzGBS31pMHV7SgB09Yo+IAL4+HjAjHlVvt1sJaDvtFPhu6YRmmpeWmElH3AIp8AMU4cgGdH8PbwUmhmT9DnNKrqub2YtrmPVmbA3JadOImErfPanoj83lxQ+2+kjQmUxfVEWXd8PAXYlFIE5hToeIjpEh/jjJy/8AFm23Ceh2OA1s/kyoDrNhgzX5oL8midJBdIYeNv/BY96AHjFqmlkFSS4iKpY1OeJuGxssDCEn0RaW4/HI/1dv+8NQ4I2bWPUE4Su9zQYNaRVEZQmnIAo4NrBZm023aoGc2wwKGidO9ChQLkAh2e7MoF0/0QNzcmWNlDJ/N16RT/lSTbPtxfaT9R1plC8jlQl5HQS3eJEzobi9ljHwdJ/x9BjixpjT1XduElzr1dOp53RsZIAyjwDNfOcmvajdvufW4MGODjiItvg1Xlqfn648KBtRhez3RSmz2BkIvUJpMb2ns9dpyWObdE36iMaee3Vuwn5GQlH1XHeCKqBQirzWYfTs3cMrg8irj1+CUVsQhSk6MsCVSaWvNz81+0IG91p3BtFBWGAmRmUVAf/1iMKSn7g05Iq4YTXZcIUf5QAHCBo11caf76RvnV7JFNbvUfcjGGp3hVCDm+VtEtkFE/We+Zfij4AqK1BjyEKmXdLqOn7iiHqI1mEpMonUUpBpkU8cyWsk2OqFT4XoQmNuATfcLfDr7QrGSgrYdL3FYvjqSzRDPV1trBHN0yoZKbIj4HgxbOW36dJQALiWWd8GIO7dQWk4l/W0O7dhTnrhK7qcXtL/R28HFLYzJCPCmuCfO+2T6Yu+1bihEgrKrgjHUzYOf/yccqsc/XJiVk5oetp/vdFVuGXQHvsswNfBMbJ116Xz14yrBFO1tzPQVa0PgcKGow9Ee OaxE9Gtz 3gx4zC1aq8Y+4IZfJ9OQHk3uxYIN+k4c24yPElvhubxdPzbRXEeaW78wMleisW5oZTd1SmpbAz2ql6adAzR21DEUy/MxLpPDFwHfzNR/HjNDyG+HcQlqdzqOZ1wqp1D2Jglcyx+4L6dCaNNr+99aEOdZKcPt1OqaZbjwxteoF9ZojJZLbUUvTIxbYhDHcrAX/w0cWzTmH8ah0uuZAVsiKRZOKkAedOH9+M3IH9EiVTzqe8SujO2KtKrSHBJnhihK5nkDDL4mI+lrcJBcmnTxSV/a5IKNDGgXvHjSh3Z0ja0mXHtSZryNg1qdaCIl/DGR3Dcx5NpcocwNYYTodWKeIyixWM4NAQgJPLU+36uYwZgclbUCi+j0j7nrThQ== 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: The purpose of this patchset is to help make writeback-cache write performance in FUSE filesystems as fast as possible. In the current FUSE writeback design (see commit 3be5a52b30aa ("fuse: support writable mmap"))), a temp page is allocated for every dirty page to be written back, the contents of the dirty page are copied over to the temp page, and the temp page gets handed to the server to write back. This is done so that writeback may be immediately cleared on the dirty page, which is done in order to mitigate the following deadlock scenario that may arise if reclaim waits on writeback on the dirty page to complete (more details can be found in this thread [1]): * single-threaded FUSE server is in the middle of handling a request that needs a memory allocation * memory allocation triggers direct reclaim * direct reclaim waits on a folio under writeback * the FUSE server can't write back the folio since it's stuck in direct reclaim Allocating and copying dirty pages to temp pages is the biggest performance bottleneck for FUSE writeback. This patchset aims to get rid of the temp page altogether (which will also allow us to get rid of the internal FUSE rb tree that is needed to keep track of writeback status on the temp pages). Benchmarks show approximately a 20% improvement in throughput for 4k block-size writes and a 45% improvement for 1M block-size writes. With removing the temp page, writeback state is now only cleared on the dirty page after the server has written it back to disk. This may take an indeterminate amount of time. As well, there is also the possibility of malicious or well-intentioned but buggy servers where writeback may in the worst case scenario, never complete. This means that any folio_wait_writeback() on a dirty page belonging to a FUSE filesystem needs to be carefully audited. In particular, these are the cases that need to be accounted for: * potentially deadlocking in reclaim, as mentioned above * potentially stalling sync(2) * potentially stalling page migration / compaction This patchset adds a new mapping flag, AS_WRITEBACK_MAY_BLOCK, which filesystems may set on its inode mappings to indicate that writeback operations may take an indeterminate amount of time to complete. FUSE will set this flag on its mappings. This patchset adds checks to the critical parts of reclaim, sync, and page migration logic where writeback may be waited on. Please note the following: * For sync(2), waiting on writeback will be skipped for FUSE, but this has no effect on existing behavior. Dirty FUSE pages are already not guaranteed to be written to disk by the time sync(2) returns (eg writeback is cleared on the dirty page but the server may not have written out the temp page to disk yet). If the caller wishes to ensure the data has actually been synced to disk, they should use fsync(2)/fdatasync(2) instead. * AS_WRITEBACK_MAY_BLOCK does not indicate that the folios should never be waited on when in writeback. There are some cases where the wait is desirable. For example, for the sync_file_range() syscall, it is fine to wait on the writeback since the caller passes in a fd for the operation. [1] https://lore.kernel.org/linux-kernel/495d2400-1d96-4924-99d3-8b2952e05fc3@linux.alibaba.com/ Changelog --------- v2: https://lore.kernel.org/linux-fsdevel/20241014182228.1941246-1-joannelkoong@gmail.com/ Changes from v2 -> v3: * Account for sync and page migration cases as well (Miklos) * Change AS_NO_WRITEBACK_RECLAIM to the more generic AS_WRITEBACK_MAY_BLOCK * For fuse inodes, set mapping_writeback_may_block only if fc->writeback_cache is enabled v1: https://lore.kernel.org/linux-fsdevel/20241011223434.1307300-1-joannelkoong@gmail.com/T/#t Changes from v1 -> v2: * Have flag in "enum mapping_flags" instead of creating asop_flags (Shakeel) * Set fuse inodes to use AS_NO_WRITEBACK_RECLAIM (Shakeel) Joanne Koong (6): mm: add AS_WRITEBACK_MAY_BLOCK mapping flag mm: skip reclaiming folios in legacy memcg writeback contexts that may block fs/writeback: in wait_sb_inodes(), skip wait for AS_WRITEBACK_MAY_BLOCK mappings mm/memory-hotplug: add finite retries in offline_pages() if migration fails mm/migrate: skip migrating folios under writeback with AS_WRITEBACK_MAY_BLOCK mappings fuse: remove tmp folio for writebacks and internal rb tree fs/fs-writeback.c | 3 + fs/fuse/file.c | 339 ++++------------------------------------ include/linux/pagemap.h | 11 ++ mm/memory_hotplug.c | 13 +- mm/migrate.c | 5 +- mm/vmscan.c | 10 +- 6 files changed, 61 insertions(+), 320 deletions(-)