From patchwork Thu Mar 2 23:27:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13158047 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 637B8C678D4 for ; Thu, 2 Mar 2023 23:28:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CDEB46B0080; Thu, 2 Mar 2023 18:28:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC17D6B0087; Thu, 2 Mar 2023 18:28:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D1A06B0082; Thu, 2 Mar 2023 18:28:07 -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 7599A6B0080 for ; Thu, 2 Mar 2023 18:28:07 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 46EA58022B for ; Thu, 2 Mar 2023 23:28:07 +0000 (UTC) X-FDA: 80525548614.12.912AEA8 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf02.hostedemail.com (Postfix) with ESMTP id 5C1F18000C for ; Thu, 2 Mar 2023 23:28:05 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=4Mn4cSCA; spf=none (imf02.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=1677799685; a=rsa-sha256; cv=none; b=HHhCAEcAtPnStM+E0BJlUeqkaIXSjXdOdSIUjUIG40LklyvIKynu+50B3ZYprTYof5/EqI LP31hJj/sGvSJsgBchK1lKcZVKf4mTAnE2qwsOjwNG+GRv3HzcNPfSkm7D4gY+3uLETp/Q REv/pNooNXeqi+9ZGgLFWFEae3ecchc= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=4Mn4cSCA; spf=none (imf02.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=1677799685; 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=qG5U0uWPFmEbIzb8qGwDd3VP74J/BRogOkPK92T1eiw=; b=6M0HTFDT3MJXlJg5QESaRd2lqZALP0rCOa0AcNNtAR/BaDaZrq7S+DX5NTIGUiaYnBJ28I 9jGUuNjKPcrpPrf3OPDM+RK3/52/UCm+bKMs8lgMSvX98xI+mTgejQONL87gAsqS2H5gdR UyGce0yWBmUlYrxBfibvSuTT1380jGQ= 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=qG5U0uWPFmEbIzb8qGwDd3VP74J/BRogOkPK92T1eiw=; b=4Mn4cSCAgRAwfc+ofEk7syFvU4 lgI+PixYXC7I6rMVPFt85Y4M8oB/dWwp5q6YY7j/3hgM2uh2P7ZtiZ22ho1zzeWefT3wd+huLJpxd mvGW2hfn1RtW61xAcyyeVfH9HN8JlRi29H3roFcGHcEC+b/G8QXX5LxaV7GoFHadburRxTnA/MMf9 +OPgxbeXJdcEcdQlRLQ0xbxT//SyOp14A7a7SO3dbpZWiKOO2+0j1sd9qtehWMvQZKVPoRxZhSOC9 XOO9h5XjMa5XF91JikH0HlR1tccdHYPW2mUwbxqK+PvPIFK+WTgqQha6vzzE6HKxjq0hmzN8pLejD /ppNx6LQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXsL9-003j3O-BB; 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 4/6] shmem: skip page split if we're not reclaiming Date: Thu, 2 Mar 2023 15:27:56 -0800 Message-Id: <20230302232758.888157-5-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 X-Rspam-User: X-Rspamd-Queue-Id: 5C1F18000C X-Rspamd-Server: rspam01 X-Stat-Signature: 6hnrdh7euibe4gtjfkjede1ib51amgy9 X-HE-Tag: 1677799685-140986 X-HE-Meta: U2FsdGVkX1/GuO+egOPjYPugFsW0pTDCNZo8nN1He0hYui0+a54iN9/u6bdGtb/+6/UMa0yr8Qtr3MU7WseE1AmZq4bBlQUq2mc5RaQWYtONqflWF7dBsH32lmma3DAwOBQXdodV+jrfHb2FjZFnmCW+Ap2OTJczIC3tD/oplcNRY/Uz6m7m182x1B5sB6/uK2V7oVJIEtQ19KpGj3V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azqnXwjSgwlIYXY8fT5zps5qpcpJ+9NJBMuZRy1/nRobVIS475zCwe0w3NjfzYrV65ET2CFdreyoPbjOOp1hbMGDHxZtzLGxn6Xf4mfz/0VWICD7Oy 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: In theory when info->flags & VM_LOCKED we should not be getting shem_writepage() called so we should be verifying this with a WARN_ON_ONCE(). Since we should not be swapping then best to ensure we also don't do the folio split earlier too. So just move the check early to avoid folio splits in case its a dubious call. We also have a similar early bail when !total_swap_pages so just move that earlier to avoid the possible folio split in the same situation. Signed-off-by: Luis Chamberlain Acked-by: David Hildenbrand Reviewed-by: Yosry Ahmed --- mm/shmem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index a5a6da51087e..6006dbb7dbcb 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1352,6 +1352,12 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) goto redirty; } + if (WARN_ON_ONCE(info->flags & VM_LOCKED)) + goto redirty; + + if (!total_swap_pages) + 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, @@ -1367,10 +1373,6 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) } index = folio->index; - if (info->flags & VM_LOCKED) - goto redirty; - if (!total_swap_pages) - goto redirty; /* * This is somewhat ridiculous, but without plumbing a SWAP_MAP_FALLOC