From patchwork Wed Jan 4 22:29:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 39140 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2180wrt; Wed, 4 Jan 2023 14:33:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXvY/9h0PE/SslyzVbOtwFReS+1g18vgiLVosegM5G6CQF8MoMzM8DPGsrfVZ9+jWA+8KpOK X-Received: by 2002:a17:907:73c1:b0:7c1:2868:65f1 with SMTP id es1-20020a17090773c100b007c1286865f1mr38472274ejc.72.1672871616735; Wed, 04 Jan 2023 14:33:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672871616; cv=none; d=google.com; s=arc-20160816; b=Jm0SUaL2mMUxI/0hJHF69gTI0UU9tQ2bAlJp2i0/tyHKI7EJfHofx0+0NTm7abNeG/ lj5adpheniY/jkInlVW9SHs5kw2K2v42BUXACsB27t6RM+X7dhJAlGiWMbkL6bzJuPgC C+oV5JqsSCHM06ds5x6ntcVialITHPJ6Ft2wg4xH25oE3/PbnFhx65iKR0OeG9boSnOK 5Rdr9LXInCyyGTklSujdpurPhBjqIb1VCHZ5OuT+bqFuVEslHr7+ltuL92SJofgmkz4U YAzh18pwEH/UdWH2oCaxMvyNhHA2JHObgIp4t+mISrTsUY1Y4d/aCA3waQsU/+tBEzQ+ K9ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=npFjL6Dds3DKnQo07iUTlbqXMaucW9/yvERNl8ZNQRo=; b=ZrsgHKkTu0t2QIFJhxoe4zFvB+l+w8DtYWblbuN+Se9Pmwhb27jbGYOlJQlWGCW9gE skOsxk30hlShzT+QXLTzNTdgMGx/dWhN3eTzHBDtxUw/8Dq6/U0V0DkLUSFH/8sY+EIa cjpGatXyv+Ts760bI5InjBDmDEIIIh46nttqcekAwfUioxXYkoTC76xFl2o12zfxGg4h wa5WXgN/Vw2eP3aAotLu8HYBE8jby6tM0upSONcZnNVNHzwMf5iy/s9uC4SXOJHMS6Ri l1qj7aSGAiGILgmjUrhtW33wYuSzlQOFfqjevH5piQm/cOF1YVw4Ygnn/IIOkIaNYCl8 MCKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="OWeh/xJa"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ek8-20020a056402370800b00485d0d6ea57si21880708edb.619.2023.01.04.14.33.13; Wed, 04 Jan 2023 14:33:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="OWeh/xJa"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240071AbjADW36 (ORCPT + 99 others); Wed, 4 Jan 2023 17:29:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240297AbjADW3w (ORCPT ); Wed, 4 Jan 2023 17:29:52 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0466B42600 for ; Wed, 4 Jan 2023 14:29:46 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id o21so7645222pjw.0 for ; Wed, 04 Jan 2023 14:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=npFjL6Dds3DKnQo07iUTlbqXMaucW9/yvERNl8ZNQRo=; b=OWeh/xJasix7ucatObuWl3DONvbabYvNQFmjbkxy4TsWrHQ6sgQ4Q1RrAkB4fHWo+R QqcOI5wHYusIxypkiUE8QA01I5znwb5MuEjGOOxYlGRJXgJ+t/Y07y47zlCa+bDecmCa jRLDzay7BhzAr/uX7Bq2XoBrcJNGjwJAn35htNsjVF1VEApIDR1mSs2kCG3nZpWp7gOg Bv65mwAtANq3K4PBT7gLkZyUIoth4O9joCJSfs0ZH5tVn9bhQrv8h6OrMlNoPYCDJn8L sPOIgorTOJPWjB04nmHqo48GY30cOLowMhG9Ue3oL4PXSXkMHjI0kIOTZs49MzFZYsTj Zy4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=npFjL6Dds3DKnQo07iUTlbqXMaucW9/yvERNl8ZNQRo=; b=w9Q3K+OySUwoQe9/21Us6gutRc1TDLk/eR1NLG6psZlVBNcmgyIsAKrgey/kQrayyD 4XdUdaQf2t/diZWU4I+2yZ50GEDh6Jmm70Rgl0L6Sci83C42FkXrmQOej7cH+FJqZ9oI 1k3PWONAd6UhT4WyEIZcghu+6HZXipZFSSxTCTCNEOU+V56L6gX0IMeG6rkwDC82E5oe FR0tLG8Q8JHVR50FOnfaoYJ03H/pVMVVcDS/Ac5IuNiz4raCvtmN5KUANZConDz8PLb7 zrhaGcRF0cfKyURuwQNDv1yVMIozygWW/Bg+115aBb/+HNB/RWAstL2QuVEgISpNuzVG gnKQ== X-Gm-Message-State: AFqh2koPz8dXsXi63u+gbjEY8VlQK+dzzpCTIceIqi13r+dFw8v2+koS fLUZjCwjuAhqJzCbVvJl4WQE5GBS+kk= X-Received: by 2002:a17:902:848d:b0:191:1e89:35de with SMTP id c13-20020a170902848d00b001911e8935demr52352601plo.9.1672871386139; Wed, 04 Jan 2023 14:29:46 -0800 (PST) Received: from localhost (fwdproxy-prn-012.fbsv.net. [2a03:2880:ff:c::face:b00c]) by smtp.gmail.com with ESMTPSA id im22-20020a170902bb1600b00192944e3650sm15456333plb.268.2023.01.04.14.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 14:29:45 -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] workingset: fix confusion around eviction vs refault container Date: Wed, 4 Jan 2023 14:29:44 -0800 Message-Id: <20230104222944.2380117-1-nphamcs@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754133028631283527?= X-GMAIL-MSGID: =?utf-8?q?1754133028631283527?= 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(-) 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) {