From patchwork Thu Feb 23 02:44:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13149792 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 8ACB6C636D6 for ; Thu, 23 Feb 2023 02:44:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0A396B0078; Wed, 22 Feb 2023 21:44:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 993596B007D; 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 832996B007E; Wed, 22 Feb 2023 21:44:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6104D6B0078 for ; Wed, 22 Feb 2023 21:44:22 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 35C501A0AD6 for ; Thu, 23 Feb 2023 02:44:22 +0000 (UTC) X-FDA: 80497012764.01.18F4001 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf12.hostedemail.com (Postfix) with ESMTP id 53BE340014 for ; Thu, 23 Feb 2023 02:44:19 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=sn2iEaZx; spf=none (imf12.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=1677120259; 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=kiZfMZIUImYTT26kimjDxbkl+uiLHr4foE9jVeUonNw=; b=B4v5Hp2x716iEgGXjVlsIug2EdrcmiqV5uo4F5zL3RijGbnCFMq2Xsbjm2hmokSbe+abQI pCY6RYKm0T8PGqzHo2MC10M5KWDNSbjqtYjQcNp0mAwrA1Udn6+9aIDCRN+d9DICBpOtNs kA7fkL4JlUBSKhOH85Zq5X+PBJhwifs= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=sn2iEaZx; spf=none (imf12.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=1677120259; a=rsa-sha256; cv=none; b=nNAgo6VdxvT/d8E44lgWMajYgP1irsu6kvPeS1b3mdy4jUXSA7OYo2I1Fs4Qfy9N3ShSTr w8Mt+h4dVpMeLOxbMp3px8CYWzjsQ7VxGzBAMAXEk5/bYHI/+4xjYkGtvEDABr9tCpiYk9 SOBhZSbzM4OB4AE/qXVVEiQATBC9tNk= 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=kiZfMZIUImYTT26kimjDxbkl+uiLHr4foE9jVeUonNw=; b=sn2iEaZxSxcZjr+lLEI+B9ZNfD ag2rd1ZA2IdkPMeYOuIbwUEge8ajYxG0X3vo+WuNHeE+62APWJEO/TQ+BEwvXPPTKO08otnIXs5Yn H5l53U6iDGmiMIOfWkieSJ1WN0Q/joKc8yr4grfgcI+SPDH7VlzINQV7egc10DDUTWILqPocCSj1o XDf9ihIRyG8DyPLMC9rit2JBlfpauaPYiOzpZfEAHTt+yslONZY1xDy5BC4wiV6lsokBvqZVjPYU9 M/s2WFxV74jDhTSMO3eHfu513os/QCbn/WTrt9tXhV/ao06RvY6cmntgbABP0/E6sLUKQ8wKo25Fz rCFNadYA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pV1ah-00EmNE-A6; 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 4/5] shmem: skip page split if we're not reclaiming Date: Wed, 22 Feb 2023 18:44:11 -0800 Message-Id: <20230223024412.3522465-5-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-Server: rspam03 X-Stat-Signature: puc636ju4t9ygncz5m1utt3yyjdajq99 X-Rspamd-Queue-Id: 53BE340014 X-HE-Tag: 1677120259-288124 X-HE-Meta: U2FsdGVkX19qHt+cGGhGPlrnVYmqNBS62EFA+1O+wui6p6f6KNz2OJNUhm1h+hP42uHFoU46e25HV9BsTRLhBQOFzOaxwBYRpyWX64OHmQ09rmLFuUj0dJgXcTdPb1V1+rtpKfecxHSl1VGGEhtnvfapzSYwcpRqBzUZwrxx2Xc+iSvA5JrIjVgm2JWYvHGUfYagXhXGpXWqhd40tUjGnUqwnpMK3chWqh9Q6PCgCU2ImJPnuQKxea00azWyQkoQ/1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9elJSjGoE45a3eqbu+/72lsQCMUgLbEQvMLuC0XiFrsfeXYQURtMchMp0+beIM0m8IDbILHfGQ8cUt92RfN08 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 --- mm/shmem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 626eb1a0856c..a49b31d38627 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1349,6 +1349,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, @@ -1364,10 +1370,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