From patchwork Fri Dec 20 15:47:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13916943 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 D9EA9E7718B for ; Fri, 20 Dec 2024 15:49:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E19296B009F; Fri, 20 Dec 2024 10:48:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DC86A6B00A0; Fri, 20 Dec 2024 10:48:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA5146B00A1; Fri, 20 Dec 2024 10:48:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 994CE6B009F for ; Fri, 20 Dec 2024 10:48:54 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 37A66C0B53 for ; Fri, 20 Dec 2024 15:48:54 +0000 (UTC) X-FDA: 82915769916.16.9A0D15F Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) by imf16.hostedemail.com (Postfix) with ESMTP id 4717818001E for ; Fri, 20 Dec 2024 15:48:17 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=dqVjau5L; spf=pass (imf16.hostedemail.com: domain of axboe@kernel.dk designates 209.85.166.179 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=1734709716; 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=86GdD84SMshyNZnB2LgwxYI5vb/3z8g/QfHnuRLr9vU=; b=5SLivOTERfF4Y0mdHERfAx87ekdKeWsme7Lyo2QtKKFLqTqHP0tEindctk3f4QU/oCoorc JQ2ORp89gXDPsyYShLs2/NOX0nTGY3A1TkV8KZh44F1RtPFVNW2K6PHxjM5pghEeDiv48W swIVlF0DZgVWRlQJEniQPLEwheafiBE= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=dqVjau5L; spf=pass (imf16.hostedemail.com: domain of axboe@kernel.dk designates 209.85.166.179 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734709716; a=rsa-sha256; cv=none; b=dDkp6QG0p/y2o7Fm04cW5JFSVbHygB0b7NCyjMjvbMQA1NlpPxZm55lLXiabIkpdAX7LFv t7DLzFn9ysfPDJvS0Rhc0TNAfBXukvYnz7mb0aYggGEej1YMxPeTXNaH6ILKXLSBQtVFge x8XK803TR7gJ3Ye2Pvdlq0uc6cW3V1I= Received: by mail-il1-f179.google.com with SMTP id e9e14a558f8ab-3a8c7b02d68so14944175ab.3 for ; Fri, 20 Dec 2024 07:48:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1734709731; x=1735314531; 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=86GdD84SMshyNZnB2LgwxYI5vb/3z8g/QfHnuRLr9vU=; b=dqVjau5LHNFoNCA9KK63lBJe2oSOtOzu2whqpRnj5buO03uuTAG2iV0pVrvQHAYSjC gsIyIkSrwPpijOYvkJclFZaKQu2hdSMr5ruaLwP+SBWKK2TyQyK279uhRCqA/VVoMbQg D8p4yWg41Qm+55FtphdHJEiK4vNhIV8HUv3BchE4JRAWGwaB12ZtyIYC7+b+beDBWxOF 88x5pn1LzGmt35KuwsfI+neSUysWukj3jB6TPdqvJctWttky0eT4RlciAiBbjO12HTho gy34uVIfPgMZ912arOEXEpcQcDCLX3zgQh2kaETS0oHqgAed+uMBlPCe7zRsPQ2gJybb 6zpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734709731; x=1735314531; 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=86GdD84SMshyNZnB2LgwxYI5vb/3z8g/QfHnuRLr9vU=; b=kKsMriLf2MiPK2WbxQ073qAOnDGWNoEhqemtApN44RKY+b3X6CKUq0UsNi+8Q3mOb+ DIaHThgReum66ag5BOcNH+9XtBRgf/eFFdHgZFsYYmBbwhOoxcQswJsxSMFhJl/DLJlw grMI35s51d0HoPqV1gUUkiabbdhGUqXt8dhxTPKwsJEbEPmdPhyLzX1408P1TFMe/qZD +jnd9PVoP5KX1sNpUI0x8UcUHslKfzkCmyQb1s9RX0OmaQ0MVnKGyFQWjgz1OVLh7sA0 Sk8ADcQUmYAM1iXGu/51RBA7G2WPbVMeHuwsetsTVL5okbuKK6NZFeCyGHaYyH/bnX0y 2/Dw== X-Gm-Message-State: AOJu0YwxCDl1i6LRprw94mrpOJrKIreVADdRlGs58gywXoSwGdBMKOYC vlsl0MjYrpidfmmh4Ak26BA1D/t7VWH68fz/ASfOzvEFoiedazUoey5OSEw98a6bAj2dwvtEHlj 5 X-Gm-Gg: ASbGncvjXr6+KtUmYAkxrZe5iNN31vYsUdELhv4pT/2mlQbuBI/npVLdYsUWiKuSr5n IxOwrnoa0af/h0AjRrHEL4td595SD/e9fibb8z93Dz5V9xcRAJI3B5raRGFptKcmvZwgc8eHM7U t+naomwcRZ6PkHLGv+bJcUPnwV9yQOYmwqTjoI75AirDjuLh6EMNi+xKMRsUflMz7ReH6CdaLcr Ae+JYwliFN/6qR+1wcWk6SuKkz1nWu8SLJJTkB+DOQ8khxPuKCzPUxiWZKW X-Google-Smtp-Source: AGHT+IENwEpB78XkZV/FFvO7zp/8wAKDMGCn+bUr8XfGQ9+IvUs//gy2KTAuIDXDGGYGOcgB+kegLA== X-Received: by 2002:a05:6e02:20c1:b0:3a7:e3e3:bd57 with SMTP id e9e14a558f8ab-3c2d533e943mr33235325ab.15.1734709731154; Fri, 20 Dec 2024 07:48:51 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4e68bf66ed9sm837821173.45.2024.12.20.07.48.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 07:48:50 -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, Jens Axboe Subject: [PATCH 12/12] mm: add FGP_DONTCACHE folio creation flag Date: Fri, 20 Dec 2024 08:47:50 -0700 Message-ID: <20241220154831.1086649-13-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241220154831.1086649-1-axboe@kernel.dk> References: <20241220154831.1086649-1-axboe@kernel.dk> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4717818001E X-Stat-Signature: 63mz9hqanicqqm351riy99a7ogora7sx X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1734709697-773948 X-HE-Meta: U2FsdGVkX1+zW+00v5aHv7G7oLsPEX1BW2l1Na3ESropn+N3DfiWhxz1svZdj1Bf6OFGMV+N74BukKzeeIbT5+3BSkA4veXx3uStYWOr9F0kc1X722uLx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b5bRuUn2wgQje/gW5EOcZ1xPPJkvQbIqTSR8Ybqi2jbxfY/yt0kl3+DUAPZCdfDbE2Fmp44mfX3KyELO/hobdj2JhNGRt0JCwM7cGS3ZmTPFKoLgB64WmdnghF5ZpXqds+DonfcJDduvx9IuvKAVc57pkXmyKwW 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 5da4b6d42fae..64c6dada837e 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -710,6 +710,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_DONTCACHE - Uncached buffered IO * * %FGP_WRITEBEGIN - The flags to use in a filesystem write_begin() * implementation. */ @@ -723,6 +724,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_DONTCACHE ((__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 9842258ba343..68bdfff4117e 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2001,6 +2001,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_DONTCACHE) + __folio_set_dropbehind(folio); err = filemap_add_folio(mapping, folio, index, gfp); if (!err) @@ -2023,6 +2025,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_dropbehind(folio) && !(fgp_flags & FGP_DONTCACHE)) + folio_clear_dropbehind(folio); return folio; } EXPORT_SYMBOL(__filemap_get_folio);