From patchwork Thu Nov 14 15:25:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13875209 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 0182FD68B30 for ; Thu, 14 Nov 2024 15:28:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78D896B0089; Thu, 14 Nov 2024 10:28:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 73DF16B008A; Thu, 14 Nov 2024 10:28:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 605496B008C; Thu, 14 Nov 2024 10:28:05 -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 407746B0089 for ; Thu, 14 Nov 2024 10:28:05 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DCBFC81212 for ; Thu, 14 Nov 2024 15:28:04 +0000 (UTC) X-FDA: 82785080868.28.2B7A92E Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) by imf29.hostedemail.com (Postfix) with ESMTP id F060E120019 for ; Thu, 14 Nov 2024 15:27:02 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=TXvcOG4L; dmarc=none; spf=pass (imf29.hostedemail.com: domain of axboe@kernel.dk designates 209.85.160.45 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731597904; a=rsa-sha256; cv=none; b=q5U/cNx3GhVTeVyt6tQ/BvXPWYv4glAZOuz+S5KHmPfCUru1S5WcpnCFXrCLLkH3jMtw9c YKjgIZ2w82cNivFOzTzMCXvGvfQ2AWmoo3OWTuHgFC65FpJ0HM2GX4heuyXbOHNa1JpZf1 8JC4PARH7XEtq+tuyfqH7sISoQj0HHU= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=TXvcOG4L; dmarc=none; spf=pass (imf29.hostedemail.com: domain of axboe@kernel.dk designates 209.85.160.45 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731597904; 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=upOcZ8Da+PhrMJT3+CvYdnGUaA0rMPuANSoknEoDO6c=; b=xJSDms/moNfkFHQqUrm3zYtVCJpxMftUIjtFygvkpqXhWLhMaHiJlzj5XU46zjZgocdNcx QU77eQZKCYcNp5RMckrO/exZjXSKTgsHnT+YOQfIAxX5CAcKAkLBZ+jpuIrAEfRDIPb8UY tNb8nQbj35yrSX3pjY87G9rLAcrR2lE= Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-27b7a1480bdso337310fac.2 for ; Thu, 14 Nov 2024 07:28:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731598081; x=1732202881; 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=upOcZ8Da+PhrMJT3+CvYdnGUaA0rMPuANSoknEoDO6c=; b=TXvcOG4Lwiq7NzkmstdrRMeX1jLmLyTc33oAZFvCKQzh4rhKBtIfYz/ozhiIDoC1bH cQbBQ/fKfQ4phiDJ6HJOHS6x0IycVEGBzlfbCdUftCxCjM0lS1V5UNwZNZcbevaKgS1T YKCeTdf+l4UlIWyX9Ly9aRZzoC9YGfIraZTyZklzRlfFE4Dw41hC4F/3ODZ/DndXrkaz velLBhABu+pRRN3KO0HrvxMtrwoPdptlRIClZwIsqZVLuxWfUd+aqlEtPIgQT8Ql+w6a J0SzKrxW9xdvh7+LCV7uld9atNdtlEJ3OBEj8D/DQ0+XBkcGjuz/sXm7giVhwJMb/xQF ZBug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731598081; x=1732202881; 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=upOcZ8Da+PhrMJT3+CvYdnGUaA0rMPuANSoknEoDO6c=; b=o7YKTTQRnWNGEyxfyHZI1x58oP1bs3d6Rt62qcIinGt8IKSwumX+NcdtXDB7F3AR41 0k5c2vH2etkvTR310va19l6mVbl8pWr5XXnjT47ZVfrSmpJzcJThx3rJn4/SEQsT8LMl ap6dCatEV+ryDhFtCIqiJFgdB4kcpcUpGz/CmRVDLkEhQ2SEOi7vVr2Y0LpYk1dZylcr i9XuPNHcQD9dBR5i9WLCIAQDGSGbWJXw5WFg960HrA+YD2/Dr40UjG+63N7AH9uS0bzu FbQr2O1Ue+PN94BaYsdU0BVHYsVEICAG2yi/JHIP1jsLRTlrGW6sZgHmlUYy+rfUbwS8 i5Dw== X-Gm-Message-State: AOJu0YyOG1oVgjHekgPzWWk1n4K1mdjcubBPsTlDYda4IzNu0YUDe8bb h/f1//8qtg2vE1DBLYCjckusmo2gLl43/oj5RYDlEVYCHDdS6VqOMXOeY9OfzZ2vDcDK3SiFueN 7GTI= X-Google-Smtp-Source: AGHT+IHBiSMdAqkwaY/EaNZLQHe509r0Wv/sQpfdA1eWS0kETb8TpyQost056gI2LIEpEMGhxGO0ag== X-Received: by 2002:a05:6871:6306:b0:277:e1bc:7da7 with SMTP id 586e51a60fabf-295e8dc02c3mr7474161fac.22.1731598081287; Thu, 14 Nov 2024 07:28:01 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eea026eb41sm368250eaf.39.2024.11.14.07.28.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 07:28:00 -0800 (PST) From: Jens Axboe To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Cc: hannes@cmpxchg.org, clm@meta.com, linux-kernel@vger.kernel.org, willy@infradead.org, kirill@shutemov.name, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, bfoster@redhat.com Subject: [PATCHSET v5 0/17] Uncached buffered IO Date: Thu, 14 Nov 2024 08:25:04 -0700 Message-ID: <20241114152743.2381672-2-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Stat-Signature: 5euhuy9psb3zn6wb1yfc6cdaejbjni3p X-Rspamd-Queue-Id: F060E120019 X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1731598022-255535 X-HE-Meta: U2FsdGVkX18cGO2vlKsn96bLigH1qbm/b19NZbwHyZj30yKnTrG7bn5QXY/0i0HUnSFUnbYoiIteI0S4i5KGuEjhgNWzv3rhTnLUBOAYfSPjzJOCdV5pWtcuwC9wkluij2QFK9k5qv49rwwhnGEQW7L+eBqOCvlZxgH2Acg2GhhgQPz10o32kpfH6OJmRT+EwVYzdJD9fBLhy+H1Fy7IjG54NAF8iAxpK5pOL8Y45wQWkNCXugAr5QXv6VFoB/+qFcOAADtgqA/Wg8Fk6GasTGnJY2pbPRpcvCjy1J/NAVmg8fEnQN3Q3uGbzvJi0KKeUPXnvRdK9fO30NicHSryQ19oz1cJ7GtHQBgWk03lhW7NdH5lh1WZCln29MKfwBYMncrqT3844PkL5QJKJD1mxf+gGw7Upj5wQ79ychLwKZ7c12/6jiNZWf0KkaURdGrEOdKydxpKAPoRhNEZ5qgYOrd+ZjBHldlaX0Ju3Po8cfUih4OuoBoq5pjrjTP2qNvgXUa2PJJCG+f4rjlampu5kjThxXLgZs1NzLeTqEvEKNbd15OK6Zu3rNLVBGvZJDb04E7RMb0n+O+Ci+b0JOmYYM9hZSbBCoGLibBmrsH6qIPVkUrXnmaTocURUIycvtObJpOmCa3ZcJlfIeuhBdVi/CCLN8+90QRw1sHxEGwZ/dDQSzyff5oSVb2uQl/pFPmpf4feBG2BIqOpm+YxM8ldUvGDaiUSjaGZVXqqi6iRkZ9rZL4m9uQPX5BxncClzobZ3nDPJPXvXULyvWJ3mQ0YyzFZHU/gKxiCLLrpv41XadOtn6NHjK/K9nUMOexu+cC4iJkaUstzuZsabLN23x2x98SKYuU8qPK7TXGST1B4CURzm6dpoZNzHSdcqcrdiBqT0PxfbeKQy1lP9Nhyr2p+YeWl2EQ+JA76iM2BNYsOwgJDJWcRdeOdocMZYRQezHqMr5VtoISnVSEnPDMyx96 m7OMol7v F85alqoQNY15NMLgdo/Z1NgrxpB+0ECGQIgcKKVA4haU2iXGY72HfgEgyIEBLa2D/rOUS3wT3wub2JjLkt6ZnkHI1xtddoRqOsB7icXoLGt/t4blkGNK/v+vDbL8KjgEvajEjvFideNTR3/2F30XipbAVTca/xIORDFXgVZ+2U6p/NfPN5v3dxJgzz1vwzw9kHldAfBwfmbgpahllcIGiE1HS+DpKmCOLajavzLVwlAj0mPRnRIMUPhiN6fs3qZXie+SlI0pnEvtK1SNoXkvBSTmiH1AeHaOaEpCRlUoUMpaq6k1VHM8gjP4K/LhfpNClbxRUXdoW6A1J76O2bTlVF3fyDomo/JMhjShi9BNFouPFV40= 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: Hi, 5 years ago I posted patches adding support for RWF_UNCACHED, as a way to do buffered IO that isn't page cache persistent. The approach back then was to have private pages for IO, and then get rid of them once IO was done. But that then runs into all the issues that O_DIRECT has, in terms of synchronizing with the page cache. So here's a new approach to the same concent, but using the page cache as synchronization. That makes RWF_UNCACHED less special, in that it's just page cache IO, except it prunes the ranges once IO is completed. Why do this, you may ask? The tldr is that device speeds are only getting faster, while reclaim is not. Doing normal buffered IO can be very unpredictable, and suck up a lot of resources on the reclaim side. This leads people to use O_DIRECT as a work-around, which has its own set of restrictions in terms of size, offset, and length of IO. It's also inherently synchronous, and now you need async IO as well. While the latter isn't necessarily a big problem as we have good options available there, it also should not be a requirement when all you want to do is read or write some data without caching. Even on desktop type systems, a normal NVMe device can fill the entire page cache in seconds. On the big system I used for testing, there's a lot more RAM, but also a lot more devices. As can be seen in some of the results in the following patches, you can still fill RAM in seconds even when there's 1TB of it. Hence this problem isn't solely a "big hyperscaler system" issue, it's common across the board. Common for both reads and writes with RWF_UNCACHED is that they use the page cache for IO. Reads work just like a normal buffered read would, with the only exception being that the touched ranges will get pruned after data has been copied. For writes, the ranges will get writeback kicked off before the syscall returns, and then writeback completion will prune the range. Hence writes aren't synchronous, and it's easy to pipeline writes using RWF_UNCACHED. Folios that aren't instantiated by RWF_UNCACHED IO are left untouched. This means you that uncached IO will take advantage of the page cache for uptodate data, but not leave anything it instantiated/created in cache. File systems need to support this. The patches add support for the generic filemap helpers, and for iomap. Then ext4 and XFS are marked as supporting it. The last patch adds support for btrfs as well, lightly tested. The read side is already done by filemap, only the write side needs a bit of help. The amount of code here is really trivial, and the only reason the fs opt-in is necessary is to have an RWF_UNCACHED IO return -EOPNOTSUPP just in case the fs doesn't use either the generic paths or iomap. Adding "support" to other file systems should be trivial, most of the time just a one-liner adding FOP_UNCACHED to the fop_flags in the file_operations struct. Performance results are in patch 8 for reads and patch 10 for writes, with the tldr being that I see about a 65% improvement in performance for both, with fully predictable IO times. CPU reduction is substantial as well, with no kswapd activity at all for reclaim when using uncached IO. Using it from applications is trivial - just set RWF_UNCACHED for the read or write, using pwritev2(2) or preadv2(2). For io_uring, same thing, just set RWF_UNCACHED in sqe->rw_flags for a buffered read/write operation. And that's it. Patches 1..7 are just prep patches, and should have no functional changes at all. Patch 8 adds support for the filemap path for RWF_UNCACHED reads, patch 10 adds support for filemap RWF_UNCACHED writes, and patches 13..17 adds ext4, xfs/iomap, and btrfs support. Passes full xfstests and fsx overnight runs, no issues observed. That includes the vm running the testing also using RWF_UNCACHED on the host. I'll post fsstress and fsx patches for RWF_UNCACHED separately. As far as I'm concerned, no further work needs doing here. Once we're into the 6.13 merge window, I'll split up this series and aim to get it landed that way. There are really 4 parts to this - generic mm bits, ext4 bits, xfs bits, and btrfs bits. And git tree for the patches is here: https://git.kernel.dk/cgit/linux/log/?h=buffered-uncached.7 fs/btrfs/bio.c | 4 +- fs/btrfs/bio.h | 2 + fs/btrfs/extent_io.c | 8 ++- fs/btrfs/file.c | 9 ++- fs/ext4/ext4.h | 1 + fs/ext4/file.c | 2 +- fs/ext4/inline.c | 7 +- fs/ext4/inode.c | 18 +++++- fs/ext4/page-io.c | 28 ++++---- fs/iomap/buffered-io.c | 15 ++++- fs/xfs/xfs_aops.c | 7 +- fs/xfs/xfs_file.c | 3 +- include/linux/fs.h | 21 +++++- include/linux/iomap.h | 8 ++- include/linux/page-flags.h | 5 ++ include/linux/pagemap.h | 14 ++++ include/trace/events/mmflags.h | 3 +- include/uapi/linux/fs.h | 6 +- mm/filemap.c | 114 +++++++++++++++++++++++++++++---- mm/readahead.c | 22 +++++-- mm/swap.c | 2 + mm/truncate.c | 35 ++++++---- 22 files changed, 271 insertions(+), 63 deletions(-) Since v3 - Use foliop_is_uncached() in ext4 rather than do manual compares with foliop_uncached. - Add filemap_fdatawrite_range_kick() helper and use that in generic_write_sync() to kick off uncached writeback, rather than need every fs adding a call to generic_uncached_write(). - Drop generic_uncached_write() helper, not needed anymore. - Skip folio_unmap_invalidate() if the folio is dirty. - Move IOMAP_F_UNCACHED to the internal iomap flags section, and add comment from Darrick to it as well. - Only kick uncached writeback in generic_write_sync() if iocb_is_dsync() isn't true. - Disable RWF_UNCACHED on dax mappings. They require more extensive invalidation, and as it isn't a likely use case, just disable it for now. - Update a few commit messages