From patchwork Fri Dec 13 15:55:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13907406 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 92EF2E7717D for ; Fri, 13 Dec 2024 15:56:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A82CA6B009A; Fri, 13 Dec 2024 10:56:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0A126B009B; Fri, 13 Dec 2024 10:56:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85DE06B009C; Fri, 13 Dec 2024 10:56:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 66BA86B009A for ; Fri, 13 Dec 2024 10:56:19 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 19C36160F02 for ; Fri, 13 Dec 2024 15:56:19 +0000 (UTC) X-FDA: 82890386670.07.34E2DAD Received: from mail-il1-f180.google.com (mail-il1-f180.google.com [209.85.166.180]) by imf07.hostedemail.com (Postfix) with ESMTP id 58D6E40003 for ; Fri, 13 Dec 2024 15:55:45 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=wxgu2dzw; spf=pass (imf07.hostedemail.com: domain of axboe@kernel.dk designates 209.85.166.180 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734105353; a=rsa-sha256; cv=none; b=N8FtteKpwt6tHZFy32sj9dh+cTfF7crb02/rJpb1Ma6KIbVoidswf4ejHsoB/wiAiIW00u Slz2ObLG3eSH6F1oxw6iKszoidv+VLU8j+SClddRhihNl74muixHqQzOhtCkyW+rPMgSKo XQLaWsLS+YAMUlr8a3ncsfucwdIPr9E= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=wxgu2dzw; spf=pass (imf07.hostedemail.com: domain of axboe@kernel.dk designates 209.85.166.180 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=1734105353; 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=eL7TH1+psm5CeVquxo+D9Ecvv3+RlpadAVoxegN1mFk=; b=Iq1NaGu8xFCfSKtv6WX1VtiQDGAf5N3QPZDS+6KUFASQWr+Bkn8l0Y1Ta8xpj2rc4iGj84 MG7XnNwhRzl16ICaQ+wnDtrb51D81cqbpwaEyFAW3o5vH6lB8fK+jYrIWfnmqDjDnIlxLW GplDdZkmNBc3WVj/aY9guYTKXqBrVog= Received: by mail-il1-f180.google.com with SMTP id e9e14a558f8ab-3a9cdcec53fso15577085ab.1 for ; Fri, 13 Dec 2024 07:56:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1734105376; x=1734710176; 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=eL7TH1+psm5CeVquxo+D9Ecvv3+RlpadAVoxegN1mFk=; b=wxgu2dzw/AUR37WEvWNTqHjbJhSUH5fL6qZ8DwhjO9A+9yaRV8lRP6Q/4EqJAXP049 Fvyq5T/bk18QnYeTQoGlxlHfkCHXySnlfhHlGb8Id/446O57Y9nRi01F+gvqfGtj+FKv R8AqovYlZ6hLv5Ihu8zG5mqkdNiJUcLX3ur6lSKhhTxh/UzrpwTKVLDFn2PY5x8SbhJI M+H06SJJJMqjCq/bulBk2WNiF2uiN3e470dI7AwcZzdYsWLRZkfClfwOXZjQPrBDGM2A upbStvE1xy4zaZI3umPO8w9IzpgyBkQPTRuuvUxF/8hoE1gr6N9UTJF/CzH/DDbeITgq aWsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734105376; x=1734710176; 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=eL7TH1+psm5CeVquxo+D9Ecvv3+RlpadAVoxegN1mFk=; b=CvjgDJsilYims/jofeK27VROtf7Tj7NQREsnnPXXt4qorAl75G18lkOo3oIacQf/2v xq/gAb57iOk9qPOIKXpnN5PlzxZ5L7n59KMPfplBP9KoTZh4RqffM+Im9qOI/usw9Xip y5ckgXgh3qvA7yfaSWp3HduQTP5r7c4Yfl7fAENlMJPiBy6KnnmLyK83oH5vBaiOo8OL ur/CSxASXyvRXNLsl1WuFbFzb8sDIUAOD02c1oNxTO/gaXeWt2qFJQtR2B/TZKRsLO1V a0kLJA0uJHNSXrRwSDnF72IzrAZouIHvc0eCfCUYa1D+aqXFXf9auScmF0+3QGpAOued C7ww== X-Gm-Message-State: AOJu0Yxa3TGPbst2yRUcUXRB4WR8CETJZIu0uGE7qsQLvsbqJb5KnFez sg4KT2kHQ9qOxPqf01qcZG5cbMJSSjFtbRoJbCROxSKOSS9tUmXWDxjTQI45iaJQu08f7cLbWbz X X-Gm-Gg: ASbGnctd0afF9fJnnEE7yYNlsl1S2r2idnIbkg9Z81zKo1fAKF2SOszOtYa0H1LKw5f VdY/A1WFSeeev+nlg7GWwuPWPYPkZvqnFmMaKObc/JoMdQM6T4NRRpS6d+KS9J+j+BuvyfC8OMu hWS01bgJYB4G8ybXcnTbLn1aMQGwIWe4QY/JlsW6kIugexV+RujQxPYzQ16By8JIeA2nLKZMZSD 3M8zH2i66M+VTsC+p8wE9aDlOPCK0CU1xYJRwfqb/oXnHuOaqKw3cVlPlTT X-Google-Smtp-Source: AGHT+IG5PcGGwL+OAF8BWXN0MfzrquLg0U95m3qvCvU2aqYiecyxUUHKeEBe+q/HNr+0PzMX/oeVbw== X-Received: by 2002:a05:6e02:12e2:b0:3a6:c98d:86bc with SMTP id e9e14a558f8ab-3aff4619e11mr40735545ab.1.1734105375832; Fri, 13 Dec 2024 07:56:15 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3a9ca03ae11sm35258405ab.41.2024.12.13.07.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 07:56:15 -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 09/11] mm/filemap: drop streaming/uncached pages when writeback completes Date: Fri, 13 Dec 2024 08:55:23 -0700 Message-ID: <20241213155557.105419-10-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241213155557.105419-1-axboe@kernel.dk> References: <20241213155557.105419-1-axboe@kernel.dk> MIME-Version: 1.0 X-Rspamd-Queue-Id: 58D6E40003 X-Stat-Signature: po49s615g4ct597cjwwodooanpyqabbx X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1734105345-435510 X-HE-Meta: U2FsdGVkX19rPxM39uHJBzznSP1ASVA/kz9Ye2zv2wmGf8gJ6UrBKuQML4Ksc9ZbF8cKnBxvEUE4vE6xZ/u+Bp+d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mYe1amRRYJsaZ5B+8mygqUMz9BpqZ3l0hvtSmbvOqegmaQ/29oHdR9cPy/PH8cL/a6gveofac5cjCMXR8Ew3muAzduBEcPteIcVPemcAEl+QtNtw6hEZvceRp+zHSdd9pM6I/uQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.019161, 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 streaming, drop pages when writeback completes. Intended to be used with RWF_DONTCACHE, 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 77290ac205dc..ec087bab1c97 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1599,6 +1599,27 @@ int folio_wait_private_2_killable(struct folio *folio) } EXPORT_SYMBOL(folio_wait_private_2_killable); +/* + * If folio was marked as dropbehind, then pages should be dropped when writeback + * completes. Do that now. If we fail, it's likely because of a big folio - + * just reset dropbehind for that case and latter completions should invalidate. + */ +static void folio_end_dropbehind(struct folio *folio) +{ + /* + * Hitting !in_task() should not happen off RWF_DONTCACHE 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. @@ -1609,6 +1630,8 @@ EXPORT_SYMBOL(folio_wait_private_2_killable); */ void folio_end_writeback(struct folio *folio) { + bool folio_dropbehind = false; + VM_BUG_ON_FOLIO(!folio_test_writeback(folio), folio); /* @@ -1630,9 +1653,14 @@ void folio_end_writeback(struct folio *folio) * reused before the folio_wake_bit(). */ folio_get(folio); + if (!folio_test_dirty(folio)) + folio_dropbehind = folio_test_clear_dropbehind(folio); if (__folio_end_writeback(folio)) folio_wake_bit(folio, PG_writeback); acct_reclaim_writeback(folio); + + if (folio_dropbehind) + folio_end_dropbehind(folio); folio_put(folio); } EXPORT_SYMBOL(folio_end_writeback);