From patchwork Thu Nov 14 15:25:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13875221 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 C3C1FD68B31 for ; Thu, 14 Nov 2024 15:28:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 549A86B00A2; Thu, 14 Nov 2024 10:28:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F65A6B00A4; Thu, 14 Nov 2024 10:28:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 321136B00A5; Thu, 14 Nov 2024 10:28:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 07F356B00A2 for ; Thu, 14 Nov 2024 10:28:22 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BA7941C6E9A for ; Thu, 14 Nov 2024 15:28:21 +0000 (UTC) X-FDA: 82785081540.02.1DBAE90 Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) by imf05.hostedemail.com (Postfix) with ESMTP id 3F164100016 for ; Thu, 14 Nov 2024 15:26:56 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=ZWtWqjMo; dmarc=none; spf=pass (imf05.hostedemail.com: domain of axboe@kernel.dk designates 209.85.161.50 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731597969; a=rsa-sha256; cv=none; b=j1PUCh+//BX4bBOxXrGHpmOGdqHc1+MV22FyCXDspdll5hT13azr0vBSvzfcYPeUew5BkI KPCaLtZvGQ83jrsyn8jnTyILgyDCGX7CdRJ+3Ea4Ed12K8cpCDAZIzR8Ooh6tXY2S9by5G UbkAQPri8+bW3GloZhrE03CXP9Jq7TA= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=ZWtWqjMo; dmarc=none; spf=pass (imf05.hostedemail.com: domain of axboe@kernel.dk designates 209.85.161.50 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=1731597969; 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=bh4vHLcSKYCCRkbDjlhjn1EJt3wp9QgKXbTvV2Vr6u0=; b=vVkNKYRMfKhQZE4DAv6TdiflWonmPq/1w9xPa8iIGgfbXU3bNRm3MeD1aRT94/mb03SpZJ dcsrYd9YFBYxfZRquz46m1ajCYOBENtLP5LnOoutslftSUxKXZxE0Rn7+OxX6ymH4AnnVH 11T1n19DY9qgLUBHVHR6R2Ykb8Y957w= Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-5ebc0c05e25so344713eaf.3 for ; Thu, 14 Nov 2024 07:28:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731598098; x=1732202898; 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=bh4vHLcSKYCCRkbDjlhjn1EJt3wp9QgKXbTvV2Vr6u0=; b=ZWtWqjMo0ErKdOUlp2TZrCQAP+kQ+4NbyFK7dy1VbaDOIGdIU6V9Wu9hXO4Q95NLXv xP49tL9wTqZsxPiyAqHFIRm5zrkroT3Ww6sxp7Si+r6mGbNq9cDFQSFbueJAkLVSULw9 0hopTvs3A3JrEwSXHLjuo5zZm2zQ80g5dzi5cnGu1tdUIKFRse7AZlWHMjc4m4K3XeQb hbw8NlrlmTScS8r51KNJhd0FqWY//xyVNAtZaVGj1R2XPzfdRFsxAVsPV/n88z9QXBA8 OYzrgZaNQ/bnI9THx7nJy29gErNttQp6/syG0E6uDwX1R8FRDgp0KDF4xIk1brY94r/9 S3NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731598098; x=1732202898; 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=bh4vHLcSKYCCRkbDjlhjn1EJt3wp9QgKXbTvV2Vr6u0=; b=Occi9A4FId37jV3hLwb12G/4I4JGa5FNZgK+2sJpWhlzZgfiasQusqf9TGIA1skAr9 m6kfsz1hg3AVq4CiAoxse9YITpCS/dV0ptRQsF6Sb+Wa/bW9Zxm/07OSybo7+Ass8IQ2 OLKg/9QSp81uCHNzKO8yXkPhdlf/2tvoXMlowruLntj2jIL+YZY/8vijT7vaWR7MTUpo EXUPI+kz6Eu/ewcNMfk6YFbYHCPdo2mUt4KZy6skS2Tab1rhUjQqMYNI8NDGAblXDomC tNkLjgAZyV2GqurRY5VGx+F6ckEUqB9jFJccrcyLBB5WYhK7wbneOhdTTuCQwjnqiKbW 65Ng== X-Gm-Message-State: AOJu0YyXC0V7dcu+7hodRZzqrLQ5+lZ4ebDWl4RwhfvsuCKXi4D7f7hv XW3o467vCdXqO84l0o/8eLXmr3zqY2Y9Rwg0oRh4Wk97bmlBtMfdnuSSj0Y3IjqHtlmUV11cBqc 5y98= X-Google-Smtp-Source: AGHT+IECtJqHxvsDZk559Jqz444iSDToPVSz/2QlEeAwby3Gwu7O3Iv2UCv4dhdd6n28ENyvjODyaw== X-Received: by 2002:a05:6820:1e0c:b0:5e3:b7a6:834 with SMTP id 006d021491bc7-5ee57b9c8e0mr20035625eaf.1.1731598098551; Thu, 14 Nov 2024 07:28:18 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 07:28:17 -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, Jens Axboe Subject: [PATCH 12/17] mm: add FGP_UNCACHED folio creation flag Date: Thu, 14 Nov 2024 08:25:16 -0700 Message-ID: <20241114152743.2381672-14-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241114152743.2381672-2-axboe@kernel.dk> References: <20241114152743.2381672-2-axboe@kernel.dk> MIME-Version: 1.0 X-Rspamd-Queue-Id: 3F164100016 X-Stat-Signature: h8mu4gx36a6ks8ju1h8zfkgz45mon8w3 X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731598016-165024 X-HE-Meta: U2FsdGVkX1+CmsUddXByCblPDDtI/weFCeqez22V3Td/ucB5fWhc9LfyEEPjmhosPsaCN3lGjMoEzMvmEsz5ET3IVVcSbEPGdE0rzhusG88EcNyi0WbFWzRGiE2GCuEchNIN8Db6zA2oTREEvF+x1m8olwzLGyQRqIcyRJDcNADyz/60vMH0LCLliXNOunfWzGL4CKZ6Q4YRlnKvcHH9u8M6bH0SNhwPptipSZRNhu7LBzGowjLp9eGVEP77/AXHBERxsksnN3WmqJUAQpm5zSlfZFENK4OY4XTTmv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jAAhjVt882QtljbcZ/v6I+Ip2gtxDmOAAZsQX/Ho0J+1vIJhvqsacAmXkhXG5lpYdVI0bt5Bj+93dA/3Q== 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: Callers can pass this in for uncached folio creation, in which case if a folio is newly created it gets marked as uncached. If a folio exists for this index and lookup succeeds, then it will not get marked as uncached. If an !uncached lookup finds a cached folio, clear the flag. For that case, there are competeting uncached and cached users of the folio, and it should not get pruned. Signed-off-by: Jens Axboe --- include/linux/pagemap.h | 2 ++ mm/filemap.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index cc02518d338d..860807e34b8c 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -721,6 +721,7 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping, * * %FGP_NOFS - __GFP_FS will get cleared in gfp. * * %FGP_NOWAIT - Don't block on the folio lock. * * %FGP_STABLE - Wait for the folio to be stable (finished writeback) + * * %FGP_UNCACHED - Uncached buffered IO * * %FGP_WRITEBEGIN - The flags to use in a filesystem write_begin() * implementation. */ @@ -734,6 +735,7 @@ typedef unsigned int __bitwise fgf_t; #define FGP_NOWAIT ((__force fgf_t)0x00000020) #define FGP_FOR_MMAP ((__force fgf_t)0x00000040) #define FGP_STABLE ((__force fgf_t)0x00000080) +#define FGP_UNCACHED ((__force fgf_t)0x00000100) #define FGF_GET_ORDER(fgf) (((__force unsigned)fgf) >> 26) /* top 6 bits */ #define FGP_WRITEBEGIN (FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE) diff --git a/mm/filemap.c b/mm/filemap.c index a8a9fb986d2d..dbc3fa975ad1 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2002,6 +2002,8 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, /* Init accessed so avoid atomic mark_page_accessed later */ if (fgp_flags & FGP_ACCESSED) __folio_set_referenced(folio); + if (fgp_flags & FGP_UNCACHED) + __folio_set_uncached(folio); err = filemap_add_folio(mapping, folio, index, gfp); if (!err) @@ -2024,6 +2026,9 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, if (!folio) return ERR_PTR(-ENOENT); + /* not an uncached lookup, clear uncached if set */ + if (folio_test_uncached(folio) && !(fgp_flags & FGP_UNCACHED)) + folio_clear_uncached(folio); return folio; } EXPORT_SYMBOL(__filemap_get_folio);