From patchwork Thu Feb 23 02:44:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13149791 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 AFD74C64ED6 for ; Thu, 23 Feb 2023 02:44:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 503486B0074; Wed, 22 Feb 2023 21:44:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4428A6B007E; Wed, 22 Feb 2023 21:44:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E74366B0074; Wed, 22 Feb 2023 21:44:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C72376B0074 for ; Wed, 22 Feb 2023 21:44:21 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9316DA0950 for ; Thu, 23 Feb 2023 02:44:21 +0000 (UTC) X-FDA: 80497012722.02.E0F6423 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf13.hostedemail.com (Postfix) with ESMTP id ADB8A20009 for ; Thu, 23 Feb 2023 02:44:19 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=nobDFyPW; spf=none (imf13.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677120260; a=rsa-sha256; cv=none; b=u49OskFTIfJsKM6xGB9QgPU6r3m8xg6yH0BcPnye/Iu00MMA7XapCMe+TGmPHIaEyCtHe3 96SLETFzwtOciBLaxYxYog3hNjELk8sdU9FMR5jkUmLquez1uYXYLCqHJdzroKD/SAhacg 2ZtmXuOLKrjzs1B8wSnckWTVEjZoGEQ= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=nobDFyPW; spf=none (imf13.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677120260; h=from:from:sender: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=vQjHgoe5Jm+n0b1ADMVciA5nvYNCQKcIEIUc76XY5yA=; b=dWyL2k16i0VN5ObJytCyBhaLTpdCHpEUV8JAoCsASBz8Xzd7Amz69SLy8CkQ0w2u90KsF/ l/Mcq+zd9Irz5DXFGXvDMdX99CiuJo57oo/YQqpc1F/I/s1FMbPRdQIvGS+naYowTHV5Q/ nHj7E0E8+kb7KU+1F7BB1UT4KsFQc34= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=vQjHgoe5Jm+n0b1ADMVciA5nvYNCQKcIEIUc76XY5yA=; b=nobDFyPW1FDWru83lnPC9EwGl6 R/FHdKwibKNjX3q9wvjpliuLql+NoQ9c0rhOKA0yrjL0c2fVAZ8p5RDkCW6T/uLryGWU6LLvIkYK3 H8ZiDSzxHfM1HiVyVJJIIX+A6Fs2dWqSFF4Mm8kGPxhMBXeV+81ZHgNBeGyY6UUKuDDPhMnjqGLO5 TABWOhP+CZw4oNP8VfJdPVbrNk70Mb5neyvgQ6W/IecffA3e/SrfwO1okz2f1jrhReSmm+2oITWqW LBsLcoG8bQlb1BH852kJkU4dTTBSJiFZIiW9Bx4gy3pLT+qeSzmlOw0EHq2ID8LlnX29yOscwqVJd SxirXIAw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pV1ah-00EmNC-8r; Thu, 23 Feb 2023 02:44:15 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org Cc: linux-mm@kvack.org, p.raghav@samsung.com, dave@stgolabs.net, a.manzanares@samsung.com, yosryahmed@google.com, mcgrof@kernel.org, linux-kernel@vger.kernel.org Subject: [RFC v2 3/5] shmem: move reclaim check early on writepages() Date: Wed, 22 Feb 2023 18:44:10 -0800 Message-Id: <20230223024412.3522465-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230223024412.3522465-1-mcgrof@kernel.org> References: <20230223024412.3522465-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: ADB8A20009 X-Rspamd-Server: rspam01 X-Stat-Signature: euz3sa4yx7ynr3hjp5taab37xkqjhxzp X-HE-Tag: 1677120259-944375 X-HE-Meta: U2FsdGVkX1/f6YaJmfq8+XUYwKqocJkkd73fGERz5QD+Dt9hn92KV/Gn9Fpr/0KJu0GMqc4dfoCkXZ7iR78scUyQMvxfrIA0XnzUsHqtrfAOKvJ9WXme0ge9x2MFQECdVj0ncS1RPkv8kZgvqm6n5+EQF+kLzvF/44HzNO6rR4dlKFq8Zl3N4Fb2NuqpjP8TvxexSqfpaW8Vw5cX6PDmHIYWOCsGOIskyXZq8z4OE68Qq3O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c0juV+fBM2+h//2SQ9c6BQYpIn37Ltydhrf/wntdwFZKQ9ALVUqlbU1iBSjFQgGY5RAyyGjJYA4nqDy7d/XUTMK8 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: i915_gem requires huge folios to be split when swapping. However we have check for usage of writepages() to ensure it used only for swap purposes later. Avoid the splits if we're not being called for reclaim, even if they should in theory not happen. This makes the conditions easier to follow on shem_writepage(). Signed-off-by: Luis Chamberlain --- mm/shmem.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 1269482d0a5c..626eb1a0856c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1337,6 +1337,18 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) swp_entry_t swap; pgoff_t index; + /* + * Our capabilities prevent regular writeback or sync from ever calling + * shmem_writepage; but a stacking filesystem might use ->writepage of + * its underlying filesystem, in which case tmpfs should write out to + * swap only in response to memory pressure, and not for the writeback + * threads or sync. + */ + if (!wbc->for_reclaim) { + WARN_ON_ONCE(1); /* Still happens? Tell us about it! */ + goto redirty; + } + /* * If /sys/kernel/mm/transparent_hugepage/shmem_enabled is "always" or * "force", drivers/gpu/drm/i915/gem/i915_gem_shmem.c gets huge pages, @@ -1357,18 +1369,6 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) if (!total_swap_pages) goto redirty; - /* - * Our capabilities prevent regular writeback or sync from ever calling - * shmem_writepage; but a stacking filesystem might use ->writepage of - * its underlying filesystem, in which case tmpfs should write out to - * swap only in response to memory pressure, and not for the writeback - * threads or sync. - */ - if (!wbc->for_reclaim) { - WARN_ON_ONCE(1); /* Still happens? Tell us about it! */ - goto redirty; - } - /* * This is somewhat ridiculous, but without plumbing a SWAP_MAP_FALLOC * value into swapfile.c, the only way we can correctly account for a