From patchwork Thu Nov 7 23:56:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13867332 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 DAA40D5D699 for ; Thu, 7 Nov 2024 23:56:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5021E6B00A5; Thu, 7 Nov 2024 18:56:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B2318D0001; Thu, 7 Nov 2024 18:56:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 352576B00A7; Thu, 7 Nov 2024 18:56:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 178C76B00A5 for ; Thu, 7 Nov 2024 18:56:31 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 77F9014060E for ; Thu, 7 Nov 2024 23:56:30 +0000 (UTC) X-FDA: 82760960604.29.60EDD7D Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf01.hostedemail.com (Postfix) with ESMTP id 7F91E40004 for ; Thu, 7 Nov 2024 23:56:00 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ANa0oM8X; spf=pass (imf01.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.169 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731023562; 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=V3jh+zXPjAH8B5UH7TxKcV2Z2agxWj09beON9xy7gjs=; b=1cyspycJQhg1PGSLs6BnI8jzqlHEEMzk84aFSxoPA3pEYQXpdd7Ldifgv7upNXTJvgXOI+ EygrpVvJ9VHVIRun8XAgYKbNc1FENDc1Skpk9fcM5idgToE5vdTSjJJ5YvmPCXZiYT8uHu MIS1WGZ/8lQ8AvuDC4F5qNowbpkABdk= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ANa0oM8X; spf=pass (imf01.hostedemail.com: domain of joannelkoong@gmail.com designates 209.85.219.169 as permitted sender) smtp.mailfrom=joannelkoong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731023562; a=rsa-sha256; cv=none; b=igurRH2XAumsMxSYit05Xle2LnozmdXXHReAbM3hZUUeAJz/oe8juti4zZalHqMV9aEyN5 m56ECIr4qr5TGH9FbxRaXxe/yWeCXqKywR1qc7CJnMyUO7kezOQSYJUITMikBIiljsIARY WnzaHyhZ9ljPUWJGjoaUZhG5LKJC6+4= Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e292926104bso1512118276.0 for ; Thu, 07 Nov 2024 15:56:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731023788; x=1731628588; 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=V3jh+zXPjAH8B5UH7TxKcV2Z2agxWj09beON9xy7gjs=; b=ANa0oM8X7JFF/gjNs+xwaj+uWhitegCMNO/+OHH5zLht6d3o+h3ZALCgBzisNtJX3A 8bqRZToAoaBpxk/G4tzxTxRJGEnxZfHnBx63n2+UX7y9okU5pMSlCr/i697lg5Jai+jb Femr9B51KfBfo5SAuzuQPpe2WAYNDjz95X1hVzZHzSnilDPOX3mkNRxcJvr8fuFmo8FC iSZTyddQ31c98B1RmQm5wMBtW9kYkeXEiQ1D6ZwvHXzBDQ5k8lI9NvlNkkCzFF1UQI0N C4AG/M0QIcGOY+CrIoKblY8/5ZsVpcecTvOIqRDPYXQ+JeA27+SMicDjoeTMB1fkmyAs oBPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731023788; x=1731628588; 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=V3jh+zXPjAH8B5UH7TxKcV2Z2agxWj09beON9xy7gjs=; b=vH2/8HvXrCWJnxxadgvQLfELnfuwizw9/iUhwMZ5zzxgTaOTKivVtRmdtUK5TmYv9X 19iGZJrd8jnpuCGU3YUMR434Xu3ZBvR9T2SgwyNFsaJA/jUDxRZCi0XYhlQvBuOz/4K2 CFZEGmGCokx8F1MSXx9+9xzBvAY3iXIooInBZLpziG56NGANUum4uWZTKMIhodr4AW+3 ZlpA6IR+fQtnzpgZYjPw9AmgkvU9sKWFYr5PEE3vRH/XOCZg1/8ZKFqNb0XWHYHtld3A OZAtUje14/gWUYvJAxqCdJgI0n8eWAs8+46lYUf9xMg9b+ZZ99MNqQihGWCJp0Wiq2mi Neqw== X-Forwarded-Encrypted: i=1; AJvYcCWKhMyQcCCMGJed91h4OctJ2TldTVlK4+d9B0xJmP6nP1lRDQSAWa9ysYUFzD2Kb02jSfy4wJEv3w==@kvack.org X-Gm-Message-State: AOJu0Yz9QICZR4vpIJ2gvfCeTUzn5+1fUF6qN08pSxZUlGAlCgfnQz24 nAAj11TXz4SbNwxsCN0TEmvDKpcLcGPjrqxmjn+uKAEeq/tr8gSM X-Google-Smtp-Source: AGHT+IHAJfLgCEcVPQgLi9Kit0YVBYjIC3gw+daVe5E2PG27h0cJnecO/WA7oHuw4flyoEPWA1d2Ng== X-Received: by 2002:a05:6902:1684:b0:e33:1486:79e1 with SMTP id 3f1490d57ef6-e337f8fe504mr1024382276.43.1731023787572; Thu, 07 Nov 2024 15:56:27 -0800 (PST) Received: from localhost (fwdproxy-nha-011.fbsv.net. [2a03:2880:25ff:b::face:b00c]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e336ee20911sm456732276.8.2024.11.07.15.56.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 15:56:27 -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 v4 0/6] fuse: remove temp page copies in writeback Date: Thu, 7 Nov 2024 15:56:08 -0800 Message-ID: <20241107235614.3637221-1-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7F91E40004 X-Stat-Signature: pe4un93ez71okgg5gdkdbfin7zz7mbqk X-Rspam-User: X-HE-Tag: 1731023760-227255 X-HE-Meta: U2FsdGVkX19QAnWI0nNfy0NHBcK32t4XDvuwoOhoGyoNuA4m+3RaaOMDoNUoZWPqbV0sp6dNgxfUQ8JxZiV4KRfPUjqNvk+JHXxaRfgNu/C7Q99QOdPg4gWc/lmZ+TSd6C31ZsDg52LjWQyFSOhEiN3ynk32PpRliwWLfjji1WrPutM9LaDchy1edpaUlCmo9VDfAJtl2Tt1QKgEogmZ0xzdKz4sZRsvMR2ZNbgLmtKqHYK37d+g0ut1pmcYULwMvb7e0LNnlTFdYSxXCcu/7X83cpLI+6Sp6a5bQtFRZXFqpv2LQsCGZ8yKWVVMmXv1Df/u8bwaNR+SNaS3HK8iSN8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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 --------- v3: https://lore.kernel.org/linux-fsdevel/20241107191618.2011146-1-joannelkoong@gmail.com/ Changes from v3 -> v4: * Use filemap_fdatawait_range() instead of filemap_range_has_writeback() in readahead 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, 60 insertions(+), 321 deletions(-)