From patchwork Mon Aug 22 02:33:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 12950113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8119CC3F6B0 for ; Mon, 22 Aug 2022 01:58:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE292940008; Sun, 21 Aug 2022 21:58:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B6B73940007; Sun, 21 Aug 2022 21:58:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E425940008; Sun, 21 Aug 2022 21:58:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 89089940007 for ; Sun, 21 Aug 2022 21:58:32 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 607D01A1055 for ; Mon, 22 Aug 2022 01:58:32 +0000 (UTC) X-FDA: 79825569264.10.0C39C5D Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf10.hostedemail.com (Postfix) with ESMTP id 0DB7EC0082 for ; Mon, 22 Aug 2022 01:58:30 +0000 (UTC) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4M9wRS4VxnzlVpZ; Mon, 22 Aug 2022 09:55:16 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 22 Aug 2022 09:58:27 +0800 Received: from huawei.com (10.175.113.32) by dggpemm100009.china.huawei.com (7.185.36.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 22 Aug 2022 09:58:26 +0800 From: Liu Shixin To: Andrew Morton , Greg Kroah-Hartman , huang ying , Aaron Lu , Dave Hansen , "Michal Hocko" , Jesper Dangaard Brouer , Vlastimil Babka , Kemi Wang , "Kefeng Wang" CC: , , Liu Shixin Subject: [PATCH -next] mm, proc: collect percpu free pages into the free pages Date: Mon, 22 Aug 2022 10:33:11 +0800 Message-ID: <20220822023311.909316-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661133512; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=xk4jwl06Knf1J6KHI9dUdFdJo1mgs7e3fd4gg/P/GHM=; b=5fWjY8eyes8/JUf0ZrNLEBHqixGS+Lzm8f7Ujld7prdE6UvbMNRii+vnyRmDeFPt7f8kHR 01HWNjY57sYapje1OeTpO8Db+IpGOhdZlbkEmCeP+EbzDLu0Bn73KuLVQNti1uyumd7fXD QDSfjrCioqiuu7kWKYJZDjXcLHb1vrY= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf10.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661133512; a=rsa-sha256; cv=none; b=HxQz/gv9n2l+PZsLm8uvh1C/2K0POQtDNke6j4f8yJMnJODmoBk5ae3dlIevg5E8EobpXf /xc6pg2eVDO5/DIhmbQW3E8z9zeuL92+IbEbqHVK/rG3a7uma+VaqgapqhAUdJhDWbrCC2 rCVrZcQzX/qtduPO+/NX9ix4w+heJ9Y= X-Rspamd-Queue-Id: 0DB7EC0082 X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf10.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com X-Rspamd-Server: rspam04 X-Stat-Signature: zrwzchxj64475p4p8r34j1wi1o7d13hg X-HE-Tag: 1661133510-968599 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 page on pcplist could be used, but not counted into memory free or avaliable, and pcp_free is only showed by show_mem() for now. Since commit d8a759b57035 ("mm, page_alloc: double zone's batchsize"), there is a significant decrease in the display of free memory, with a large number of cpus and zones, the number of pages in the percpu list can be very large, so it is better to let user to know the pcp count. On a machine with 3 zones and 72 CPUs. Before commit d8a759b57035, the maximum amount of pages in the pcp lists was theoretically 162MB(3*72*768KB). After the patch, the lists can hold 324MB. It has been observed to be 114MB in the idle state after system startup in practice(increased 80 MB). Signed-off-by: Liu Shixin --- mm/page_alloc.c | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 033f1e26d15b..f8b46ac2c2a0 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5853,6 +5853,26 @@ static unsigned long nr_free_zone_pages(int offset) return sum; } +static unsigned long nr_free_zone_pcplist_pages(struct zone *zone) +{ + unsigned long sum = 0; + int cpu; + + for_each_online_cpu(cpu) + sum += per_cpu_ptr(zone->per_cpu_pageset, cpu)->count; + return sum; +} + +static unsigned long nr_free_pcplist_pages(void) +{ + unsigned long sum = 0; + struct zone *zone; + + for_each_zone(zone) + sum += nr_free_zone_pcplist_pages(zone); + return sum; +} + /** * nr_free_buffer_pages - count number of pages beyond high watermark * @@ -5894,7 +5914,8 @@ long si_mem_available(void) * Estimate the amount of memory available for userspace allocations, * without causing swapping or OOM. */ - available = global_zone_page_state(NR_FREE_PAGES) - totalreserve_pages; + available = global_zone_page_state(NR_FREE_PAGES) + + nr_free_pcplist_pages() - totalreserve_pages; /* * Not all the page cache can be freed, otherwise the system will @@ -5924,7 +5945,8 @@ void si_meminfo(struct sysinfo *val) { val->totalram = totalram_pages(); val->sharedram = global_node_page_state(NR_SHMEM); - val->freeram = global_zone_page_state(NR_FREE_PAGES); + val->freeram = global_zone_page_state(NR_FREE_PAGES) + + nr_free_pcplist_pages(); val->bufferram = nr_blockdev_pages(); val->totalhigh = totalhigh_pages(); val->freehigh = nr_free_highpages(); @@ -5938,30 +5960,28 @@ void si_meminfo_node(struct sysinfo *val, int nid) { int zone_type; /* needs to be signed */ unsigned long managed_pages = 0; + unsigned long free_pages = sum_zone_node_page_state(nid, NR_FREE_PAGES); unsigned long managed_highpages = 0; unsigned long free_highpages = 0; pg_data_t *pgdat = NODE_DATA(nid); - for (zone_type = 0; zone_type < MAX_NR_ZONES; zone_type++) - managed_pages += zone_managed_pages(&pgdat->node_zones[zone_type]); - val->totalram = managed_pages; - val->sharedram = node_page_state(pgdat, NR_SHMEM); - val->freeram = sum_zone_node_page_state(nid, NR_FREE_PAGES); -#ifdef CONFIG_HIGHMEM for (zone_type = 0; zone_type < MAX_NR_ZONES; zone_type++) { struct zone *zone = &pgdat->node_zones[zone_type]; + managed_pages += zone_managed_pages(zone); + free_pages += nr_free_zone_pcplist_pages(zone); +#ifdef CONFIG_HIGHMEM if (is_highmem(zone)) { managed_highpages += zone_managed_pages(zone); free_highpages += zone_page_state(zone, NR_FREE_PAGES); } +#endif } + val->totalram = managed_pages; + val->sharedram = node_page_state(pgdat, NR_SHMEM); + val->freeram = free_pages; val->totalhigh = managed_highpages; val->freehigh = free_highpages; -#else - val->totalhigh = managed_highpages; - val->freehigh = free_highpages; -#endif val->mem_unit = PAGE_SIZE; } #endif @@ -6035,8 +6055,7 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) if (show_mem_node_skip(filter, zone_to_nid(zone), nodemask)) continue; - for_each_online_cpu(cpu) - free_pcp += per_cpu_ptr(zone->per_cpu_pageset, cpu)->count; + free_pcp += nr_free_zone_pcplist_pages(zone); } printk("active_anon:%lu inactive_anon:%lu isolated_anon:%lu\n"