From patchwork Fri Nov 8 17:43:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13868804 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 F3A02D64074 for ; Fri, 8 Nov 2024 17:45:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C4156B00E8; Fri, 8 Nov 2024 12:45:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 872B96B00E9; Fri, 8 Nov 2024 12:45:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EFAB6B00EB; Fri, 8 Nov 2024 12:45:32 -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 138BC6B00E8 for ; Fri, 8 Nov 2024 12:45:32 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BDBE81C693D for ; Fri, 8 Nov 2024 17:45:31 +0000 (UTC) X-FDA: 82763653434.06.A816E11 Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) by imf30.hostedemail.com (Postfix) with ESMTP id 198AE8001D for ; Fri, 8 Nov 2024 17:44:19 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=vmnLOpy4; spf=pass (imf30.hostedemail.com: domain of axboe@kernel.dk designates 209.85.167.171 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=1731087878; 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:in-reply-to:references:references:dkim-signature; bh=2fb9FZGyCFOFnaRiTxheAGhz9Js7yp85PwlVOXqpxuQ=; b=a+bPgL+sxHuPXdrERkt5rf+rpDNdzIZZYIbtzyzj+5K3dGFa31Ln1PxKUdPum6hu4w+jeA uNGvXzZ5BT6BYj6UmvLlqRfck6p6Kx813ldRYjigGpx34O9eudbA7RYuuyW6uRycM9cjU2 zxxRxNPmm/JKefSfqN00TzVJBmKD+BU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731087878; a=rsa-sha256; cv=none; b=jyFq1lw0UjrRCOOGDUb5XBc+Di1POkuOLcqH3JtbdKEAZosAPi9oG5//4hYjYrKR+xOUj6 MsyeVJTOKeQg39bmLYUqF3Vr6mzuXdl/bBHP0z/8p9qGxtB3hI/4h8zFtZ1haSWNOWgDm8 N7Fs80tCPI/zfHo2fNRXZnUqj8ilc50= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=vmnLOpy4; spf=pass (imf30.hostedemail.com: domain of axboe@kernel.dk designates 209.85.167.171 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-3e6048bc23cso1497177b6e.3 for ; Fri, 08 Nov 2024 09:45:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731087929; x=1731692729; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2fb9FZGyCFOFnaRiTxheAGhz9Js7yp85PwlVOXqpxuQ=; b=vmnLOpy4ER9mma0FxFCVZazuh9B3r9duraQGmwqfecBAdvlaJF8556oacc1Qr0KPsX MxAssnWeEULn7cIy5R1R1i9qUQLrWUGE6/L0GyX81wmDpSI4eK2jZrXRov8XgJs5LHae Q+MKhLopUhQqxJx+l1G2DMCSIywib0hmnz2tF4y9XfArdVKcu7EG5Uk1Zz3hbVQVhalB gyuwPVgC9PuCAZxhzpyNoTP/2fBTt9w6Nbi+9PZLoGIAsWwI0gFJgNRFqjgc+sibiYV7 DwsM5a6FVO+AE+erJ49YzP6fECACaCMJ0p28lr4qLVQbhodqFne2g1eozWjVmS/95WXE jxWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731087929; x=1731692729; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2fb9FZGyCFOFnaRiTxheAGhz9Js7yp85PwlVOXqpxuQ=; b=tpPPCOhMuM+6m0l+61MnjFgRW7sXtKWb0kJ+h5e3xNq+jbydMAkVlAeJrtDm5x6vJO jm6CGrJbi8BbdwsURfGsnzJCwxBF4wo7bKUKD/rlIPauk57oQQlRaZAB9RyAPC4pqvoM QDJIseMflazcALYOLK1pJOhrO/CEwqz0gzqFkmN8Jd2GBrsVr7Cl2mUNwpk6l7eaqpse U/ak3kDHKoXk5aIJzAW4kqBgrEKu+5iiE0LRd51LfyICfHvJalEimnyk3zEVvbJjjlvZ C5getV2uAAIJV4N+nvRWqRUhVoc6Uv67VUw50kEBvtEf/f2IGeTCkobQsCKcNAJ0721d XWnA== X-Gm-Message-State: AOJu0YxpLwesmQmLyTMqTajspzXB4dQxaAXvfV5A3HpwxRnkxdfBkHlG 4R9Y8ARCJlcNIuFXiHxzrCeOkqtqOF3cM0id6IazD0rlLVSCKoTmw/tdzmBrev6uBbh/TAWlCHf qK2M= X-Google-Smtp-Source: AGHT+IH8lOHs5F7JgjBYwdnat/pkPGU3i89izTiRydGTFEpVaYP+S65Vq9chKUX3hmqFUZHNf6tOPg== X-Received: by 2002:a05:6808:1922:b0:3e6:61f0:4797 with SMTP id 5614622812f47-3e79477095cmr3867819b6e.40.1731087928735; Fri, 08 Nov 2024 09:45:28 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3e78cd28f80sm780969b6e.39.2024.11.08.09.45.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 09:45:28 -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, Jens Axboe Subject: [PATCH 11/13] iomap: make buffered writes work with RWF_UNCACHED Date: Fri, 8 Nov 2024 10:43:34 -0700 Message-ID: <20241108174505.1214230-12-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241108174505.1214230-1-axboe@kernel.dk> References: <20241108174505.1214230-1-axboe@kernel.dk> MIME-Version: 1.0 X-Stat-Signature: ry6bceimmb3r5br6wgang9pf5gfddc7d X-Rspam-User: X-Rspamd-Queue-Id: 198AE8001D X-Rspamd-Server: rspam02 X-HE-Tag: 1731087859-463646 X-HE-Meta: U2FsdGVkX1/0LOY32oSsWN7DDJ5+6OA86D+OfVZerAkLK5MyKuT/XY07fZ9QYhAfxo42tK2ZwIB21sFKjUdiZdhIen9IXkzY1UD9C+NNJSVNBI7PIOra71vl6p29GTIZjT52pyjq6GYBXoSGGqBSP3z5cTpcWmZhpKzHnH0UbYjulP3L0i3QzWTCPVOcmFtNz2aj+mKsCsqaed0bvAviFFqC96H4prESC3I/3W4V//t0j/wBo35Oo1JKgYyH5XeSSkiv8bxH9+ELoXnRi+OJ8xAKo3mVG2aOrb4XxmOSyeCSUDkdq1RzVXGsRHyXY36Q+DovlALV8pvXri6/ItY+0Nf+njWzK69TRLpn5/6TMTCw4iwmNVtRiaAgdfIrgK7bD3A9Iv4pZf6kiMGlq0XrJLWY71cfPLBphk6+8ZhdvqrQJi11TU3DnAEiQZA5bOtaHfeDmss9Y5EjLrguvfSY0ZPvCrRC0m15S7IeS4wh5widV0ZZRBlcAhkQLZpAzHgoPWeGQILsXxmKethTgKq7AI93HzIBHFLl226PbPz82YQAZ5KNjWcq2EItWVMZS8z+ARi/wGK+Dtz2SMFGvo5D8CLvEknijfGFpo8ky/mP9y4oi1GZcH4Ew0IhU00kk7IlabGUj66qhEaKjMwDAxLYzTJmaknRYrTVuVmkrDIkDB3SKuv9dMY4xEnejxNQK3OJNd2V5Nx3GKqjbIy3bjxaDqF2Q7lfrTyGcunem4rsbIrFyRy/s/fRrl2sKkHzPaiCi/LtPx576io6iLWfR89E0hh43Xc8aopMo+l5rp9fYxkSH0zKTHmZSOJDizjMBAt2l813ZGYG8grwcrahWRlNA9N/wPYV205Q/fxwHh7JSAl1cNWufkKqI3BSgNUbgTp2ZDzZRNv60V7t+slyFmaPwrJwZrtYn3s8XQeDHNJ2BgHXEAyQpc2pevETNzD2tkrPNOaGKz9nutZgcyCGS+4 ia5HHSsX veramc80+8tO/IUWSst71SRIv19n7t/ML/VmCFipg9w4CX7CTFRfuaIZjLGGs6v7F4UFb37fDKtpDgMusc7ju6ffKXSygTfWsUwSPP6+okZ/ipAoAhtj3NojiXmFqqUw/4ZCc4MpAKlJulCS40kEWphOQDZY3Wu2M2vulmw+NBoTq7F8QYhfxwfLIOcXiS7bnx/1EhfqKM+R5HaZohvRgfGGbPWsyZO53ytWVFYhDHVntnuqbaAsTO2u42vOcLvqSgVieMwW6NC7Kd59pqz660MKfa5lO91VBMYW4gZ8y8l+m/QNGJ2Bsn2mLTvcVM2ijzf7/wbcufb/G3jxlAW9KheY0PY4A2OOCrjOM 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: Add iomap buffered write support for RWF_UNCACHED. If RWF_UNCACHED is set for a write, mark the folios being written with drop_writeback. Then writeback completion will drop the pages. The write_iter handler simply kicks off writeback for the pages, and writeback completion will take care of the rest. See the similar patch for the generic filemap handling for performance results, those were in fact done on XFS using this patch. Signed-off-by: Jens Axboe --- fs/iomap/buffered-io.c | 12 +++++++++++- include/linux/iomap.h | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index ef0b68bccbb6..609256885094 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -959,6 +959,8 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) } if (iter->iomap.flags & IOMAP_F_STALE) break; + if (iter->flags & IOMAP_UNCACHED) + folio_set_uncached(folio); offset = offset_in_folio(folio, pos); if (bytes > folio_size(folio) - offset) @@ -1023,8 +1025,9 @@ ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, const struct iomap_ops *ops, void *private) { + struct address_space *mapping = iocb->ki_filp->f_mapping; struct iomap_iter iter = { - .inode = iocb->ki_filp->f_mapping->host, + .inode = mapping->host, .pos = iocb->ki_pos, .len = iov_iter_count(i), .flags = IOMAP_WRITE, @@ -1034,12 +1037,19 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, if (iocb->ki_flags & IOCB_NOWAIT) iter.flags |= IOMAP_NOWAIT; + if (iocb->ki_flags & IOCB_UNCACHED) + iter.flags |= IOMAP_UNCACHED; while ((ret = iomap_iter(&iter, ops)) > 0) iter.processed = iomap_write_iter(&iter, i); if (unlikely(iter.pos == iocb->ki_pos)) return ret; + if (iocb->ki_flags & IOCB_UNCACHED) { + /* kick off uncached writeback, completion will drop it */ + __filemap_fdatawrite_range(mapping, iocb->ki_pos, iter.pos, + WB_SYNC_NONE); + } ret = iter.pos - iocb->ki_pos; iocb->ki_pos = iter.pos; return ret; diff --git a/include/linux/iomap.h b/include/linux/iomap.h index f61407e3b121..89b24fbb1399 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -173,8 +173,9 @@ struct iomap_folio_ops { #define IOMAP_NOWAIT (1 << 5) /* do not block */ #define IOMAP_OVERWRITE_ONLY (1 << 6) /* only pure overwrites allowed */ #define IOMAP_UNSHARE (1 << 7) /* unshare_file_range */ +#define IOMAP_UNCACHED (1 << 8) /* uncached IO */ #ifdef CONFIG_FS_DAX -#define IOMAP_DAX (1 << 8) /* DAX mapping */ +#define IOMAP_DAX (1 << 9) /* DAX mapping */ #else #define IOMAP_DAX 0 #endif /* CONFIG_FS_DAX */