From nobody Sat Apr 11 08:26:22 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19E2FC678D4 for ; Thu, 2 Mar 2023 23:28:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230053AbjCBX21 (ORCPT ); Thu, 2 Mar 2023 18:28:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229936AbjCBX2L (ORCPT ); Thu, 2 Mar 2023 18:28:11 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A55C125BF for ; Thu, 2 Mar 2023 15:28:09 -0800 (PST) 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=Hpr/mKVZzGGQqVrubmxhAsrFv4PlfL2VXUxF3A6d69A=; b=hKi5B7rksyIKLYpIpojH3COwse 6yVboytacnRm0DNMUh5BKMfZwbdWYuNUklJLKFbD4wjEle33GCTpvZJdXbQPCk3hIf0DFStd9tL+t jq4IAgiksjYqh8v8mIireTRU6LNVj2zfYQ9mtUda+GZCTq6XHxJgjkKPxVVTVA6t/x9znl5F31erd JzgAsoy7GHNSk6QSSzDOJz7LMMAQ1DbbEpT234nu/jFOtmuCwstY5Gm50cCZVHGdz0FpM/qmB87KL Z3RJNpaMrZyQyQJFwvIzGInyQpaIjBIYAAKuhUc2yvfiaKNxUBSuS7LOizfLNgOD6cguhCKiDt7p1 C3zX/D7w==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXsL9-003j3M-8Z; Thu, 02 Mar 2023 23:27:59 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org Cc: linux-mm@kvack.org, p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 3/6] shmem: move reclaim check early on writepages() Date: Thu, 2 Mar 2023 15:27:55 -0800 Message-Id: <20230302232758.888157-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302232758.888157-1-mcgrof@kernel.org> References: <20230302232758.888157-1-mcgrof@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Acked-by: David Hildenbrand Reviewed-by: Yosry Ahmed --- mm/shmem.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 2b9ff585a553..a5a6da51087e 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1340,6 +1340,18 @@ static int shmem_writepage(struct page *page, struct= writeback_control *wbc) swp_entry_t swap; pgoff_t index; =20 + /* + * 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, @@ -1360,18 +1372,6 @@ static int shmem_writepage(struct page *page, struct= writeback_control *wbc) if (!total_swap_pages) goto redirty; =20 - /* - * 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 --=20 2.39.1