From patchwork Fri Feb 5 18:27:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 12070705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E58D2C4332D for ; Fri, 5 Feb 2021 18:28:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 53A7A64EEF for ; Fri, 5 Feb 2021 18:28:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 53A7A64EEF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C5FF06B0071; Fri, 5 Feb 2021 13:28:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C0FD86B0073; Fri, 5 Feb 2021 13:28:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B012E6B0074; Fri, 5 Feb 2021 13:28:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0230.hostedemail.com [216.40.44.230]) by kanga.kvack.org (Postfix) with ESMTP id 99D3B6B0071 for ; Fri, 5 Feb 2021 13:28:28 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 642808249980 for ; Fri, 5 Feb 2021 18:28:28 +0000 (UTC) X-FDA: 77785049496.08.leg84_5007526275e6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 421B31819E793 for ; Fri, 5 Feb 2021 18:28:28 +0000 (UTC) X-HE-Tag: leg84_5007526275e6 X-Filterd-Recvd-Size: 5765 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Fri, 5 Feb 2021 18:28:27 +0000 (UTC) Received: by mail-qt1-f170.google.com with SMTP id e15so5675405qte.9 for ; Fri, 05 Feb 2021 10:28:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=anbL9Wexkq0QH+x4JfZ6vBo+adkAAWXAkexWmp3sHZ4=; b=U4EQA/daTMWDj2KpnKM6JeOv9uy/kBDEm/uO2MZ/dYoFEl9BtZMe0u8Up1GJlOAVat FyUdHSnYcoLRyCDpy8I5JguO9gryQYk06pvXlFuWvP1nanx9BoVt708OpOVjX7hGp0NM u3CpSRjrbpoptPnLF+vCKAD0uEl8CgLgfTmhRpQRx/D7hadhMAKsjwWqjtUsOTrJBngg UoyMrvGzLTbhsQjBLb0Zn4ex3iUdg2hNEv85wEs/BAJ3rcBGu3oLsoIUeTYsYAC4yl/2 Yon8QeGPR9FRKoCpxU7jZA/EY4KF58sECERo6V/grHRiHwQukuZWKSjdWkEetayENa9D 8EAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=anbL9Wexkq0QH+x4JfZ6vBo+adkAAWXAkexWmp3sHZ4=; b=khdONrDJVa28SlruegnYwZ80eLWx3TBUHOKFKmv1cdjql3ZdIy1SI23RvODgL8cfgA ieT7k8D8iKPwQOLrNgzO6Qpx8j0AN4rCk06PPKAFq0V3Sq93xBtC0TFHAVCc78YJ02DN hser0rf78ThAqNfKSGKezw21jc9fPDnDPwgMZcOFMqI4G+23ryz//vZhvE3u78dMEwEK 8e33fUJ8tYFn9psatuGh2q/plbdaa6++c7N9DX9JbTlPLbxx55riMkZNOEXiK9N6npPo XmOevezUfZUdgEhdux4tJS8zz5AxTIsHAxb8kzVGeUwJHsx+1abPc8uzwQzAwQ1txfcI Jlxg== X-Gm-Message-State: AOAM530fGCuCfhRtkiIUVQWRLHFhv0R7i09JrNU4kCrlEqAIRYrdDeId hpIbERSmNp0Ib6H7mXn/rZXyrA== X-Google-Smtp-Source: ABdhPJxc7WXk4zJUXM1XvvDnCZEwxVU/BXPLAaamoPKXlLUScXsoh7UaMFIajiqR+agL6tmf/QJPQg== X-Received: by 2002:ac8:598e:: with SMTP id e14mr5644319qte.346.1612549707014; Fri, 05 Feb 2021 10:28:27 -0800 (PST) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id q50sm9452451qtb.32.2021.02.05.10.28.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 10:28:26 -0800 (PST) From: Johannes Weiner To: Andrew Morton , Tejun Heo Cc: Michal Hocko , Roman Gushchin , Shakeel Butt , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 1/8] mm: memcontrol: fix cpuhotplug statistics flushing Date: Fri, 5 Feb 2021 13:27:59 -0500 Message-Id: <20210205182806.17220-2-hannes@cmpxchg.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205182806.17220-1-hannes@cmpxchg.org> References: <20210205182806.17220-1-hannes@cmpxchg.org> MIME-Version: 1.0 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: The memcg hotunplug callback erroneously flushes counts on the local CPU, not the counts of the CPU going away; those counts will be lost. Flush the CPU that is actually going away. Also simplify the code a bit by using mod_memcg_state() and count_memcg_events() instead of open-coding the upward flush - this is comparable to how vmstat.c handles hotunplug flushing. Fixes: a983b5ebee572 ("mm: memcontrol: fix excessive complexity in memory.stat reporting") Signed-off-by: Johannes Weiner Reviewed-by: Shakeel Butt Reviewed-by: Roman Gushchin Acked-by: Michal Hocko --- mm/memcontrol.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index ed5cc78a8dbf..8120d565dd79 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2411,45 +2411,52 @@ static void drain_all_stock(struct mem_cgroup *root_memcg) static int memcg_hotplug_cpu_dead(unsigned int cpu) { struct memcg_stock_pcp *stock; - struct mem_cgroup *memcg, *mi; + struct mem_cgroup *memcg; stock = &per_cpu(memcg_stock, cpu); drain_stock(stock); for_each_mem_cgroup(memcg) { + struct memcg_vmstats_percpu *statc; int i; + statc = per_cpu_ptr(memcg->vmstats_percpu, cpu); + for (i = 0; i < MEMCG_NR_STAT; i++) { int nid; - long x; - x = this_cpu_xchg(memcg->vmstats_percpu->stat[i], 0); - if (x) - for (mi = memcg; mi; mi = parent_mem_cgroup(mi)) - atomic_long_add(x, &memcg->vmstats[i]); + if (statc->stat[i]) { + mod_memcg_state(memcg, i, statc->stat[i]); + statc->stat[i] = 0; + } if (i >= NR_VM_NODE_STAT_ITEMS) continue; for_each_node(nid) { + struct batched_lruvec_stat *lstatc; struct mem_cgroup_per_node *pn; + long x; pn = mem_cgroup_nodeinfo(memcg, nid); - x = this_cpu_xchg(pn->lruvec_stat_cpu->count[i], 0); - if (x) + lstatc = per_cpu_ptr(pn->lruvec_stat_cpu, cpu); + + x = lstatc->count[i]; + lstatc->count[i] = 0; + + if (x) { do { atomic_long_add(x, &pn->lruvec_stat[i]); } while ((pn = parent_nodeinfo(pn, nid))); + } } } for (i = 0; i < NR_VM_EVENT_ITEMS; i++) { - long x; - - x = this_cpu_xchg(memcg->vmstats_percpu->events[i], 0); - if (x) - for (mi = memcg; mi; mi = parent_mem_cgroup(mi)) - atomic_long_add(x, &memcg->vmevents[i]); + if (statc->events[i]) { + count_memcg_events(memcg, i, statc->events[i]); + statc->events[i] = 0; + } } }