From patchwork Tue Dec 3 15:31:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13892629 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 6E827E69EAF for ; Tue, 3 Dec 2024 15:33:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A87CF6B00A0; Tue, 3 Dec 2024 10:33:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A368C6B00A1; Tue, 3 Dec 2024 10:33:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D6266B00A2; Tue, 3 Dec 2024 10:33:06 -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 6F7546B00A0 for ; Tue, 3 Dec 2024 10:33:06 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2965E120B54 for ; Tue, 3 Dec 2024 15:33:06 +0000 (UTC) X-FDA: 82854040206.20.C459038 Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) by imf23.hostedemail.com (Postfix) with ESMTP id 6BC67140018 for ; Tue, 3 Dec 2024 15:32:55 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=jPt3bW9L; spf=pass (imf23.hostedemail.com: domain of axboe@kernel.dk designates 209.85.167.178 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=1733239978; 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=45ZT5fvdDImmdgAdnvc6z/+AzY3WZJ2Fl5NYIbZiSAo=; b=1siB5WCq4sbkWhGmbU5dmqBQKer2QZHX0dL6QzhPU6A1MCxSF7csiko1IqiD/9PeMmAY7w JJoolJeQxnmqPuj4wjm/aIYs5W/DGLd5UsLrzfsC9pn/RRQ+vVHwHk1yhyB7N51iFGkWRr dnfk+K2npPn14GsHpDQbnIF3HTVYfXk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=jPt3bW9L; spf=pass (imf23.hostedemail.com: domain of axboe@kernel.dk designates 209.85.167.178 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733239978; a=rsa-sha256; cv=none; b=whUi4aQKkYOF+6XN5/77BHRkU2h6V1ObTBMDOcFZMVRHA+5jghs9cpSLQ2faE7jeCJk8LF v63xe/abGInWZISpzAnZWQY4Ug/ArZfnCJCxmlfWKpPzd08oCPJ+QpXMPVD9jkjaqNQrOH iSx3kDbWWt3K4DFJcJ+u5sIt8NjTrAU= Received: by mail-oi1-f178.google.com with SMTP id 5614622812f47-3e786167712so2728175b6e.3 for ; Tue, 03 Dec 2024 07:33:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1733239983; x=1733844783; 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=45ZT5fvdDImmdgAdnvc6z/+AzY3WZJ2Fl5NYIbZiSAo=; b=jPt3bW9L3CFp6HWDaRnqqjgbWfYU1VAqw1gE6xE7FNm4RBPFPTUQrHdygjFXDPrebe 33Odk4FbGzHEtldbeR3h63MqrtBZ9nU1iw6pRQr5VZZuj19jB+v1MRTJlSBdC/sn9oOU 5beGrse4nuYwAHJDgno1bKt9NLDHBD+sX2LIxSQigSTluT6mpC//xkBJznoz7lOgTFeM o5FwPrA6b+q3DpjYA8Xxn3AfM2cL5WSP72xWXBFfToa84evZhxqzHzjdmTQV4GYuDOg0 Okt2jESeGIlYEDrYUVwmsWyU/ImjbUUY0pPfhv+XHIZLCXaW2N+CpQQM7LJjmxpQRBb/ iYHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733239983; x=1733844783; 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=45ZT5fvdDImmdgAdnvc6z/+AzY3WZJ2Fl5NYIbZiSAo=; b=SJA8pdkaM55Uebi6QFfSZ4x3GeNE4fo7addBcOxkbIWBiYRom1rEburLV2vHkE6gXf 12hH0NJlMMJOQ4I0+G5/HAcV1bcHu+PHXEDG4746iE7L0SrBFpmbOn/ign23gjuT8Kfo uCP3gQODRTKUh2z/DCQ8xPpeH/H45/pDWBfkUWY+T9eTZKj2nlKhdFr9dt8SDKMK/Lk0 8Dl8u/hO+vTKXczuWUhmwDp9PjRDRdNePJyhLkDFV++7MqhUi+Uvel2p0mFjcATXWSlt X6xXObxP23vThSqoELroHr3O3jvCTZeZCBDrIKRubbPvWSX6aCMKyb8+aeYups9twss5 4KTw== X-Gm-Message-State: AOJu0YxgAcR2/Yi3uFpGFthOBYQXXGk+GMQo1Qd+9Gd1guON8BQe4q4z sjVYpXp8W2UO+5yhEzSZAzNS/geIDUFfPHmAJ11N/TeWvvQcBuYCgGBsfJ1ALVsG0X8UgqPA4fw n X-Gm-Gg: ASbGncvTy1TcnoViYwvLlQ2uksbrF0DxFNj9t94tZ1YX5slnnirKiA9fsFGtgRouoxj lmmyeL4BpjwvYiPArJon1kDVxwVDPbK8fhCIE/I5PS9DaZwRBnBF+7wRZ1kne1UDRP2WVBV2AX/ uZ5+ooUY3pDy1B1gGpbQ7iVaaP954EUcsXXcekaNEyCfOEqOG93NAqRibrHOshRqJSp6puoxu4W m/Vtuhw89lBiK5wI6TyGLilp1LC+bGYfzhZBqP3mYD0Y3Gr0xmmB6itDCU= X-Google-Smtp-Source: AGHT+IFgNffB59kRtGSa279D+oxFDG6GGmZlBVzfslJYY485yS6Rp8valFBlgcp9p+EP83czXVtQIg== X-Received: by 2002:a05:6808:199e:b0:3ea:6533:f19d with SMTP id 5614622812f47-3eae505a0femr2960000b6e.30.1733239982974; Tue, 03 Dec 2024 07:33:02 -0800 (PST) Received: from localhost.localdomain ([130.250.255.163]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3ea86036cbbsm2891878b6e.8.2024.12.03.07.33.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 07:33: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, Jens Axboe Subject: [PATCH 12/12] mm: add FGP_UNCACHED folio creation flag Date: Tue, 3 Dec 2024 08:31:48 -0700 Message-ID: <20241203153232.92224-14-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241203153232.92224-2-axboe@kernel.dk> References: <20241203153232.92224-2-axboe@kernel.dk> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6BC67140018 X-Stat-Signature: jgywzckce1xeswyytdkiw5s9nzensxgx X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1733239975-322383 X-HE-Meta: U2FsdGVkX186Qzrg8lLkTlJOfoQDLBJ6b52b3G/zt5WKj2rv5ztQR/OtKkTllRgIHWq7ssz66+yWJ6MBnm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mlUz6bKu1E676NcrGsePE4/qb3W8te82WFQm1Aq/8udsW13VhurxLoZeM5jo0cfjxxllUkr5jCa7j4fnMpFVIfCuv+kXfWU5GZxBV/Z8oSS1BPSq5r/urzoggwmUZZJ7tLFJl0Ad61jUT90eVD2ucu5xXjbZEaFWnXJMHdB+ID7yM7iww85 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 e49587c40157..374872acbe1d 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 00f3c6c58629..a03a9b9127b8 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_UNCACHED) + __folio_set_uncached(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_uncached(folio) && !(fgp_flags & FGP_UNCACHED)) + folio_clear_uncached(folio); return folio; } EXPORT_SYMBOL(__filemap_get_folio);