Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5707585ybp; Tue, 15 Oct 2019 03:58:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqzEEpImdVfK7q0OegRG/qC8Zip/TMnFioQenn8nzMU0DA9622z7YNzX8iPTgJaKxVVbn8R2 X-Received: by 2002:a05:6402:21eb:: with SMTP id ce11mr32255612edb.182.1571137081431; Tue, 15 Oct 2019 03:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571137081; cv=none; d=google.com; s=arc-20160816; b=vkcZnX0CMkS16Q2nrSQ6YJUbiVRNwvXP7HoWbMm8WlM3ZUiRVC8sYlXpBx+TuB1aUn uuu+GOkUPxUdO97IiMOfonZSej3YU8f3WkkX7HlABBio/taIvnAyw/MjG0fhkxeyOHO4 iWC66dN0GqzSDgfv2bBI6EN8Z+5W4Q1NOZ2Yty/Wj4kf/0t2VFV0In/6dB/HWw7pMiid z32Z+PcGw31+iYtBUqB2pCsQK5UWbqO625fF2QXH5vMVRTpfxiYVuHHxxcOzCuYgfX/3 f4Q6nFfGXM61tiL5rWSj4cLw6ZNkgv/+glHd3wt5IMTfHnRHRovs9BqquEWyU5U36wNL l1Rw== 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:message-id:date:cc:to:from:subject:dkim-signature; bh=uBM99g9Ux3Kxexvrq/r6f01uJx9JtYqNm8Mfn0xVlC8=; b=f6pSe7yIki2A4Pw+YW8L14nfoubwl0E6X4NpHHA7KvDam9knwxYUM3ERDJWnaPpf42 npFmM8JxpYC6Y94/xsZbMovZm5W0Ef7eGWJVjl8+1m1uknHQVD1fEKOR8ZNQ++8uPmh1 +oF71aptFWt84XPbK8WOwJSelV1ri6nFhXkBMzX4SQS7/4NgEDwWi/N0IOPagT7wHgAr NkUnYIXWUDHKeCzM9qlf91laHaFgFFbD0cO3taUf3NHo4ilEM5mDbOQqj5TYOMLIDsOs blqXA36KCxNXNcM66wkTm76qeM56kRTPSqGn+YIKznGPuOjLjxOCmXECN5t14SvLp0uG nAMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=0zJyKpG7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x20si12386871ejb.393.2019.10.15.03.57.38; Tue, 15 Oct 2019 03:58:01 -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=@yandex-team.ru header.s=default header.b=0zJyKpG7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728535AbfJOIKD (ORCPT + 99 others); Tue, 15 Oct 2019 04:10:03 -0400 Received: from forwardcorp1o.mail.yandex.net ([95.108.205.193]:45518 "EHLO forwardcorp1o.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728295AbfJOIKD (ORCPT ); Tue, 15 Oct 2019 04:10:03 -0400 Received: from mxbackcorp1g.mail.yandex.net (mxbackcorp1g.mail.yandex.net [IPv6:2a02:6b8:0:1402::301]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id C88662E129A; Tue, 15 Oct 2019 11:09:59 +0300 (MSK) Received: from iva4-c987840161f8.qloud-c.yandex.net (iva4-c987840161f8.qloud-c.yandex.net [2a02:6b8:c0c:3da5:0:640:c987:8401]) by mxbackcorp1g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id nfkXVoMT4l-9xq84ZVX; Tue, 15 Oct 2019 11:09:59 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1571126999; bh=uBM99g9Ux3Kxexvrq/r6f01uJx9JtYqNm8Mfn0xVlC8=; h=Message-ID:Date:To:From:Subject:Cc; b=0zJyKpG7DWT6yZkKFLtLlBCDanDEvWtoPV22gBVytDfdFHCGcDN3cNYokg3xrx23a yV8iYJy6AziG4UYARUNuT4xWygPrhyB4XnTvju8yRj7eTLGBh/BrKL4wgr485tWZK/ B1IZEXSXS1tFGgk3Jhtgz1t5/D9VbJfk5tJKB1mc= Authentication-Results: mxbackcorp1g.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:3d4d:a9cb:ef29:4bb1]) by iva4-c987840161f8.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA id xXgS5w1Urj-9xNiLTXE; Tue, 15 Oct 2019 11:09:59 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) Subject: [PATCH] mm/memcontrol: update lruvec counters in mem_cgroup_move_account From: Konstantin Khlebnikov To: linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org Cc: cgroups@vger.kernel.org, Michal Hocko , Vladimir Davydov , Johannes Weiner Date: Tue, 15 Oct 2019 11:09:59 +0300 Message-ID: <157112699975.7360.1062614888388489788.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Mapped, dirty and writeback pages are also counted in per-lruvec stats. These counters needs update when page is moved between cgroups. Fixes: 00f3ca2c2d66 ("mm: memcontrol: per-lruvec stats infrastructure") Signed-off-by: Konstantin Khlebnikov --- mm/memcontrol.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index bdac56009a38..363106578876 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5420,6 +5420,8 @@ static int mem_cgroup_move_account(struct page *page, struct mem_cgroup *from, struct mem_cgroup *to) { + struct lruvec *from_vec, *to_vec; + struct pglist_data *pgdat; unsigned long flags; unsigned int nr_pages = compound ? hpage_nr_pages(page) : 1; int ret; @@ -5443,11 +5445,15 @@ static int mem_cgroup_move_account(struct page *page, anon = PageAnon(page); + pgdat = page_pgdat(page); + from_vec = mem_cgroup_lruvec(pgdat, from); + to_vec = mem_cgroup_lruvec(pgdat, to); + spin_lock_irqsave(&from->move_lock, flags); if (!anon && page_mapped(page)) { - __mod_memcg_state(from, NR_FILE_MAPPED, -nr_pages); - __mod_memcg_state(to, NR_FILE_MAPPED, nr_pages); + __mod_lruvec_state(from_vec, NR_FILE_MAPPED, -nr_pages); + __mod_lruvec_state(to_vec, NR_FILE_MAPPED, nr_pages); } /* @@ -5459,14 +5465,14 @@ static int mem_cgroup_move_account(struct page *page, struct address_space *mapping = page_mapping(page); if (mapping_cap_account_dirty(mapping)) { - __mod_memcg_state(from, NR_FILE_DIRTY, -nr_pages); - __mod_memcg_state(to, NR_FILE_DIRTY, nr_pages); + __mod_lruvec_state(from_vec, NR_FILE_DIRTY, -nr_pages); + __mod_lruvec_state(to_vec, NR_FILE_DIRTY, nr_pages); } } if (PageWriteback(page)) { - __mod_memcg_state(from, NR_WRITEBACK, -nr_pages); - __mod_memcg_state(to, NR_WRITEBACK, nr_pages); + __mod_lruvec_state(from_vec, NR_WRITEBACK, -nr_pages); + __mod_lruvec_state(to_vec, NR_WRITEBACK, nr_pages); } #ifdef CONFIG_TRANSPARENT_HUGEPAGE