From mboxrd@z Thu Jan 1 00:00:00 1970 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 77DA3C53210 for ; Wed, 4 Jan 2023 23:22:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16DBC900002; Wed, 4 Jan 2023 18:22:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 11CC28E0001; Wed, 4 Jan 2023 18:22:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2787900002; Wed, 4 Jan 2023 18:22:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E4BCC8E0001 for ; Wed, 4 Jan 2023 18:22:49 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C1D13160331 for ; Wed, 4 Jan 2023 23:22:49 +0000 (UTC) X-FDA: 80318693658.04.E114838 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by imf19.hostedemail.com (Postfix) with ESMTP id 3C5071A000A for ; Wed, 4 Jan 2023 23:22:47 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=psyzDoWE; spf=pass (imf19.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.221.52 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=1672874568; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rZzfdo0ziPPx2TPaj2KeqRicG6hTBB0FcIoqRc87RUk=; b=bpOi/DnY9rgfkbyou9m34UiHQmzirtOYhJYGAS8+sTc49pL/VDnxxbIxGIhIkgmTYaC0sT TkcGIlm4ZHVUs5RRdnM5uESN8aCrFGU7ST5go9LOD8G9mE1R5CkrS1HGu9M7nv9yTO9pLW dPzJrgswT0Dn2ElNgAlVGvrlEHn28Q8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=psyzDoWE; spf=pass (imf19.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.221.52 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=1672874568; a=rsa-sha256; cv=none; b=n8pd5CNznLDbp+ver96iAer+rZcLbQjlMEPjUVxTPUcJfgdi8Y523aCm/1fSpzM2yUpkXI 0O1u94VGZwn/oqFFZveISPD3mKbsVLPWMaSNdreOl0l/AKbVar55m3NxvupERcOaUp1OrC wLIKHiFr/bOLaAaF4aBxMNvl34V+nJg= Received: by mail-wr1-f52.google.com with SMTP id d17so14836873wrs.2 for ; Wed, 04 Jan 2023 15:22:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=rZzfdo0ziPPx2TPaj2KeqRicG6hTBB0FcIoqRc87RUk=; b=psyzDoWE8dn3mhEjSUdM6XuCzJlSIkK2IU6izNdCGTNSekIeECgoA1MEej3kHk5Hrg 8Lc+rkqfq+9jAG5HM6J1de1Kx2nle37+OKcMMvR1LilN9viKDF3MmJlXbUt+3X9O5kau Oo4Tdz14ipK9o3Le6+3Bg9Z1niTm5o04QT5OAg623BBqkIEnKHzLbkDDNQLmBje3/Dkb UTOHUJAwt6i8WBYMgIIdCyjPp+axosEtGTN/Wo16L5o0qd78TpLc+3QSmxPe8FnMysBW 0Gix5pgaQJuBiXYZTAyA1aV650sGnrFCykpvLzaqCFtWwC22M4dzwAb1nS40VFfaGjVC 9aow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rZzfdo0ziPPx2TPaj2KeqRicG6hTBB0FcIoqRc87RUk=; b=Th6wI2VR41yBhyRzGkFi6yOrQPgo/9/Y81AISDU5PQIWyBoUxT5f6lAsGKdM2vOye5 GI11aMvL7o99uXgjpXfY1c0zRmIRYOs8FHWArjrBWk978AZLPS0F6CQ+JAWMvXH9b8qy 6LUSflMIF70GEmdxC0zfWK6vSY1OlKJxw/eIS6fEHNIxQdaREpGTghSxhIDwAJ2coV9h iIwNz8XTGpJhTsGsQQmHlCr93DkCUxtDUd+hEyQdYfQmgEUiFZEIi8G95KPwiGx2Otoc cBxb68Wu/9JJApJrKlVz8baNae9zW+VDjALuYf7zRJO4XN0slCur88q3JqtLDijHm7VH JUbA== X-Gm-Message-State: AFqh2kpCOTGSPIzRp9PbvQaxYw8bRDidRUiT+eVhVX025M0NgADTKQYe WAER7gJI51nFdFtv8VuRdxtOKZqKqze+Ya6jAi0= X-Google-Smtp-Source: AMrXdXunSszWmBf44gTHaI+aiu3RKary3dRCzwUnnDN8xzpFRk/ihE4hFTVdFobDPpUjKu2HrZdc19y/uuEFYaq0EkM= X-Received: by 2002:a5d:5221:0:b0:2b0:6953:fac6 with SMTP id i1-20020a5d5221000000b002b06953fac6mr40522wra.131.1672874566982; Wed, 04 Jan 2023 15:22:46 -0800 (PST) MIME-Version: 1.0 References: <20230104222944.2380117-1-nphamcs@gmail.com> In-Reply-To: <20230104222944.2380117-1-nphamcs@gmail.com> From: Nhat Pham Date: Wed, 4 Jan 2023 15:22:35 -0800 Message-ID: Subject: Re: [PATCH] workingset: fix confusion around eviction vs refault container 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 Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: m4ri6qgb1r1ty4srfmiadok3cn93ioka X-Rspam-User: X-Rspamd-Queue-Id: 3C5071A000A X-Rspamd-Server: rspam06 X-HE-Tag: 1672874567-861780 X-HE-Meta: U2FsdGVkX19y+tmAksL1keWkVoqocxlnSAgWI2kI3VtICzH+q1wSaVDwMocueO30d3b/ctsm4Ehb88RXNVnaD7sJQgdhF/NpEggBYXCXMxteKDA5CLeBePFzfut2tBQ6G8t6gQz9tvdB6wy1NmGgqM00KynWXo5dJcBv1aozECdwYEWAs/1O2u8y5oWw/2uGMCbzpSGxDF4hvauDC8E57RveqmzGkngD92FT0YqKvXRFXlCyWapXphpyJyo+E7Bf/HZZLzJbgRuPcLu3o+JmB5clJei9VGFhnHbSrEqk5JykQ95+h5U+r/ZheZ9pL/0Jsr92TwNwVOJqYH/IThF+ds/WOcrcV+TdFQBorg9juOQIhzbX77Y/T4joq8/+cWMfUWFkAxw8XrXBFEGV/+AVDguICcq54pgXjjo/9d+t2K6iw3FiZ40lJoFRaeEhTifDM6mgIAT/pOTJ5Rj002rUT0iVDCU/laOEIo9fUc6Se/5wqy7M1GurXJq34ZysFlrHRAxq38egc7AU0pjBXJEBSxa82DLnMB8RfO54F8+EwAGEb58fpSEb08eFfgwpLBbgXEc0cGMdfSEigMMkr9EIcajCY6WO8gsobv+AHxeSkz8wnnCeq6T5gYPqZ6nOaHTp2mQolH0gEB1ETh5OuzCy5Fz/ttpPhbx4AYqlmfwfPjpUXcZEuu3SaPspqCykEwiCBTN4pSTlCL2tpv88xs2TYvVe5ngcF5nMD0NQ5DKd2syZSkwcWQkrz8bGsYF7tNhBD4wqzDBLESJr8+BvUc7bPO5vxZaj5NocQgwzETzStx3pwDuUuIS2bF4xcmRJsAoYhGMgPh+r/Iir7EGG++nK6DpKXRaVfGs7oYPjspj+sBYvHCt6SIvMR8Lz0qoDOM8pzlWgsksH9X7FCi/4xQpW95wPbg71ZXQ1his5glf4q2H9j6fjwaLr8gC07ExqFFqv5cWigrhJUA9SpLreDMn bWuoAKzi qzNeLix/DtT6VyER4LiCRUlM07XRC67CSsEYEdLgAwANm/rM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.004851, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Jan 4, 2023 at 2:29 PM Nhat Pham wrote: > > 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) { > -- > 2.30.2 Oh this one is sent out twice too... Something is wrong with my pipeline... Anyway, please disregard the first email and only review this one!