From patchwork Fri Dec 13 15:55:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13907397 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 61DBFE7717D for ; Fri, 13 Dec 2024 15:56:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACC796B007B; Fri, 13 Dec 2024 10:56:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A7C466B0082; Fri, 13 Dec 2024 10:56:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 943D26B0085; Fri, 13 Dec 2024 10:56:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 68E616B007B for ; Fri, 13 Dec 2024 10:56:07 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E8B1A14103E for ; Fri, 13 Dec 2024 15:56:06 +0000 (UTC) X-FDA: 82890386922.14.8BA6EEB Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) by imf15.hostedemail.com (Postfix) with ESMTP id 360DAA001F for ; Fri, 13 Dec 2024 15:55:33 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=b6ifpo7B; spf=pass (imf15.hostedemail.com: domain of axboe@kernel.dk designates 209.85.166.53 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734105353; 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=za0bLXvR2ZxwqfIp7xTCo311NzSVeVSxysS9fw8Qkds=; b=oz5hoQM0LsUKWn0JF1V5uI/r5s4bq5YVzFuAsrgZr91p/QMuWPutUQSa9l67XjNgl8FfTe 1bZ25bgvsAcy1m3IOXsJEzUPxeoh1KigxBhfGxwSL9FjCshEecfUYax0jEloh7srsgt29v r7Q8Ov3mSZDle/g0o6VK9YoHW2DQjio= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=b6ifpo7B; spf=pass (imf15.hostedemail.com: domain of axboe@kernel.dk designates 209.85.166.53 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734105353; a=rsa-sha256; cv=none; b=zvDjmkAEGk9x8fU9AaRoU0f/EYREHBsSaTXV00p4cofeD8jPLRYPNcaOqk11ja1XGfn2i8 gHLVEQ5qSW9hOwloXqLJxqFHV9Xvw8jCoCrMjE2Mfspm0+STdAckywz7PYMD3NedPRSwx2 OBMOUOzccPkDczoRamcvSAYuK+dKsSc= Received: by mail-io1-f53.google.com with SMTP id ca18e2360f4ac-844eac51429so54891339f.2 for ; Fri, 13 Dec 2024 07:56:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1734105363; x=1734710163; 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=za0bLXvR2ZxwqfIp7xTCo311NzSVeVSxysS9fw8Qkds=; b=b6ifpo7BzQy9ytQDItzfwrGbUKQaHv2TSjP0KI3D25g/xJE0kZ6hGY5Gapy7XvKdcN 7svp8I03woJ8opGz3qi/eMMxhC98BsAt4ZPIEMU2r9k/ZJdUDZBkXWSf1njCZX/uIiZ6 iyR1jr8Mb9AdwnSi7pV/BZI0oytTqLvHzvQtbjTGvyb4jdVxN7W6Yo9Veze3BcSInnBH HcUHwsFb6CJT9HP1ZKR0hQdzBBNhoSMjLpbVvGi6xpBaExy8nB8TzcAUmvyUYlD9HMml aP6g0eijCKjuf2AKyTaBS2XHNrkoGhJbd9fNpjeI1v42TfG3UNCTe24b3iz/m3NF0nPi 7LAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734105363; x=1734710163; 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=za0bLXvR2ZxwqfIp7xTCo311NzSVeVSxysS9fw8Qkds=; b=RcQh+p/OaAlPVbRs/VpD5ZdKgsNmX/+LIT90hzOjmvO4k9O+fSH1vLo0lT1w9TCdx+ ZjeDRajk+rWr+Du2veJV5TGpUvrfshvLPrBG7jPgyHul8lcOTlpoAEWs0E5xVmDnU0rO AR2EATTWoAnq/+xrWJnGsmpTsoyxupodGbAgMWWwdgzW5QOtCTgPqJwgOtF86oS0zqfg H5SfWHsmniXq35QWMJ+vvzzuqSG2pjUxlAKQiaHSubqTuSIUy48ZwtASFlst416ysAAI F0LidPGLnn+iI6rfPWB2GtcC6kuQSI/Ro9uAXzuNkCiayPUZZHL3rCbBPd/UiyXFMoao RM3g== X-Gm-Message-State: AOJu0YyT7UHS4vKCyydIWqZsoCIsiha5s+hmVj6iVtAxdyyvWEbH5dZS gkbBPEkN/WKFN/gbAdhiUduXD/4+0VLhuduxmJ6Xez7HwPVc1ymIPkmVAk/PLCXsUF1Gi3rSZYq v X-Gm-Gg: ASbGncsjn9b9furmFckZ6DNKDzY/HX/EK6/dNbwnsV8TlQA4V6qEYDvTNya9VxiWnCV HXq0jmYK+scDkgvMDwfLVFY/PZWZUvR6KRaJXvI8mHf+an2frowzTEHOT/PNCTw7mQLkgFZXDji PcTFJ/9+3GHe+F2f2vf9Yjhf9MtC2E4ofHyKJsvFYbA4W0yXCCglwIuTVFkYpqxUPhYO435v/1R khmKQzRD8dLGGbY7qD6Tnnnv3PeyR53ahSC40dgA1B6zMTBoKdisTUyNfQ8 X-Google-Smtp-Source: AGHT+IHylx/3oulFehnVhUto4Z0aFot/OVrF8JHJ3N5rc4ltn5nu/Oa1A1HwG6LLrEzas0hHyeATmg== X-Received: by 2002:a05:6e02:1b0b:b0:3a7:8208:b843 with SMTP id e9e14a558f8ab-3aff19b7d9amr38862585ab.23.1734105363016; Fri, 13 Dec 2024 07:56:03 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3a9ca03ae11sm35258405ab.41.2024.12.13.07.56.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 07:56:02 -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, bfoster@redhat.com Subject: [PATCHSET v7 0/11] Uncached buffered IO Date: Fri, 13 Dec 2024 08:55:14 -0700 Message-ID: <20241213155557.105419-1-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 360DAA001F X-Stat-Signature: hqpja6xn39r3d69c78pchh65p1fcm4e4 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1734105333-464462 X-HE-Meta: U2FsdGVkX1+WqO9NcL/uK8jV/tpBVmXNksqeZ3BYybLB9dmGeHNN/Gj1wZsB3Sww4Q/2FxoXxzWgC9cGgwFWd6eil51l11uGkWuOVEwDAnPZwJoodoKpHD3I5JyShS3o1Vg6oVh0ApzoJaQBQcpZxQoNzcrLNUkWzac53fugcp03IDoJ/sejwGO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pW3cIG+sWUH75kCgOdvBp8BckhucGnrkUzwE4L4KsEfl6MAPWvJkK8HxYwEE38MIn7lOB+0pZacjNi0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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. Due to excessive bike shedding on the naming, this is now named RWF_DONTCACHE, and is 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_DONTCACHE 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_DONTCACHE. Folios that aren't instantiated by RWF_DONTCACHE 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. This patchset adds support for the generic read path, which covers file systems like ext4. Patches exist to add support for iomap/XFS and btrfs as well, which sit on top of this series. If RWF_DONTCACHE IO is attempted on a file system that doesn't support it, -EOPNOTSUPP is returned. Hence the user can rely on it either working as designed, or flagging and error if that's not the case. The intent here is to give the application a sensible fallback path - eg, it may fall back to O_DIRECT if appropriate, or just live with the fact that uncached IO isn't available and do normal buffered IO. Adding "support" to other file systems should be trivial, most of the time just a one-liner adding FOP_DONTCACHE to the fop_flags in the file_operations struct. Performance results are in patch 8 for reads, and you can find the write side results in the XFS patch adding support for DONTCACHE writes for XFS: ://git.kernel.dk/cgit/linux/commit/?h=buffered-uncached.9&id=edd7b1c910c5251941c6ba179f44b4c81a089019 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_DONTCACHE for the read or write, using pwritev2(2) or preadv2(2). For io_uring, same thing, just set RWF_DONTCACHE 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_DONTCACHE reads, and patches 9..11 are just prep patches for supporting the write side of uncached writes. In the below mentioned branch, there are then patches to adopt uncached reads and writes for xfs, btrfs, and ext4. The latter currently relies on bit of a hack for passing whether this is an uncached write or not through ->write_begin(), which can hopefully go away once ext4 adopts iomap for buffered writes. I say this is a hack as it's not the prettiest way to do it, however it is fully solid and will work just fine. Passes full xfstests and fsx overnight runs, no issues observed. That includes the vm running the testing also using RWF_DONTCACHE on the host. I'll post fsstress and fsx patches for RWF_DONTCACHE separately. As far as I'm concerned, no further work needs doing here. And git tree for the patches is here: https://git.kernel.dk/cgit/linux/log/?h=buffered-uncached.9 include/linux/fs.h | 21 +++++++- include/linux/page-flags.h | 5 ++ include/linux/pagemap.h | 1 + include/trace/events/mmflags.h | 3 +- include/uapi/linux/fs.h | 6 ++- mm/filemap.c | 97 +++++++++++++++++++++++++++++----- mm/internal.h | 2 + mm/readahead.c | 22 ++++++-- mm/swap.c | 2 + mm/truncate.c | 54 ++++++++++--------- 10 files changed, 166 insertions(+), 47 deletions(-) Since v6 - Rename the PG_uncached flag to PG_dropbehind - Shuffle patches around a bit, most notably so the foliop_uncached patch goes with the ext4 support - Get rid of foliop_uncached hack for btrfs (Christoph) - Get rid of passing in struct address_space to filemap_create_folio() - Inline invalidate_complete_folio2() in folio_unmap_invalidate() rather than keep it as a separate helper - Rebase on top of current master