From patchwork Mon Feb 14 21:49:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 12746182 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 D9C8DC433EF for ; Mon, 14 Feb 2022 21:49:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15DD36B0075; Mon, 14 Feb 2022 16:49:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 10E1F6B007B; Mon, 14 Feb 2022 16:49:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F168E6B007D; Mon, 14 Feb 2022 16:49:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0132.hostedemail.com [216.40.44.132]) by kanga.kvack.org (Postfix) with ESMTP id E011B6B0075 for ; Mon, 14 Feb 2022 16:49:23 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 984EB8248D52 for ; Mon, 14 Feb 2022 21:49:23 +0000 (UTC) X-FDA: 79142727006.29.A93FB4F Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf19.hostedemail.com (Postfix) with ESMTP id 15CD41A0002 for ; Mon, 14 Feb 2022 21:49:22 +0000 (UTC) Received: by mail-qk1-f170.google.com with SMTP id d5so403955qkc.8 for ; Mon, 14 Feb 2022 13:49:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HduNWSXwHF2qMp2tKTU9szIHjs3c1KQrYw+jf8BZZPM=; b=215dMlHoklWFE+75szJr/Y820Jgsu6uYnJPnIt2MoQCGOJqW3qsQAALF4vXlV9bVTf oaY8xA66Iez3WRkyPgpYJ3sJx9jd6pDLsWo5K6Iofc1NmBq5OSY4k07jmhOfFpT9SM6p /9JaJyDct5CGz4+UyIutmyUdQFUDTMH4jFG/WLfxmBUQRnsdSk8hw5YKSyeGHnHIkEUH 3Rzw8AHUCnbs7Wi+ORDMhd1492oL8mFwaYTPkjLGBF1qRd+vM4lIINt6AGmoCT8JQVxw MR3RWrJXhYYwa/QgmZ2012SBgF6iPaTdSiOwNh5JC9a+J4bDdec2LxCpQ7Pitsj9HTYN qvqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HduNWSXwHF2qMp2tKTU9szIHjs3c1KQrYw+jf8BZZPM=; b=kKpBdHIwAgmUpSfo8KgGC5b6XACRIHs6ANLkHZsXMmgYW/sFu5O2X03J4y/pmmUAsJ vXljU3/rOMyZHpBKIz8xQGDY96ACNtYXhzXgbOrpVrhHM0uhqj2kBOOqog8DCyLz8rkI Ob5JyAzVcFIpPZcIBcXxFeEc5DJI4LqiUeLJ3urdV1bSNTIE306oWR5hk5SOIwnXX1Gj W4fEWxZQAItrDj4jRZwzgCqrrMA0hSx98Dx+BpQ+SByOLUTCCWubXVINGFYVRYO6JrBL 7qvPkqpN+HjbyIRygnEPrvnIJQ0BGgtQiVIlLut4BzIsmFCryG5N5/5K44n1rtBcsC/6 4IZA== X-Gm-Message-State: AOAM530Mluff85B2913bNVLraVWG6BCvYLhZHa3ivo1ggXoorSv5hzHf QlM3HO7T6Wvqmg2mkcqpgElRzA== X-Google-Smtp-Source: ABdhPJyiRZjNZ7NyCD66Td1gEAAhNJr5fwSQTasB43SkAUHLAcSMqVyxeErZVQxtBTjDHLDXHSpppw== X-Received: by 2002:a05:620a:128c:: with SMTP id w12mr560649qki.464.1644875362346; Mon, 14 Feb 2022 13:49:22 -0800 (PST) Received: from localhost (cpe-98-15-154-102.hvc.res.rr.com. [98.15.154.102]) by smtp.gmail.com with ESMTPSA id 5sm18474167qtp.81.2022.02.14.13.49.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 13:49:22 -0800 (PST) From: Johannes Weiner To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, CGEL , Minchan Kim , Joonsoo Kim , Yu Zhao Subject: [PATCH] mm: page_io: fix psi memory pressure error on cold swapins Date: Mon, 14 Feb 2022 16:49:21 -0500 Message-Id: <20220214214921.419687-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 15CD41A0002 X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=215dMlHo; spf=pass (imf19.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.170 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org X-Stat-Signature: ftnaj3x34fnnwc5eu4z6hcnfga5zxjx6 X-Rspamd-Server: rspam03 X-HE-Tag: 1644875362-612229 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: Once upon a time, all swapins counted toward memory pressure[1]. Then Joonsoo introduced workingset detection for anonymous pages and we gained the ability to distinguish hot from cold swapins[2][3]. But we failed to update swap_readpage() accordingly, and now we account partial memory pressure in the swapin path of cold memory. Not for all situations - which adds more inconsistency: paths using the conventional submit_bio() and lock_page() route will not see much pressure - unless storage itself is heavily congested and the bio submissions stall. ZRAM and ZSWAP do most of the work directly from swap_readpage() and will see all swapins reflected as pressure. Restore consistency by making all swapin stall accounting conditional on the page actually being part of the workingset. [1] commit 937790699be9 ("mm/page_io.c: annotate refault stalls from swap_readpage") [2] commit aae466b0052e ("mm/swap: implement workingset detection for anonymous LRU") [3] commit cad8320b4b39 ("mm/swap: don't SetPageWorkingset unconditionally during swapin") Reported-by: CGEL Signed-off-by: Johannes Weiner Cc: Minchan Kim Cc: Joonsoo Kim Cc: Yu Zhao Acked-by: Minchan Kim --- mm/page_io.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/page_io.c b/mm/page_io.c index 61c792f916fa..f6296ee25014 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -359,6 +359,7 @@ int swap_readpage(struct page *page, bool synchronous) struct bio *bio; int ret = 0; struct swap_info_struct *sis = page_swap_info(page); + bool workingset = PageWorkingset(page); unsigned long pflags; VM_BUG_ON_PAGE(!PageSwapCache(page) && !synchronous, page); @@ -370,7 +371,8 @@ int swap_readpage(struct page *page, bool synchronous) * or the submitting cgroup IO-throttled, submission can be a * significant part of overall IO time. */ - psi_memstall_enter(&pflags); + if (workingset) + psi_memstall_enter(&pflags); delayacct_swapin_start(); if (frontswap_load(page) == 0) { @@ -431,7 +433,8 @@ int swap_readpage(struct page *page, bool synchronous) bio_put(bio); out: - psi_memstall_leave(&pflags); + if (workingset) + psi_memstall_leave(&pflags); delayacct_swapin_end(); return ret; }