From patchwork Thu Nov 14 15:25:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13875218 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 73CD5D68B32 for ; Thu, 14 Nov 2024 15:28:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C4316B009C; Thu, 14 Nov 2024 10:28:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FE3C6B009D; Thu, 14 Nov 2024 10:28:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E43B56B00A0; Thu, 14 Nov 2024 10:28:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C13D66B009C for ; Thu, 14 Nov 2024 10:28:17 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7CF16C11C4 for ; Thu, 14 Nov 2024 15:28:17 +0000 (UTC) X-FDA: 82785080448.10.1706255 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) by imf14.hostedemail.com (Postfix) with ESMTP id 6E800100006 for ; Thu, 14 Nov 2024 15:27:26 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=S0lOFfBB; spf=pass (imf14.hostedemail.com: domain of axboe@kernel.dk designates 209.85.161.51 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=1731597859; 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=vSo08QFzm+JiqHz4hWmAqopvA0C/7UNivlhAphA9PAA=; b=qLs1atll3n4vZhJkHCWTz6BqUUPMbw+ZHxkxNagxDpKbG06hQMB81tp0sw/mP6meTWImoP xmOw4vQfuiBQo/SmjugSGGuj09fhypxl9UnXKpWkWcs7N32uM2NkR6szEANMUGUGdxY0jq tLYx4OMhoMEFBYfrh4yrQKz+Ix0/8MI= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=S0lOFfBB; spf=pass (imf14.hostedemail.com: domain of axboe@kernel.dk designates 209.85.161.51 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731597859; a=rsa-sha256; cv=none; b=DhGrku9jCBWZVZPkkOzXpJldGcAyZNI1Pqyk5fDqYP5PYOPzJWQH/tShRsNxEnxucsY3tJ 4laLUF5bsw3zfWa2ObK4l2MWnCv6BVOV5d+ZGiEfBsSgvaavyv8LBQXUI43G40luY8zcSV NVa4SdfDmUlQgkh4RBolWTrBZLRLfE4= Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-5ebc0dbc566so315420eaf.3 for ; Thu, 14 Nov 2024 07:28:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731598094; x=1732202894; 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=vSo08QFzm+JiqHz4hWmAqopvA0C/7UNivlhAphA9PAA=; b=S0lOFfBBxzXoXUSkYRVHISzZ5gptp5mcdbE1/h8nF17l12STP4fRmdLbXSaMs45BWl RemkpndS3k2NdI0WsETqsGE6Ix7yqnViwGbe8Lj2WMnM/u9spZ5trRkPkddxY7mNzxpO WuvEU8HIGn10R5/XTaeEJzgYxBFAzdPVdlIhvORGhngP87J8VwPNq6EVC+/qU0hFx51p ViLfYJwVO43mdzlDL+Xa055qwPmpOWwbmwcm8ZZyK+3tmSCcpCeunOdUPtHnu936fVjn ejvt9ODFbdtiEkg1kQLmnDvTy3HMIBPvTu1qxonF+2n+j5Sc8FmDBpqv9uyQZtUCGX6f xcbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731598094; x=1732202894; 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=vSo08QFzm+JiqHz4hWmAqopvA0C/7UNivlhAphA9PAA=; b=rGVNLwZVHvPKON6rNzFkw2xDo92i6ePcT2OhC7SEMY3flpgnzDba+QeMJq2XDXIgp3 vhRRPUE3wSejbyR45yZqFFEOhFRAdoeJSuL4ukfZtbeTz1WVS291WjZOOsyElfccQmum +V4d9jHrfAxVkP/NyhYr26Kg5A0YLmAJkRkSJev4TDKfKz2xWA5nLXKOcOqVDb7++Ls2 xuizfIF0pkgKMTBydekjflrzDwIhjjVRfi2PLY5fSxXGMZWYH+ghWlZLJlfyKus0qfVP W4K5JGtcSlO2bK/fuHM9AZKepa6pzdPE6ZDTSaqI9CO0Qc1BnJ0BcAhSEmESDONLnOKf byWw== X-Gm-Message-State: AOJu0YyHJ9gYrWxz/tA6fnG5XSPa/K5N0E7Eeh/5PeiJHPdNkXSrXE4p 3Zv6wRnwTSzIOWyUyfBqCdbCpINFZxLUBkB/g3q8khW241GhkbEInrSdVtQFrtJC8hBnF6dboQO yuec= X-Google-Smtp-Source: AGHT+IF/wU8hdLitBYUw1Xm5/VEAvnGHF/Lmj1TdlA4Dk/xHse2V/nkks/Gl33gMzxUMuX6RfmQ7hg== X-Received: by 2002:a05:6820:983:b0:5ee:bb2:bdd4 with SMTP id 006d021491bc7-5ee57b96aadmr18195949eaf.1.1731598094397; Thu, 14 Nov 2024 07:28:14 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 07:28:13 -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 09/17] mm/filemap: drop uncached pages when writeback completes Date: Thu, 14 Nov 2024 08:25:13 -0700 Message-ID: <20241114152743.2381672-11-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-Server: rspam06 X-Rspamd-Queue-Id: 6E800100006 X-Stat-Signature: a487xsezazcxrbfa9mdts8ntxr9xocx5 X-Rspam-User: X-HE-Tag: 1731598046-891501 X-HE-Meta: U2FsdGVkX19XXtggrG+qK5X6ZIGYAxYB9iNoSuEHX02EExh4aTj6/tkxWKMF1Bi9sN3mD5PFo6QUIRmbARwYm+r6gMhziSEq75x522P9HUac9Tl9qFKeOYofYlJRw7j/yzCXQiP47CH7yD850FnE6FTAni/kQaC69RqtydS1gb/1TCiTHlAdvkjA6ucmttVuPn5eWp2Rxhzx8GMxO2I9py+Ad4lwriCKr3ePq25OflZcR/m5/IcoMzWb+l54OAJMFXARdkMNZq41GPzSOcpHEL5hGLFYrPCHXmSWVWB4FED7YuL5aZOgITLC99ehbPinPtXRPvvIpAF63cV4/MIelzkY/6sGKgUS3UR1AwdezQ+TKit88TPgMFJu/oGeXOJx1GaMTQM2m1pArpHRzhzV7igWMMngY23PtXHInEe6n/TRzmscvwvdIjCxCkXdNa/SWkc3d4hafsfBxmUjb2f2Lxovktvn0fcSeegfJMDzYGMHT9All/CP2UqHt8q3v9oUksAEk7vGOIslXCiyp1Al51bX6qQzgULPqqIJ2wjSMKLo9idEFfdD5RrvZTIVWmudFBv+ga8yuH3DgT0z1eLW0JPv5JRVwd1F1m2uvq6/V4xXvQq9GqwvWOUgjO3bq4NwMbJOclr3GNxhE/oICM4HX9m/6FbkGcwmJNNeCqtI0LC+AlBEHrK5giszQdrVAY1rZhVFDMPqM/TTHdiSzaUjgaM11qmHvM/eJ9qNDfaS6PPqvIc7q29SFb4CR8ucWrM+vgM81exZPEt4etdHyxOVpxaOoyiQf2nTkiYoVVBRJRpGSXhC+8tbOqXDRtVmvCJnx7gsfEiy+6FfVe0RM67LZtqee0EPqhEarazD4+PaitNiq0l7IBIpOJtzEUc1H55nFwIA9ftO6dysBNP1ifjufX9mwn+TD2YMhXNX+i+O4d/UknYzG6GhLJpQq39hivQ9L8JEM6HO9/6BOdVY70B Hg3EeKVS MZjzlxwQemB4ZW68tT8Gz4kuo7Um/ZxJdkdwsCvXF4gFcIcJtj0yg9twdkUqDleMzEieGq1BEwyfI2/tasJcRVB4qJA4GATQbxkVqtUeCc654CmU/PgM4RONpEs+ud+LmdIY74ATpmKPDB4ks1F5g8qS98ZEGHIGj8YP7UtIY+EtsNuf4SmisdIaC7EG9rZbmyhecVvvfS+sCoZM4wKIMr7JUPibl6B91xkUi8i72ntMgiY+656ANwqRHzsDxECyLdw0jFWVcXaPEfEgru9mW3ddGkmdPQKRyCQv3L7SwNdq/Rzgip9YSyB1z0g== 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: 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 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mm/filemap.c b/mm/filemap.c index 3d0614ea5f59..13815194ed8a 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1600,6 +1600,27 @@ 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) +{ + /* + * Hitting !in_task() should not happen off RWF_UNCACHED writeback, but + * can happen if normal writeback just happens to find dirty folios + * that were created as part of uncached writeback, and that writeback + * would otherwise not need non-IRQ handling. Just skip the + * invalidation in that case. + */ + if (in_task() && folio_trylock(folio)) { + if (folio->mapping) + folio_unmap_invalidate(folio->mapping, folio, 0); + folio_unlock(folio); + } +} + /** * folio_end_writeback - End writeback against a folio. * @folio: The folio. @@ -1610,6 +1631,8 @@ EXPORT_SYMBOL(folio_wait_private_2_killable); */ void folio_end_writeback(struct folio *folio) { + bool folio_uncached = false; + VM_BUG_ON_FOLIO(!folio_test_writeback(folio), folio); /* @@ -1631,9 +1654,14 @@ void folio_end_writeback(struct folio *folio) * reused before the folio_wake_bit(). */ folio_get(folio); + if (!folio_test_dirty(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);