From patchwork Sat Oct 7 06:23:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13412200 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 4E849E92FFC for ; Sat, 7 Oct 2023 06:24:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B58DB6B02F7; Sat, 7 Oct 2023 02:24:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B08F96B02F8; Sat, 7 Oct 2023 02:24:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F8626B02F9; Sat, 7 Oct 2023 02:24:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 93FFA6B02F7 for ; Sat, 7 Oct 2023 02:24:50 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 53E37400FD for ; Sat, 7 Oct 2023 06:24:50 +0000 (UTC) X-FDA: 81317677140.07.289D2AF Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by imf05.hostedemail.com (Postfix) with ESMTP id 1FF39100018 for ; Sat, 7 Oct 2023 06:24:47 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="f8Opa/Op"; spf=pass (imf05.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696659888; a=rsa-sha256; cv=none; b=ha3awhXbovb/+Cb+zOXVAoZyVbBYhn0Lk72HZHfYgQ+oNw1OD+dYqpR7G8qD6C3ST+G5/I B6NANgRP06nwrxDxN/y6VmZo1IMhWj7U61PkhzxL8vs5OH03Pxj4fQfDeh//CllAyC5+HR l01/2xmnh1nf5a3IMxOb6hy0FO2taIY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="f8Opa/Op"; spf=pass (imf05.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696659888; h=from:from: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:references:dkim-signature; bh=nklBuHxxMw/ogHWHvA/XT6XANu5rykgc5mbrz4eDeo4=; b=pVEJmDeZGXQ2TAkvJ7ADf9eQ2yGVBp7yCmMYaeYn3qaMT76UOHdhP5oTYTUCIFhwdTklru Qld5dIJ8Mkp+RXwD8kQHHosz9PJ3KFAaByLCrC9+7gYLXQl5rORWUkSrwZpvk+tyjtoG8d CRs7m+bqg9UEpxPhQQSKo9ydmw2J17s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696659888; x=1728195888; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=wqsmBsrFVhBwMfcb7/vOHRtZdmYOe7LU00pD8fViK0Y=; b=f8Opa/Oprby1OPnInLvpXbGctEoJfTVgTv5S7U36/ZHq1c7wCLDUtLc3 sNdRV0HK0pvOgc7rouj0RuNu/zT0A/4WzL2QMbFE8AP+ZOE9efwypYlW8 wsZ3aJuzw2P9Z6YvP32Z6IRJLR/UzzNr2hkR9/VSRtB67wWj1AWtgortN WslvdV7PDv3LPl3Vy4T1QYHJwTm1yqN4D2n2GWW9HBmAl/ZdAdAj+BZSD 5IfYTvU63QlcdyWKuVgXnc3wBUJaffy1tk9iF9Wp09EmeSHHKRGADmIDu 6d08ZYMReD3MZ6lSjHFd13g++KFBv2yGLDrozjn8RMzhVJyoK9jgfbul1 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="382764837" X-IronPort-AV: E=Sophos;i="6.03,205,1694761200"; d="scan'208";a="382764837" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2023 23:24:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="787617302" X-IronPort-AV: E=Sophos;i="6.03,205,1694761200"; d="scan'208";a="787617302" Received: from jieli7-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.28.12]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2023 23:24:42 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Christoph Lameter , Mel Gorman , Vlastimil Babka , Michal Hocko Subject: [PATCH -V2] mm: fix draining PCP of remote zone Date: Sat, 7 Oct 2023 14:23:56 +0800 Message-Id: <20231007062356.187621-1-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 1FF39100018 X-Stat-Signature: 1orf8awsxyhou9m99nakx8z1ygp558zm X-Rspam-User: X-HE-Tag: 1696659887-45736 X-HE-Meta: U2FsdGVkX18esxdXCEN1zJFJARAkLc2bPr4+zDXTXrUc4qx0LI3b8+1RYKATLGfCTfY+7DV26jGYLtytRDXNDCGBmMHLEht1OFRNKiQYi1B/Btj8bqa5usU0yIU2jcbuYs6e9W4FYi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qu/kGZWI3jZFEfz6jII6/vMrb5VcBs3lfNnLvFCpNp+X80JlMaE7ERLhcVg793rpOlZPtKKGyzz1ZmmCncqrw8PTNPDVUlXDQVG8vCh2oHhndtGk= 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: If there is no memory allocation/freeing in the PCP (Per-CPU Pageset) of a remote zone (zone in remote NUMA node) after some time (3 seconds for now), the pages of the PCP of the remote zone will be drained to avoid memory wastage. This behavior was introduced in the commit 4ae7c03943fc ("[PATCH] Periodically drain non local pagesets") and the commit 4037d452202e ("Move remote node draining out of slab allocators") But, after the commit 7cc36bbddde5 ("vmstat: on-demand vmstat workers V8"), the vmstat updater worker which is used to drain the PCP of remote zones may not be re-queued when we are waiting for the timeout (pcp->expire != 0) if there are no vmstat changes on this CPU, for example, when the CPU goes idle or runs user space only workloads. This may cause the pages of a remote zone be kept in PCP of this CPU for long time. So that, the page reclaiming of the remote zone may be triggered prematurely. This isn't a severe problem in practice, because the PCP of the remote zone will be drained if some memory are allocated/freed again on this CPU. And, the PCP will eventually be drained during the direct reclaiming if necessary. Anyway, the problem still deserves a fix via guaranteeing that the vmstat updater worker will always be re-queued when we are waiting for the timeout. In effect, this restores the original behavior before the commit 7cc36bbddde5. We can reproduce the bug via allocating/freeing pages from a remote zone then go idle as follows. And the patch can fix it. - Run some workloads, use `numactl` to bind CPU to node 0 and memory to node 1. So the PCP of the CPU on node 0 for zone on node 1 will be filled. - After workloads finish, idle for 60s - Check /proc/zoneinfo With the original kernel, the number of pages in the PCP of the CPU on node 0 for zone on node 1 is non-zero after idle. With the patched kernel, it becomes 0 after idle. That is, we avoid to keep pages in the remote PCP during idle. Fixes: 7cc36bbddde5 ("vmstat: on-demand vmstat workers V8") Signed-off-by: "Huang, Ying" Reviewed-by: Christoph Lameter Cc: Mel Gorman Cc: Vlastimil Babka Cc: Michal Hocko --- mm/vmstat.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/vmstat.c b/mm/vmstat.c index 00e81e99c6ee..7f1bf40e71e8 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -855,8 +855,10 @@ static int refresh_cpu_vm_stats(bool do_pagesets) continue; } - if (__this_cpu_dec_return(pcp->expire)) + if (__this_cpu_dec_return(pcp->expire)) { + changes++; continue; + } if (__this_cpu_read(pcp->count)) { drain_zone_pages(zone, this_cpu_ptr(pcp));