Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4075247ybz; Mon, 20 Apr 2020 15:14:33 -0700 (PDT) X-Google-Smtp-Source: APiQypITWVRPwgScvI3DBdPbkcWODTPrZyUuCGpJJtaktQw8YNkJpNidJvW6TiPfm6pQGKeKraat X-Received: by 2002:aa7:d655:: with SMTP id v21mr10234677edr.355.1587420872818; Mon, 20 Apr 2020 15:14:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587420872; cv=none; d=google.com; s=arc-20160816; b=0cTc4kzXzY8NJOz+RnJ56WMH7MTcMwOZsf+KJTCZYjNCyjmo1/JshzRJ1h8VnV8EOw WDBaWqFqO5J0pQA2w4AYyy2tT0LpcQCicEnlR4yB7xgI02uLka2ctBWI3MuXhPgSijhs OsL1SwwZlFn3saIHbw69v2gLi6Q8D8wj2gR3L4gV2Tj1TmKB+6UCP4pPOtozdnNtVCj7 jNOCx8m9Map3rwlVS7RKb74IZePlmkRvEbGhk3/wARr90FEfzIhTlZnz1eD7QI9IIChL 7p/Zv2/uUKi994VjAJe37OGiZNcA+uCx2+cpvel535RY5trTxZklO35rbJepBP/2GrK2 v01g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=B6Lc3E3LhxWdBCoIQ263CZTYhXxWswvkwsnvqPUoqvI=; b=ksYw4f4q9imf3Uh3iOHuf6snau6jGjME35cyfz1D7MbmGPHUBHGnzZuRYb9iUnGrhv ip6nUmtf9Zwf5p0yiBbV+HyGLZtNj6QpzVAUAlobTQaTp9NP4VdfeMs6vNuHY9or3G3R pPKa+KwGimTNKDtS104RD27IURbg1Oxo8b1CxnKo0ROHbWAM60s6NOeJyWzrv1BEv6rA YrwEBVMyJoCtKHF3gSA5M/ZNBO1eTAAzOSuUbSTzTTFmNJUrj18m3xEGQVYOcadNI8u1 4/le7TMEKqWPIryioUlKy6DVAcgQG8oqNojvwVs4wFREW2CmHX2UNEXmc+w2XaOKjSDb GbMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b="zOh4nR//"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cf5si362126ejb.171.2020.04.20.15.14.10; Mon, 20 Apr 2020 15:14:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b="zOh4nR//"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728291AbgDTWMB (ORCPT + 99 others); Mon, 20 Apr 2020 18:12:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728209AbgDTWL4 (ORCPT ); Mon, 20 Apr 2020 18:11:56 -0400 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D50C2C061A41 for ; Mon, 20 Apr 2020 15:11:55 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id w29so10044260qtv.3 for ; Mon, 20 Apr 2020 15:11:55 -0700 (PDT) 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=B6Lc3E3LhxWdBCoIQ263CZTYhXxWswvkwsnvqPUoqvI=; b=zOh4nR//aGqF/G3PkVQBTFQpUXaW2roAMB53HTt3TgNOo4Skb5ppokAmhVW07gKrgS Iz5r3vdxlD8OBux0DOlpjHsXYTfU46y9ILOMZ+x+3ZN77/8ZkatUWSzOjZP3cHCh7IUm YHGQrlRRFJZ4Sksi3PQh6eOPU7qfLoNDvw5lAJxQFEzP8GUIQ+km9ul/+/baMjnxjpUR l01Mi9MKW3UZ01itSMHkJqXfR6hXne2g0igBp3ULTRt7epfQtzKpURMliuCd91FTIxsV 4P5LdL/TnocHc9+7FXcNilk2T0otOYFWgPHciSC3APZ4Rj7J0C15LDLbsIgvf+cA7/Gd hSEQ== 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=B6Lc3E3LhxWdBCoIQ263CZTYhXxWswvkwsnvqPUoqvI=; b=TGD3aOEzuFz6FntK2xPud3ByIB3RwXRfxN8wQoKJolytRVvVjm/RUuJuHbP1E7J9CR wm7ean1aPuq+/xiy3pWwvH9XmX6Wus5bPTXoouhUA9mBOH27aZ6+xz75LB4jZ75MHvh9 dtNzFyYyAKxCj1m7FtvvrpDkRvmz6C9KNPv94QThcie52NF2U14XAWAsKRgq6tDenv/6 ypxnVxjgqSD0Vmf02k/CTYoJbU1tv6IAHJZ12mWfFtpyxvFru2HpSrca7vjqXKqfGPiI GLpEJEfajToGAkfiVvyLB7S+541VTdoP6VHXnCs/twZDAZftj2WJDZTTDTUmbbQKeRXD e5hQ== X-Gm-Message-State: AGi0PuYcB5J0MO6yRFY3GEl31vJz1vhdNRqWtULGL2Ey7SzaQn+TZFl3 lv/t+MMcibFZw5/feZitWzWVaw== X-Received: by 2002:aed:3b0b:: with SMTP id p11mr18236016qte.109.1587420715039; Mon, 20 Apr 2020 15:11:55 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:e6b6]) by smtp.gmail.com with ESMTPSA id u5sm590828qkm.116.2020.04.20.15.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2020 15:11:54 -0700 (PDT) From: Johannes Weiner To: Joonsoo Kim , Alex Shi Cc: Shakeel Butt , Hugh Dickins , Michal Hocko , "Kirill A. Shutemov" , Roman Gushchin , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 08/18] mm: memcontrol: prepare cgroup vmstat infrastructure for native anon counters Date: Mon, 20 Apr 2020 18:11:16 -0400 Message-Id: <20200420221126.341272-9-hannes@cmpxchg.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200420221126.341272-1-hannes@cmpxchg.org> References: <20200420221126.341272-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Anonymous compound pages can be mapped by ptes, which means that if we want to track NR_MAPPED_ANON, NR_ANON_THPS on a per-cgroup basis, we have to be prepared to see tail pages in our accounting functions. Make mod_lruvec_page_state() and lock_page_memcg() deal with tail pages correctly, namely by redirecting to the head page which has the page->mem_cgroup set up. Signed-off-by: Johannes Weiner --- include/linux/memcontrol.h | 5 +++-- mm/memcontrol.c | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 5e8b0e38f145..5a1b5a7b7728 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -711,16 +711,17 @@ static inline void mod_lruvec_state(struct lruvec *lruvec, static inline void __mod_lruvec_page_state(struct page *page, enum node_stat_item idx, int val) { + struct page *head = compound_head(page); /* rmap on tail pages */ pg_data_t *pgdat = page_pgdat(page); struct lruvec *lruvec; /* Untracked pages have no memcg, no lruvec. Update only the node */ - if (!page->mem_cgroup) { + if (!head->mem_cgroup) { __mod_node_page_state(pgdat, idx, val); return; } - lruvec = mem_cgroup_lruvec(page->mem_cgroup, pgdat); + lruvec = mem_cgroup_lruvec(head->mem_cgroup, pgdat); __mod_lruvec_state(lruvec, idx, val); } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index ac6f2b073a5a..e9e22c86a118 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1979,6 +1979,7 @@ void mem_cgroup_print_oom_group(struct mem_cgroup *memcg) */ struct mem_cgroup *lock_page_memcg(struct page *page) { + struct page *head = compound_head(page); /* rmap on tail pages */ struct mem_cgroup *memcg; unsigned long flags; @@ -1998,7 +1999,7 @@ struct mem_cgroup *lock_page_memcg(struct page *page) if (mem_cgroup_disabled()) return NULL; again: - memcg = page->mem_cgroup; + memcg = head->mem_cgroup; if (unlikely(!memcg)) return NULL; @@ -2006,7 +2007,7 @@ struct mem_cgroup *lock_page_memcg(struct page *page) return memcg; spin_lock_irqsave(&memcg->move_lock, flags); - if (memcg != page->mem_cgroup) { + if (memcg != head->mem_cgroup) { spin_unlock_irqrestore(&memcg->move_lock, flags); goto again; } @@ -2049,7 +2050,9 @@ void __unlock_page_memcg(struct mem_cgroup *memcg) */ void unlock_page_memcg(struct page *page) { - __unlock_page_memcg(page->mem_cgroup); + struct page *head = compound_head(page); + + __unlock_page_memcg(head->mem_cgroup); } EXPORT_SYMBOL(unlock_page_memcg); -- 2.26.0