From patchwork Mon Dec 5 17:51:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13064928 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 961C2C4321E for ; Mon, 5 Dec 2022 17:51:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 276D78E0003; Mon, 5 Dec 2022 12:51:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 228318E0001; Mon, 5 Dec 2022 12:51:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F0778E0003; Mon, 5 Dec 2022 12:51:47 -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 019AA8E0001 for ; Mon, 5 Dec 2022 12:51:46 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AC08D1A078B for ; Mon, 5 Dec 2022 17:51:46 +0000 (UTC) X-FDA: 80208995412.11.1AEDE23 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf11.hostedemail.com (Postfix) with ESMTP id 48DFB40012 for ; Mon, 5 Dec 2022 17:51:45 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mLWxUj1c; spf=pass (imf11.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670262705; a=rsa-sha256; cv=none; b=0UmN+1M5wsTGuog73r0o1duHgYLKT4JMvYchGMjun9GfOg9YXmHJ7CI2zdSnjwBT2QE5ZF 4GmtBRtec0WFibNXueP3DPKXb6EzMVQgHkIQtlImp9qSBKqRBYKa8acaGUgW6Afi3LKzbq RQRvCwrPAnr+kOIouwa+8PEeGMAMqzM= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mLWxUj1c; spf=pass (imf11.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670262705; 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:in-reply-to:references:references:dkim-signature; bh=npFjL6Dds3DKnQo07iUTlbqXMaucW9/yvERNl8ZNQRo=; b=CIgKJepAq05E6Rbx+r1Kyaz79ATeeVAVoya95f2Mknw6hOCLKE2JvfzL5HcCt4qak+fK71 BGkik17ykX1ZLxtFaJjH//HjOnmZCqNGmaX6Y3Ntxdp60G8sWiae5CGaEcX+7qViDiSH3u MyGFVb5pnHYwmJ28cTaU+pPn29W3SK0= Received: by mail-pl1-f173.google.com with SMTP id s7so11525920plk.5 for ; Mon, 05 Dec 2022 09:51:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=npFjL6Dds3DKnQo07iUTlbqXMaucW9/yvERNl8ZNQRo=; b=mLWxUj1chMRiHdvugVEpnaxQ41A/ablxwsfxwk8xacytULj+ChB/06IFBL6WwSIScd 4UnPBnLjtdJHcrXsK8FrHNSCKlQJosnldDtaMV7Y6yjl6vVGA8CnsUR4UNcov+bpxf7l 1e2gADjhBINCiJVwtfuwZmxFtzvnoNpDHz6DRdaKJi+DPqLQ8hCNpZBPeDqAKBn8P+67 AgBeur0PkHavY/K9nJOKtSb29BTgBnokiSezvSqrDesT1h0xSPvN4CjbmVS/EHS1/MJZ GilTo4H194oDwlt09T1aymIMfQ9aR7xVQAtH5wbx3oi6kb6dFhMa97eaikt7FES2sMrR DhQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=npFjL6Dds3DKnQo07iUTlbqXMaucW9/yvERNl8ZNQRo=; b=4VRUYQdfT7y7Z/fN6/TijFyTfv9JRqjbOn5VGS4soy4ZMwLZxS5uW7+a5rUjUzfkvR Fun+91us4VFSs/MECw7SNUbjN97oDMY8T6ZTzv45ZkPZasjCFajeG4yBgQPRpaEMvyFd 24sMh45QExv+DdJwcfoK9DkXV3a+BmxOZ9aJqpWqe8LZ4CbhC6yaRfAwl4ATD2I9wCX4 gfsuhZA6DZSHMtGIul2+oZa1ClfM2jOE0rWnY5Huiib+/gIvtLlwYbHQDRaR/cceD/TD c2UFDxvxgZ50vVzix/+MdDqb8sSI4G+vfIG4sGZ4HxSS2Ss+OulLoe0j93oyHYmQgDty +pMw== X-Gm-Message-State: ANoB5pliSxfcfUt5wAwHSaZOsNtaoWCfLXQausLG3g0DdO47oYqW63mv R0KVGcsVD/Z4UIhk0sktWeE= X-Google-Smtp-Source: AA0mqf7E5ztRL11sQZw9Ri0S+eLl0oSX/xxG2eP09s/4GVm7agnok9htqDogdvSs9ZdZLmqIvUrxvg== X-Received: by 2002:a17:90a:eac2:b0:219:484:e955 with SMTP id ev2-20020a17090aeac200b002190484e955mr53314897pjb.214.1670262704724; Mon, 05 Dec 2022 09:51:44 -0800 (PST) Received: from localhost (fwdproxy-prn-001.fbsv.net. [2a03:2880:ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id m1-20020a17090a5a4100b00219396d795esm9476586pji.15.2022.12.05.09.51.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 09:51:44 -0800 (PST) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, bfoster@redhat.com, willy@infradead.org, kernel-team@meta.com Subject: [PATCH v2 1/4] workingset: fix confusion around eviction vs refault container Date: Mon, 5 Dec 2022 09:51:37 -0800 Message-Id: <20221205175140.1543229-2-nphamcs@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221205175140.1543229-1-nphamcs@gmail.com> References: <20221205175140.1543229-1-nphamcs@gmail.com> MIME-Version: 1.0 X-Spamd-Result: default: False [6.59 / 9.00]; SORBS_IRL_BL(3.00)[209.85.214.173:from]; R_MISSING_CHARSET(2.50)[]; MID_CONTAINS_FROM(1.00)[]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; BAYES_HAM(-0.01)[42.88%]; FROM_HAS_DN(0.00)[]; R_DKIM_ALLOW(0.00)[gmail.com:s=20210112]; RCPT_COUNT_SEVEN(0.00)[7]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; DMARC_POLICY_ALLOW(0.00)[gmail.com,none]; DKIM_TRACE(0.00)[gmail.com:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; R_SPF_ALLOW(0.00)[+ip4:209.85.128.0/17:c]; TO_DN_NONE(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; ARC_NA(0.00)[] X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 48DFB40012 X-Stat-Signature: jctommggzmqnhzx7zze3egat5yt315uw X-HE-Tag: 1670262705-190473 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Johannes Weiner Refault decisions are made based on the lruvec where the page was evicted, as that determined its LRU order while it was alive. Stats and workingset aging must then occur on the lruvec of the new page, as that's the node and cgroup that experience the refault and that's the lruvec whose nonresident info ages out by a new resident page. Those lruvecs could be different when a page is shared between cgroups, or the refaulting page is allocated on a different node. There are currently two mix-ups: 1. When swap is available, the resident anon set must be considered when comparing the refault distance. The comparison is made against the right anon set, but the check for swap is not. When pages get evicted from a cgroup with swap, and refault in one without, this can incorrectly consider a hot refault as cold - and vice versa. Fix that by using the eviction cgroup for the swap check. 2. The stats and workingset age are updated against the wrong lruvec altogether: the right cgroup but the wrong NUMA node. When a page refaults on a different NUMA node, this will have confusing stats and distort the workingset age on a different lruvec - again possibly resulting in hot/cold misclassifications down the line. Fix the swap check and the refault pgdat to address both concerns. This was found during code review. It hasn't caused notable issues in production, suggesting that those refault-migrations are relatively rare in practice. Signed-off-by: Johannes Weiner Co-developed-by: Nhat Pham Signed-off-by: Nhat Pham --- mm/workingset.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.30.2 diff --git a/mm/workingset.c b/mm/workingset.c index ae7e984b23c6..79585d55c45d 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -457,6 +457,7 @@ void workingset_refault(struct folio *folio, void *shadow) */ nr = folio_nr_pages(folio); memcg = folio_memcg(folio); + pgdat = folio_pgdat(folio); lruvec = mem_cgroup_lruvec(memcg, pgdat); mod_lruvec_state(lruvec, WORKINGSET_REFAULT_BASE + file, nr); @@ -474,7 +475,7 @@ void workingset_refault(struct folio *folio, void *shadow) workingset_size += lruvec_page_state(eviction_lruvec, NR_INACTIVE_FILE); } - if (mem_cgroup_get_nr_swap_pages(memcg) > 0) { + if (mem_cgroup_get_nr_swap_pages(eviction_memcg) > 0) { workingset_size += lruvec_page_state(eviction_lruvec, NR_ACTIVE_ANON); if (file) {