From patchwork Mon Nov 23 16:14:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 11925673 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.6 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable 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 58F66C2D0E4 for ; Mon, 23 Nov 2020 16:14:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 907F82083E for ; Mon, 23 Nov 2020 16:14:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="E73TtGYl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 907F82083E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9BB7B6B00AC; Mon, 23 Nov 2020 11:14:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 990ED6B00AE; Mon, 23 Nov 2020 11:14:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A6F76B00AF; Mon, 23 Nov 2020 11:14:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0131.hostedemail.com [216.40.44.131]) by kanga.kvack.org (Postfix) with ESMTP id 5CAD46B00AC for ; Mon, 23 Nov 2020 11:14:35 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id EF449180AD815 for ; Mon, 23 Nov 2020 16:14:34 +0000 (UTC) X-FDA: 77516180868.09.join25_131077327366 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id D5114180AD801 for ; Mon, 23 Nov 2020 16:14:34 +0000 (UTC) X-HE-Tag: join25_131077327366 X-Filterd-Recvd-Size: 11100 Received: from mail-vk1-f201.google.com (mail-vk1-f201.google.com [209.85.221.201]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Mon, 23 Nov 2020 16:14:33 +0000 (UTC) Received: by mail-vk1-f201.google.com with SMTP id z198so8260184vkd.9 for ; Mon, 23 Nov 2020 08:14:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=BsqWv4H/ufsdI2enRXP/dhtCNxc7q7+QGCOqB9klA0M=; b=E73TtGYlXIPv5BXhSLTiLYKMuw3vS2alfGMoummcGqb7QNatr9be19pVmj9hbD8+Rq YkIW+Kb9l+7OUYfSnxD0V4C0duWbj/2dvNcdMejih4/WS9r6q65zmiwknhkMGO1Yci3t yTdcp1ZkeBs5yBllDCAFXY3i89n0WoRCjtieqkVL3Q7KbeoOe6FHzzA6W/N+7Zq//fu/ SBBDUi8Qtf/Ii4I75Rbys83TfdTD53pZxu0+TUqBHcx3at2gEj+j8G1DWYPbhn6lWRfC LDGmGo8oC7Ob8+5d0jrvGcmCdVjRWXioEpt7yGJkeRtSJzTiskjQ+JjBP1v4mRrIWw/F RDKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=BsqWv4H/ufsdI2enRXP/dhtCNxc7q7+QGCOqB9klA0M=; b=UBJsPwPlpQa6y2tsL2vZV3xdA0cM76KszIDn3Y9D0LxOCM0c1dQ2RDz5bf01s4uuQg HX8Uw2I0vc6zx7ToS+uwhVkoocHB3f9wpymYl312CCIN6oT8b76gZ62YYf2xswdQMmcr cu28oaw/JcDHUFcCM7XK9YXeDv4wJdsdGLuOVVxS+myTKfdxMLg5Po3Nv9cvbuslFgwz uOGgJn/PyaUYnY1BZhzgL4nS8KUoqZZGzufDgEVWcV05MNl5zqW8luia4d8XA1KEeiyh A5DatOetGmR/a83XnavJIgiQ11RuiYF7ZEIvKJk9dsd5i/8If7LbJPYosCC9PLL8Pmln 7VMw== X-Gm-Message-State: AOAM530qje/sRzy0XkhCqvcukbXVgKf32CokJ1TZp51JRaQLVeJlIFTf 9Mq407xhjKA7ZgMCAouue/OpkdK5NELAKw== X-Google-Smtp-Source: ABdhPJzPAR0FIGIXZmaPU04YGbCUhzxYAyiHlFXUkog/zks7W5viLRusblL/tIacNEJvmSJh3o9jo72jHNEx0g== X-Received: from shakeelb.svl.corp.google.com ([100.116.77.44]) (user=shakeelb job=sendgmr) by 2002:a67:2085:: with SMTP id g127mr92049vsg.16.1606148073233; Mon, 23 Nov 2020 08:14:33 -0800 (PST) Date: Mon, 23 Nov 2020 08:14:25 -0800 Message-Id: <20201123161425.341314-1-shakeelb@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH v2] mm: memcontrol: account pagetables per node From: Shakeel Butt To: Roman Gushchin , Johannes Weiner , Michal Hocko Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Shakeel Butt 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: For many workloads, pagetable consumption is significant and it makes sense to expose it in the memory.stat for the memory cgroups. However at the moment, the pagetables are accounted per-zone. Converting them to per-node and using the right interface will correctly account for the memory cgroups as well. Signed-off-by: Shakeel Butt Reported-by: kernel test robot Reported-by: kernel test robot --- Changes since v1: - Tried to fix linking errors for m68k and nds32 Documentation/admin-guide/cgroup-v2.rst | 3 +++ arch/m68k/include/asm/mcf_pgalloc.h | 1 + arch/nds32/mm/mm-nds32.c | 7 ++++--- drivers/base/node.c | 2 +- fs/proc/meminfo.c | 2 +- include/linux/mm.h | 11 +++++++---- include/linux/mmzone.h | 2 +- mm/memcontrol.c | 1 + mm/page_alloc.c | 6 +++--- 9 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 515bb13084a0..63521cd36ce5 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1274,6 +1274,9 @@ PAGE_SIZE multiple when read back. kernel_stack Amount of memory allocated to kernel stacks. + pagetables + Amount of memory allocated for page tables. + percpu(npn) Amount of memory used for storing per-cpu kernel data structures. diff --git a/arch/m68k/include/asm/mcf_pgalloc.h b/arch/m68k/include/asm/mcf_pgalloc.h index bc1228e00518..9088812c2174 100644 --- a/arch/m68k/include/asm/mcf_pgalloc.h +++ b/arch/m68k/include/asm/mcf_pgalloc.h @@ -4,6 +4,7 @@ #include #include +#include extern inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) { diff --git a/arch/nds32/mm/mm-nds32.c b/arch/nds32/mm/mm-nds32.c index 55bec50ccc03..d18e59877503 100644 --- a/arch/nds32/mm/mm-nds32.c +++ b/arch/nds32/mm/mm-nds32.c @@ -5,6 +5,7 @@ #define __HAVE_ARCH_PGD_FREE #include +#include #define FIRST_KERNEL_PGD_NR (USER_PTRS_PER_PGD) @@ -34,8 +35,8 @@ pgd_t *pgd_alloc(struct mm_struct *mm) cpu_dcache_wb_range((unsigned long)new_pgd, (unsigned long)new_pgd + PTRS_PER_PGD * sizeof(pgd_t)); - inc_zone_page_state(virt_to_page((unsigned long *)new_pgd), - NR_PAGETABLE); + inc_lruvec_page_state(virt_to_page((unsigned long *)new_pgd), + NR_PAGETABLE); return new_pgd; } @@ -59,7 +60,7 @@ void pgd_free(struct mm_struct *mm, pgd_t * pgd) pte = pmd_page(*pmd); pmd_clear(pmd); - dec_zone_page_state(virt_to_page((unsigned long *)pgd), NR_PAGETABLE); + dec_lruvec_page_state(virt_to_page((unsigned long *)pgd), NR_PAGETABLE); pte_free(mm, pte); mm_dec_nr_ptes(mm); pmd_free(mm, pmd); diff --git a/drivers/base/node.c b/drivers/base/node.c index 6ffa470e2984..04f71c7bc3f8 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -450,7 +450,7 @@ static ssize_t node_read_meminfo(struct device *dev, #ifdef CONFIG_SHADOW_CALL_STACK nid, node_page_state(pgdat, NR_KERNEL_SCS_KB), #endif - nid, K(sum_zone_node_page_state(nid, NR_PAGETABLE)), + nid, K(node_page_state(pgdat, NR_PAGETABLE)), nid, 0UL, nid, K(sum_zone_node_page_state(nid, NR_BOUNCE)), nid, K(node_page_state(pgdat, NR_WRITEBACK_TEMP)), diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index 887a5532e449..d6fc74619625 100644 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c @@ -107,7 +107,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) global_node_page_state(NR_KERNEL_SCS_KB)); #endif show_val_kb(m, "PageTables: ", - global_zone_page_state(NR_PAGETABLE)); + global_node_page_state(NR_PAGETABLE)); show_val_kb(m, "NFS_Unstable: ", 0); show_val_kb(m, "Bounce: ", diff --git a/include/linux/mm.h b/include/linux/mm.h index 7cfc4653dddf..15c8d082e32f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2177,12 +2177,15 @@ static inline void pgtable_init(void) pgtable_cache_init(); } +static void inc_lruvec_page_state(struct page *page, enum node_stat_item idx); +static void dec_lruvec_page_state(struct page *page, enum node_stat_item idx); + static inline bool pgtable_pte_page_ctor(struct page *page) { if (!ptlock_init(page)) return false; __SetPageTable(page); - inc_zone_page_state(page, NR_PAGETABLE); + inc_lruvec_page_state(page, NR_PAGETABLE); return true; } @@ -2190,7 +2193,7 @@ static inline void pgtable_pte_page_dtor(struct page *page) { ptlock_free(page); __ClearPageTable(page); - dec_zone_page_state(page, NR_PAGETABLE); + dec_lruvec_page_state(page, NR_PAGETABLE); } #define pte_offset_map_lock(mm, pmd, address, ptlp) \ @@ -2277,7 +2280,7 @@ static inline bool pgtable_pmd_page_ctor(struct page *page) if (!pmd_ptlock_init(page)) return false; __SetPageTable(page); - inc_zone_page_state(page, NR_PAGETABLE); + inc_lruvec_page_state(page, NR_PAGETABLE); return true; } @@ -2285,7 +2288,7 @@ static inline void pgtable_pmd_page_dtor(struct page *page) { pmd_ptlock_free(page); __ClearPageTable(page); - dec_zone_page_state(page, NR_PAGETABLE); + dec_lruvec_page_state(page, NR_PAGETABLE); } /* diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 8b074e2ba12c..0dead297d1f1 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -151,7 +151,6 @@ enum zone_stat_item { NR_ZONE_UNEVICTABLE, NR_ZONE_WRITE_PENDING, /* Count of dirty, writeback and unstable pages */ NR_MLOCK, /* mlock()ed pages found and moved off LRU */ - NR_PAGETABLE, /* used for pagetables */ /* Second 128 byte cacheline */ NR_BOUNCE, #if IS_ENABLED(CONFIG_ZSMALLOC) @@ -206,6 +205,7 @@ enum node_stat_item { #if IS_ENABLED(CONFIG_SHADOW_CALL_STACK) NR_KERNEL_SCS_KB, /* measured in KiB */ #endif + NR_PAGETABLE, /* used for pagetables */ NR_VM_NODE_STAT_ITEMS }; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 45465c03a8d7..29a558279520 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1501,6 +1501,7 @@ static struct memory_stat memory_stats[] = { { "anon", PAGE_SIZE, NR_ANON_MAPPED }, { "file", PAGE_SIZE, NR_FILE_PAGES }, { "kernel_stack", 1024, NR_KERNEL_STACK_KB }, + { "pagetables", PAGE_SIZE, NR_PAGETABLE }, { "percpu", 1, MEMCG_PERCPU_B }, { "sock", PAGE_SIZE, MEMCG_SOCK }, { "shmem", PAGE_SIZE, NR_SHMEM }, diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 42c32e8a9c5d..074664f1ea23 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5515,7 +5515,7 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) global_node_page_state_pages(NR_SLAB_UNRECLAIMABLE_B), global_node_page_state(NR_FILE_MAPPED), global_node_page_state(NR_SHMEM), - global_zone_page_state(NR_PAGETABLE), + global_node_page_state(NR_PAGETABLE), global_zone_page_state(NR_BOUNCE), global_zone_page_state(NR_FREE_PAGES), free_pcp, @@ -5547,6 +5547,7 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) #ifdef CONFIG_SHADOW_CALL_STACK " shadow_call_stack:%lukB" #endif + " pagetables:%lukB" " all_unreclaimable? %s" "\n", pgdat->node_id, @@ -5572,6 +5573,7 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) #ifdef CONFIG_SHADOW_CALL_STACK node_page_state(pgdat, NR_KERNEL_SCS_KB), #endif + K(node_page_state(pgdat, NR_PAGETABLE)), pgdat->kswapd_failures >= MAX_RECLAIM_RETRIES ? "yes" : "no"); } @@ -5603,7 +5605,6 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) " present:%lukB" " managed:%lukB" " mlocked:%lukB" - " pagetables:%lukB" " bounce:%lukB" " free_pcp:%lukB" " local_pcp:%ukB" @@ -5624,7 +5625,6 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) K(zone->present_pages), K(zone_managed_pages(zone)), K(zone_page_state(zone, NR_MLOCK)), - K(zone_page_state(zone, NR_PAGETABLE)), K(zone_page_state(zone, NR_BOUNCE)), K(free_pcp), K(this_cpu_read(zone->pageset->pcp.count)),