From patchwork Mon Nov 11 23:37:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13871494 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 4BAFBD3ABF4 for ; Mon, 11 Nov 2024 23:49:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75D7C6B00E2; Mon, 11 Nov 2024 18:49:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E6B86B00E3; Mon, 11 Nov 2024 18:49:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C3876B00E4; Mon, 11 Nov 2024 18:49:09 -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 24A396B00E2 for ; Mon, 11 Nov 2024 18:49:09 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2E142141B16 for ; Mon, 11 Nov 2024 23:49:08 +0000 (UTC) X-FDA: 82775456316.23.67E786D Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf27.hostedemail.com (Postfix) with ESMTP id 701D64000B for ; Mon, 11 Nov 2024 23:48:24 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=2PJDInq4; spf=pass (imf27.hostedemail.com: domain of axboe@kernel.dk designates 209.85.210.170 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=1731368714; 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=MuWHSESvZxScxt1gtQJTtWY+NoQXodLd0kknM0wzZSI=; b=SwjWBUtrkfRW/nVxvHKYADOkhPW0vWnE6QnDjkYCWNSkIp9XRazNEg0xqOL0SBQCKn/I4X 6jNbpKu0fw1B8/AhWsYPZqB8TwVYH3KAg/7uf9JT8cQTM5InJZHNPfTaR0IV1/gAOJUf5h NETUDVgXqO519rN5d1rDLEx2g+cOqB4= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=2PJDInq4; spf=pass (imf27.hostedemail.com: domain of axboe@kernel.dk designates 209.85.210.170 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731368714; a=rsa-sha256; cv=none; b=Ic7Dc9MmrTHP+z4k7sCSqSNo0BP7gFsohfpdM4s/uGxrwjtaRcxW/TLJe8h0RVeVF8Ulfa QzdbQ0cjX5HNxz8FB6et6/W2zUe0yMjS8aPh3m8AwrmII4uF0csd4DRYoJojHB9f3m5ouM zkreiSuTkLG/dGfD8suHewriVl7WwXI= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-71ec997ad06so4154542b3a.3 for ; Mon, 11 Nov 2024 15:49:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731368945; x=1731973745; 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=MuWHSESvZxScxt1gtQJTtWY+NoQXodLd0kknM0wzZSI=; b=2PJDInq43te7Q2p4LBx95oG6F7FfIq2lqCU4T2+ftJkPsIgnamhhvb8QJyyC+yfSgl LB9576RMDb3Ex1xWiCrs7Z5AYlMALxQmPpphFHEWQ3AF6fouaYcptgDU5QEfZSVERzVM xfrFTfVeNLv5aNb17Crw8VwDFLlYyKe9WadJHawp75iEzDeb2KNtiSIQg16irbXdSs5/ cTzGStOqALLf5khtkROetZEnDJXBuO2DLa7avOW9DFolJIYsioUJUV+lAtxebzgJG3A5 XdDtaUrtUcHW+JohNE2hkY5lyNzmn0HHZ3zDO2DMEDzrnGZE3oRUP2z8KmfJjd23lqpy Kvvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731368945; x=1731973745; 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=MuWHSESvZxScxt1gtQJTtWY+NoQXodLd0kknM0wzZSI=; b=tnXgAIfwVdtjTNUDZntvDB11M8G9Atf1rBfN0tF+EqEALjV9rqChgPV/FucnI9FI2T HCzoPDxiNzIXTl+J5HANyzteamOjTNSx3gYN4HhG8nS9QGxhOrF9GLc2GTAywkgq5y6k 845G+UacRmlop7Kj1UYEEvrCwbioL8X/SWaNTvLgF2de/Jkc/XQKnnvfA1orCm95GSiW RU33GqKGQTe0nYtdC10HAIkUcLFXMAqDL8yIt+nxQFbFODUzRS7Nc9aKaNGs+2TNQlmH 9u0NjddECFxp7nJ+NbqDyaxwrsD9hdo+tvJLp0TwzL1mv5iAdD5tFB/nTHFqBbowRT+q VtLQ== X-Gm-Message-State: AOJu0YyqtcnuJ9qrWI+0tX6OyD1SFp/1eMX676Pus0eokqpLq0RVLdMv qnhogSnYn7E7MVseb6sZxsBCtH+hncgEdeYe1umOY6Tzojnr9xVDqOi7MvUAAGwMjRzjS7C/S04 vZqc= X-Google-Smtp-Source: AGHT+IGY8U2EPa5TOjOCgJt8zYCC4on7T5T+FZCdrixkNsVQpkNRkQsZMbpHQUFVB4Pf9fNlDncpCQ== X-Received: by 2002:a05:6a00:22d2:b0:71e:755c:6dad with SMTP id d2e1a72fcca58-7244a4fdea0mr1056066b3a.5.1731368944673; Mon, 11 Nov 2024 15:49:04 -0800 (PST) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724078a7ee9sm10046057b3a.64.2024.11.11.15.49.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 15:49:04 -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, Jens Axboe Subject: [PATCH 11/16] mm: add FGP_UNCACHED folio creation flag Date: Mon, 11 Nov 2024 16:37:38 -0700 Message-ID: <20241111234842.2024180-12-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241111234842.2024180-1-axboe@kernel.dk> References: <20241111234842.2024180-1-axboe@kernel.dk> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 701D64000B X-Stat-Signature: e3zpqmqz4cfb7hhriug86obxb8br64cf X-Rspam-User: X-HE-Tag: 1731368904-535872 X-HE-Meta: U2FsdGVkX1/StCpz95sYWLpUGxyoBmJELRPe5RAA8tY/chJ5J8gfNmyBRulDSzaHPC3GUvqB/924oU33jD1zR4eBF2Dz1miLnXowWqZc6WyvlwOHjA6eOZMrrD4KGbKIeUCMmerDmxU34BRRy2eJDIlvYywLqLS/M+gqisUIgnz01MQSHAjHSPUMkW8rLvL6+s3yonp9pOSxsHjp4Tlw7DfBUT3zEKlNtynbhY7f+ShEYADwaGkIocNRw2tIC/mnOQKYHFCkgjsZVWGlStpA4ScPku97iDLnxx0zAF+gFs3DBQ0lgAAM6sTEeptLk9mYIpiHcYuFkjQwQWqkHYqRXaSN+q89yXAv1xQx3Bj4L9sxTpqGJavq4yOwQX9MGpezvjUHrH0u8uq6BT7HXNjPldugSpfLT+lMnOp0rfs6Alf6eBzwKpKgmUopN1KDlvj+S19FW62G1kMJ8LSlLzE43WKDyrZfsh/lD6u9uc4NY6f0LnpgKOpLNntM7DADuwCf/moCLxhOGfQBiIwDwwV1Fax+znwn5OnMfvUHJkSySK2RLno6sNnQyB9E5SvQx7z1o4S0xzGNrhAI/CPOu7KcfrY8SODGQqhMPeo3pRPupIiCuiZ6Xrncr7W34P1VYaJoxiHB2fLPq6enwOF2Vume2ZgcE4sjNtsOSN4zyaxkw1Ww1Zo2CjLAPloKrOMInl9gsox23C/YSl8GOKK0YfwT7Nsoa/4IVWid3FRV+BbDiAupZVIkFYqbG38Z4xIKSTFT6fit6z0S9oWtxcmefTcGBnmFepbdgdECzRPg2k4qB/yteD3W1lv4eqmJO5Jje6xB2CuH2x2WtcJ+bfOfAqJPtX+6x/q5ECZxM1h6QqRpkAgQ88PLu4dWYNG7iMyN85guR0nyiVP1jFjD1XGiedpODH90E7BZscSdpAMZu6fvHJt2Kfwq/SwbudMQi+XL+wvMvEjBGETr2HUjtKD9BFy 9Qa3SBPS lmr2bAlpuu+CmTk5gRjxtqHfByluwwxDIU2Vhvc53kxZHFD19YN3JUIO+DLh4y/SXBf0qLx/eROHiU0O0fytYTlwYCvfhIAJbg26UKcHB6JXQzsTMECYbgaqfNLQJRrLDY5aEprN4EoThjyynMCI1qV2IxTM+poFmex5mLL0FjcXuXKRYYf1RdbbcKOaoL6IwYVcK66EuogrAf87mzbgQmPOcenUUX/4EvJR6Zg8Zg1HE2uUxETAbWE63/4QGB0JNaxURdUqeJa43R0RMtBpLki7GSeOEnUqDTke0zOzH2cJp+CnbiJL34nMtFXovk2yBFf2I/OxTw4jgSvUUHZt2Ez4dgje5on4xGcC3 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 d35280744aa1..0b298e81fcae 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -741,6 +741,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. */ @@ -754,6 +755,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 0d312de4e20c..0949f0f340f5 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1985,6 +1985,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) @@ -2007,6 +2009,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);