From patchwork Sun Nov 10 15:28:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13869952 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 DA92FD12D44 for ; Sun, 10 Nov 2024 15:29:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A67016B00B8; Sun, 10 Nov 2024 10:29:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 900016B00B9; Sun, 10 Nov 2024 10:29:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77BA76B00BA; Sun, 10 Nov 2024 10:29:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4C8476B00B8 for ; Sun, 10 Nov 2024 10:29:30 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id F185B120E1C for ; Sun, 10 Nov 2024 15:29:29 +0000 (UTC) X-FDA: 82770568482.30.AABD959 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf22.hostedemail.com (Postfix) with ESMTP id 35432C001F for ; Sun, 10 Nov 2024 15:28:39 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=uxtVz91c; dmarc=none; spf=pass (imf22.hostedemail.com: domain of axboe@kernel.dk designates 209.85.214.173 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731252506; a=rsa-sha256; cv=none; b=W/Dxku8nw99dO3clJpcsTA3RvA6VnQYrf07lEL1qQWHus+5Kv8Zo0DDdxVPeu5n1lUbSXM heWTY4NmJOl0aNlYUUrMEDX5Qiwqlz+1vOPRfyeUYWcCOvcnI2EBMGEOwgiVNBHyZHFQhz hJoEnrSxiHJb4zO5aW9YsVdzkZua7a8= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=uxtVz91c; dmarc=none; spf=pass (imf22.hostedemail.com: domain of axboe@kernel.dk designates 209.85.214.173 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=1731252506; 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=xtqsp3FpRWE9h3nra5m9D1cpUkXI8hkSCKuFCrWSblw=; b=13FXyrmnOI+XxG+IFmgad/oH6/+oxT5w9Qe3OP71df24hLDc6pTxzPD7LFZRVSXJNMCFNf 2TIzYk4HAdYzpy/6U5oLEaVrwDnNPt56ZYTBQUfNgsGnQuLCvQPrXPZ6HSmekb1sKU6l1E gie9Dxr6rzovKj3GZlnGp6BR9Lld61A= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-20c8b557f91so40229285ad.2 for ; Sun, 10 Nov 2024 07:29:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731252566; x=1731857366; 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=xtqsp3FpRWE9h3nra5m9D1cpUkXI8hkSCKuFCrWSblw=; b=uxtVz91cVsc2WyOKcUH7fr8ENmAXGh2U3QYmPYEE9Ry9VgcCUGmKHnkdHZtKRG1YiP wk5dWR8j7HX9VLpWTkQ47Ddb8B0CnfO3yuXH0SLU9puMkZLLyIpZ7HycyNr6GpdqA7/z kXhnyZPDMT7EZYIEcTn2C9CLZP0mfVkiswUSLGoVM22bk938l+ASsvR97EVsqrCCi/7f 83/RMBeYnl5hfiCDeFRRLYA43w3Ril39sTO4MT615D/RXEjs4VIQ9+auvYN/rg5OAyRk h5Z0qYSwoKGNXeSmKUEZwVcK58qmTekWRkPmvARZpkYSgQNayOHXlUqU+cXmxb6aHi4B xS5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731252566; x=1731857366; 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=xtqsp3FpRWE9h3nra5m9D1cpUkXI8hkSCKuFCrWSblw=; b=p02aVTUcO4mh/TqZIDHUCJjRQEmFmB/DfSYk4jpRsuwd/jI4j9jciwOHWt0OT4Gmnv tZ4yPoKlKsIZIzB2kmuQf6F4A1mU1j2cE8Gb0NWTMNQ5fEiVnjzIjJcmNkXG/9IgEMAL yNV4Ol63bOjVHNKC4PUiZys205sywZV1bsOFqTVVOVphCk21OGSNCOa87YA39uYBpVgd Wd9hKf1VL2v2ZvKvk/uLqbNBOEX4pmtLdoJD5EuYlfggGd421kudRQliwgOp186NgPZo XmnH/q+jc5DzBmfh5QyCqqcwYLMqLmd6+Ik8VrfkmXCzB1NMjVkHGmC0H1SDY3Awh79B bJnA== X-Gm-Message-State: AOJu0YykisvVkmBnhgHRJV9/UjKqiMgBmDYJh1gbSNXpOY78iY0rdxpo HiDX2MobnFl3bY6+MDy9z2u9TwzPTR0P7N59ioZ1LAnwu0puBe2yldForjqv1+Q/TBJHwpBzsm5 kTKU= X-Google-Smtp-Source: AGHT+IF5qTNuztLawL22nFdoWM3hBa8g+iEMn3AucUKZX2m0zot7CflQJgWfjjOvLTZBT0mpwh+/bA== X-Received: by 2002:a17:902:cf02:b0:20c:af07:a816 with SMTP id d9443c01a7336-21183d087c7mr129753345ad.31.1731252566678; Sun, 10 Nov 2024 07:29:26 -0800 (PST) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e99a5f935dsm9940973a91.35.2024.11.10.07.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2024 07:29:25 -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, Jens Axboe Subject: [PATCH 09/15] mm/filemap: drop uncached pages when writeback completes Date: Sun, 10 Nov 2024 08:28:01 -0700 Message-ID: <20241110152906.1747545-10-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241110152906.1747545-1-axboe@kernel.dk> References: <20241110152906.1747545-1-axboe@kernel.dk> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 35432C001F X-Rspamd-Server: rspam01 X-Stat-Signature: xkuq3tk53ypne1yy8o34u16a817btgbz X-HE-Tag: 1731252518-812574 X-HE-Meta: U2FsdGVkX18+Ak+3eVaUvFNYkokCdwjiCRZTIhHYww4QxLhwaspUA8LOA4tmZ1NHtlMQQptBlIBOKdT6a+F0RFJFnFEaf4RrFIj8ZV8+reJBLF5V5gp9q4x1skZP+lEH+eRGu1f/87Gn67GNxjRa3h4UI2pyARRKsX0qIj6qDTLzyoKC4WPxDrvT/G9oRUSrugUeHSmc5Rk3YKkaPro7VW2s6xEfYigF73sJgEHIOKuaPgDJuTTkFDsy8R2paWl8u7bh0/sQkmy39pHP1uMZdfNKBhH8fnqO/YYjtVwd5Ez/e/gMzqgeHBePE+L3yRG4qjmm/wttIJjnFa5Z2hbkoBkLQKqiOMv3Aj0TSxxDRQQR3acEFo+Uc1B5knmJRoejEF7syuybjTEysMYJcqHv0mf17V+fhDKNSsQ9ES1OZgXDb3oR03R9gs9dCKYddS+bv1pQhAu2ZbpWC4k07MZKEyl7EMvyiu9X6izzSJb66osOi+4tqOEMBCXr3zOaDX92tKZMXlKwW3UZvqje03iPDgq/6MQt5I6eQbtb+m0dDSO6yoem+XUycpBDfMXPJrH8YBMzjnRXBcujzXbtKapKH+VpFM8CYtG3XcZHIadGrAYpWlCXaIghDHklsdJyWWhczC4KbsvGEUPb447/3VhYVr77zZM8jaNruicFUXJj9Ry2/xxJbzpbN+gdiADX1Wy2RSyMjID6VGJOAjgd6kxwFmiMtflKkatyCLrc841fbK0DofzXNWNiYD/sW8rDZUOklZscyklx4dlmygdwsjTp8s/HtZWi3XC7jnMGhZJLYrXen+ZEYNPAXWyuQJjE1ycclpD2S5kN4OufdQX44WnQQQY2QPePrxVc6d1lU9UzFo7kDDkSZ/V0OkpboVh3QMe9M4BixLZcJy7A6jIJsJOblozcTKtrpE1MFU2Ha0op8oryRvOTqSbAruhMxPsYfJW81DjWv5kW29UeIf02AW4 iLBbPUEO zbWIZNbXkk6DmH9oSRDuehrM0zW/2RZHeHHsn9Mu+bKuMhlsbopUn3yaX8ZgON1GUvYQBQ6SFXflTHc9U8GPVi27JddxWh4OsaUUCg/An/hdtFWr/+r2RXo4DYxNsySnwBFg+bmLyAwKDhDBITIjGCzmBaI4xa8UB802j5xUr1EtL6R3/jeD6ccfyEmttCY/IeZxbe51foYzUiHyw+PiSTK+1erR+Bw3sez+1/4NPFpX0/laK16MchUp6Cb0Kg5WzAytobhSD6Z6UcRQYhy+POCn0FYnqLdAjCCTirHpOplzcIHyTzJ8pURn39Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000334, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: If the folio is marked as uncached, drop pages when writeback completes. Intended to be used with RWF_UNCACHED, to avoid needing sync writes for uncached IO. Signed-off-by: Jens Axboe --- mm/filemap.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mm/filemap.c b/mm/filemap.c index bd698340ef24..efd02b047541 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1600,6 +1600,23 @@ int folio_wait_private_2_killable(struct folio *folio) } EXPORT_SYMBOL(folio_wait_private_2_killable); +/* + * If folio was marked as uncached, then pages should be dropped when writeback + * completes. Do that now. If we fail, it's likely because of a big folio - + * just reset uncached for that case and latter completions should invalidate. + */ +static void folio_end_uncached(struct folio *folio) +{ + bool reset = true; + + if (folio_trylock(folio)) { + reset = !invalidate_complete_folio2(folio->mapping, folio, 0); + folio_unlock(folio); + } + if (reset) + folio_set_uncached(folio); +} + /** * folio_end_writeback - End writeback against a folio. * @folio: The folio. @@ -1610,6 +1627,8 @@ EXPORT_SYMBOL(folio_wait_private_2_killable); */ void folio_end_writeback(struct folio *folio) { + bool folio_uncached; + VM_BUG_ON_FOLIO(!folio_test_writeback(folio), folio); /* @@ -1631,9 +1650,13 @@ void folio_end_writeback(struct folio *folio) * reused before the folio_wake_bit(). */ folio_get(folio); + folio_uncached = folio_test_clear_uncached(folio); if (__folio_end_writeback(folio)) folio_wake_bit(folio, PG_writeback); acct_reclaim_writeback(folio); + + if (folio_uncached) + folio_end_uncached(folio); folio_put(folio); } EXPORT_SYMBOL(folio_end_writeback);