From patchwork Thu Mar 9 23:05:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13168525 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 E3953C64EC4 for ; Thu, 9 Mar 2023 23:05:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB380280003; Thu, 9 Mar 2023 18:05:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C6443280002; Thu, 9 Mar 2023 18:05:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B2A5A280003; Thu, 9 Mar 2023 18:05:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A4A0A280002 for ; Thu, 9 Mar 2023 18:05:56 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6EE4CA118C for ; Thu, 9 Mar 2023 23:05:56 +0000 (UTC) X-FDA: 80550894312.28.17F0D7B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf21.hostedemail.com (Postfix) with ESMTP id C5DFB1C001B for ; Thu, 9 Mar 2023 23:05:53 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=3HA+jE0d; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf21.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678403153; 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=nd2m/LNu9NMKcIyRptke6PFaE+tBCNb9V+MN5pDSpQU=; b=8KwLI9/SvlnpUyhXEHG993PJdsBvdqwC5i5zYHXtBQkyC/uEa8cpJVAZ1h6lLLsYeYi6Uj xJnLjgv5hTucakTiv0l/UO+Au7zeS38osr4Uqew2vAwgRjs1GoIXKPWNY0zcLptzYDPKxT UyVDzQG2HyQ19IiXdYRRuXidVOSnIW4= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=3HA+jE0d; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf21.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678403153; a=rsa-sha256; cv=none; b=5WIzs3e4tX0RtpgQMLQ+FVlf1x/4xiFe9euRA/MJG2BO6jHMCwmtHgfsTVFGn+JrDt7En/ /ysj1pAtU8CpdNeijLHLlzU2iJLwbrRoOW2KF28r70X8STftoRzZcFu7czJjgdGHJDVo/3 4pSDiPCJE3+nSKE73o8EVSj7m/h/sE4= 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=nd2m/LNu9NMKcIyRptke6PFaE+tBCNb9V+MN5pDSpQU=; b=3HA+jE0dyswGu9J5ZVVPfPe329 BO74aE5mhVip8O7KCZwd+SF7eFwb27HJyop6K4tGVHCtQXPIHeTkMP2VAkR0T3MojwU8x6u+tf0Dv nBlE2vsMycFdc8mJdNhg9Wjv8EuDGp2Liutocgdvmqk3KDlQD+PgebAyTzprcitwS5UM8JZ4yfkgZ UNrRRD4Z1LIzm7QVLI/cT8FeeIAguMrwrgUAi/3NZY3KeND9TvJ0wUDcAtY9ObElBVCcs+W7kwkZ9 7EyooKOu7ISN/RzkBo8MmRK2IeqGOi5Rh2g77AKzK4W7UpYmr2grBlhpxHPHisC4onhlVIrgPbgEq 5dxQmXXA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1paPKW-00CIRY-8d; Thu, 09 Mar 2023 23:05:48 +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, David Hildenbrand Subject: [PATCH v2 4/6] shmem: skip page split if we're not reclaiming Date: Thu, 9 Mar 2023 15:05:43 -0800 Message-Id: <20230309230545.2930737-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230309230545.2930737-1-mcgrof@kernel.org> References: <20230309230545.2930737-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: C5DFB1C001B X-Stat-Signature: j8fi5dafd3g9gmxqacwerr1ua71be57z X-HE-Tag: 1678403153-950591 X-HE-Meta: U2FsdGVkX18P4jpXGTgsrcUyx0XIUdRbJy3oioH+hnIFI5/IOvfkWoosFHmwheOsVJwhRkCNLyXb102VT5wWLkAOtTdb29xrh4yLaMY788eQZElMykgtljpMQU7GRkUSYOvPdf0UkwpJwXwsCgapj9gV2sGIUgbFDMtxUoQDKuU8tVGSZQu1qQvAgaWmLzFkCKhL5R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nTmKHzQBxNTQRaksljyOlenxkRe2xUrnxEeJRpSYDyNGjb1Bcvc5HaEY5sPoch5pTM6Dt8etljTwDNpySi1KflbAS5u/KOoWM6BvivkJPaZ4h3rh4/7ofOzH5LNojKd1QKE0Y/d8+fWPkDq/FP4uD3bA== 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. Acked-by: David Hildenbrand Reviewed-by: Christian Brauner Signed-off-by: Luis Chamberlain 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 68e9970baf1e..dfd995da77b4 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1350,6 +1350,12 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) if (WARN_ON_ONCE(!wbc->for_reclaim)) 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, @@ -1365,10 +1371,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