Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2759702ybh; Mon, 5 Aug 2019 06:24:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+6M+H+WFCH7Ftfe8EneWSugP2uQTjir7nnEIrEVm9kfzUUNp8hze7vCaLPpnf8AsK6gA6 X-Received: by 2002:a17:90b:d8a:: with SMTP id bg10mr18256810pjb.92.1565011484054; Mon, 05 Aug 2019 06:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565011484; cv=none; d=google.com; s=arc-20160816; b=wOVHc6RlW9r7b7p6RvL3LFAFXVeQgbKKDfDcxob5zoQBcQ3pFd0eFxI+qh8mfp4uH1 E3kkkY3jV/+E4x9VGEVNCmLkHxPzQYSyyuQ1HxXpt+GDfMVevLTx88Y4+3K6H6h2o4AA 2Y1i7iQaCO++fBWrnPXrNtoKK8p/W/iPM9CnH2uWTFGlA+zCybOs8URaVlytOKLI7o5w DD0yKxiKwKbSPGyxwomUjitsaNnbV0cURUFjTDHnLowGZKF76/LRKsFUjdv3Jl6fy6Ko XCO61ed2A9zpqLwykFoyUTFl5VCiMPu36tXnqA08svXsKI2e7ZIWgG2GzRd7zcX+Ae9g rk0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=j1mJRRM/OInokhVuBbDEvKdTAUzRXyTXsgy+Ak2tUzw=; b=tl1vY3mrcpBBIIqXhDaLzeZUMXpdLJUUuKvCKKi3zItVRqzVSPkUG14cgGLMLXB0Gq Z5Xi7OtYB8JkmgPvcsc1zlUkwW88XN3RAugvqCjty911VAbtvXnh+7KA7mytix3rAeZS lm7mNJeG9AjhhnzexgGOm3GLsITAnPxbHYZ/JsAqpmpJy5OglAZL/+lWO1+5ic5diTF1 xwR3WxIDCEEo0zSFT0S51z7HJAHghWv6xUUDYnanjq+NT6upIsI4/e+ViDxs1HGdJu/g NgQfMfrH9pLMfM8u+lntGM5H5lTHY0sw4OajR6EGJU50+ison/05la3zz7QFV+cGOQ2q bC+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BCtQaIzo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o23si47008747pfp.131.2019.08.05.06.24.29; Mon, 05 Aug 2019 06:24:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BCtQaIzo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730872AbfHENXj (ORCPT + 99 others); Mon, 5 Aug 2019 09:23:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:60356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730858AbfHENXh (ORCPT ); Mon, 5 Aug 2019 09:23:37 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 293F221880; Mon, 5 Aug 2019 13:23:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565011416; bh=8uCq6Hog5rSLXya+/nTvcvv2RE/+H2+vXoQZB/KOLes=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BCtQaIzodfI8jEbOZRiaI53O16daspKgrsG+GfLcdlpYjW/HiVPOA7jbYq+RJtvOJ +ZKEz8SmzwjiK1tKlbUdwQRU4IqTPQpc88XiJrP3zP+6ktpjufuK9DeziSvVH0JM29 JRk+1cPMRsSFN6tLElk8bC/KvSNUhpJ9JsGAm2JE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yafang Shao , Johannes Weiner , Michal Hocko , Vladimir Davydov , Yafang Shao , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.2 049/131] mm/memcontrol.c: keep local VM counters in sync with the hierarchical ones Date: Mon, 5 Aug 2019 15:02:16 +0200 Message-Id: <20190805124954.714867980@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190805124951.453337465@linuxfoundation.org> References: <20190805124951.453337465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 766a4c19d880887c457811b86f1f68525e416965 ] After commit 815744d75152 ("mm: memcontrol: don't batch updates of local VM stats and events"), the local VM counter are not in sync with the hierarchical ones. Below is one example in a leaf memcg on my server (with 8 CPUs): inactive_file 3567570944 total_inactive_file 3568029696 We find that the deviation is very great because the 'val' in __mod_memcg_state() is in pages while the effective value in memcg_stat_show() is in bytes. So the maximum of this deviation between local VM stats and total VM stats can be (32 * number_of_cpu * PAGE_SIZE), that may be an unacceptably great value. We should keep the local VM stats in sync with the total stats. In order to keep this behavior the same across counters, this patch updates __mod_lruvec_state() and __count_memcg_events() as well. Link: http://lkml.kernel.org/r/1562851979-10610-1-git-send-email-laoar.shao@gmail.com Signed-off-by: Yafang Shao Acked-by: Johannes Weiner Cc: Michal Hocko Cc: Vladimir Davydov Cc: Yafang Shao Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/memcontrol.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 591eafafbd8cb..902d020aa70e5 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -691,12 +691,15 @@ void __mod_memcg_state(struct mem_cgroup *memcg, int idx, int val) if (mem_cgroup_disabled()) return; - __this_cpu_add(memcg->vmstats_local->stat[idx], val); - x = val + __this_cpu_read(memcg->vmstats_percpu->stat[idx]); if (unlikely(abs(x) > MEMCG_CHARGE_BATCH)) { struct mem_cgroup *mi; + /* + * Batch local counters to keep them in sync with + * the hierarchical ones. + */ + __this_cpu_add(memcg->vmstats_local->stat[idx], x); for (mi = memcg; mi; mi = parent_mem_cgroup(mi)) atomic_long_add(x, &mi->vmstats[idx]); x = 0; @@ -745,13 +748,15 @@ void __mod_lruvec_state(struct lruvec *lruvec, enum node_stat_item idx, /* Update memcg */ __mod_memcg_state(memcg, idx, val); - /* Update lruvec */ - __this_cpu_add(pn->lruvec_stat_local->count[idx], val); - x = val + __this_cpu_read(pn->lruvec_stat_cpu->count[idx]); if (unlikely(abs(x) > MEMCG_CHARGE_BATCH)) { struct mem_cgroup_per_node *pi; + /* + * Batch local counters to keep them in sync with + * the hierarchical ones. + */ + __this_cpu_add(pn->lruvec_stat_local->count[idx], x); for (pi = pn; pi; pi = parent_nodeinfo(pi, pgdat->node_id)) atomic_long_add(x, &pi->lruvec_stat[idx]); x = 0; @@ -773,12 +778,15 @@ void __count_memcg_events(struct mem_cgroup *memcg, enum vm_event_item idx, if (mem_cgroup_disabled()) return; - __this_cpu_add(memcg->vmstats_local->events[idx], count); - x = count + __this_cpu_read(memcg->vmstats_percpu->events[idx]); if (unlikely(x > MEMCG_CHARGE_BATCH)) { struct mem_cgroup *mi; + /* + * Batch local counters to keep them in sync with + * the hierarchical ones. + */ + __this_cpu_add(memcg->vmstats_local->events[idx], x); for (mi = memcg; mi; mi = parent_mem_cgroup(mi)) atomic_long_add(x, &mi->vmevents[idx]); x = 0; -- 2.20.1