From patchwork Thu May 25 11:58:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13255105 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 2240FC77B7A for ; Thu, 25 May 2023 11:42:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A41656B0075; Thu, 25 May 2023 07:42:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F1EC6B0078; Thu, 25 May 2023 07:42:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B9F56B007B; Thu, 25 May 2023 07:42:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7E76C6B0075 for ; Thu, 25 May 2023 07:42:51 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4E06414048B for ; Thu, 25 May 2023 11:42:51 +0000 (UTC) X-FDA: 80828590542.23.EAE998F Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf04.hostedemail.com (Postfix) with ESMTP id 9D41040004 for ; Thu, 25 May 2023 11:42:46 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685014969; 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=rAawysvRcRH9V45XjmIlfDlL/bTfo0k5PRjGKFeMchA=; b=uJi13erfBq9gm6nMF8hNcZpYgRX5RlxjpHh6jgPgth1orz3kByhF/Hx6kskSefHhO+XDay 9aenbIIn027fF+9UV8L4h9o1hNQ9FTEPDJeQ7mtCJOwGhygbcLgbSTO2NKSJMb3QmJqWjd ECkVqYhjO63C+rPC6zPvr4wTXvvqSjE= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685014969; a=rsa-sha256; cv=none; b=8ambpVEth8chxSdTg5+c4MlH2PPyMj5BFKM2t7g+gVkzdLq/7dIWQaKA7vywnNAsVpDAuH R0GyiU8rxlj4dHALR5mdddpfKMWNFkWV1jJrWVn5ULny1QhFvdsZbkCGRTtxo2WF2naQvv VZlwuplo/poUOhoZDscnaq27XwBz4kA= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QRmPp4gnGzTkn0; Thu, 25 May 2023 19:42:38 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 25 May 2023 19:42:39 +0800 From: Kefeng Wang To: Mike Rapoport , Andrew Morton , CC: , , , , Kefeng Wang Subject: [PATCH -next] memblock: unify memblock dump and debugfs show Date: Thu, 25 May 2023 19:58:56 +0800 Message-ID: <20230525115856.124507-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9D41040004 X-Stat-Signature: sxxqydri9rxbuf4a7jzd79479wtsjj6n X-HE-Tag: 1685014966-570895 X-HE-Meta: U2FsdGVkX19SdxgpVPYAavkyggvwe+XfoQJWTGFDqbqDyDteodXqBAznuLFVCV4uo2DPAeJIIlO39KISMjTKmjeOJRc0i35uvjzXmq/u4TWVDvt86J46/NRYBaaKDjBRJV3gAbe0g1Y9+uX1ZTy0KtjyD/kVBbA5zNIU6lFDiv0jvAdEckUSUquSlcA62fmYLfu1lf8NWNQxf0QRW8pLDtZzjKnZe4s0OCMfWo89azcOhKjGnCRqQVKvNoMVbWqRArLS6EMSxaaIUu3cRt/zjn8rk02Qbw5UM74mFkAyxIRDmC4f1gyiQFxPYY0Q5DqD5xf+1Va6ku+j2UuZinZpWg+YBQziavaiYKJyaOuZ617bI4A3LCsYz+8YjXeLK9Na4Bm99fok5kKlMpvMO2HzcdlM2IEYaDJdRiuGelBA4ncXoyDF0fiUYM7Y04dlIbQEUMnONvkmdMYIKGK85ijB3mEtCVPxHeTbsTdXHAQ+1UE5NkMM36da2/8zR4SruLPgXdpxIFpnbLwdUaTipHKLw5sUL3jn/slAOKVa/SD0eKeS+05o+lE6bN8b57FY69AqKRPTkeYpO4PQpe3PTx4UB6hZSS7KMoAeIUwfad6ZnSFvJ0jAMSghGDk1huVdfZG6m/rzpKghqRAjw6OFC4qPJWDbHEoWBs9l3Zn+sdTgGMatewZBaP3aTioGVMKoMRpgrg0fUobRcswff7BRfDXH3V8yVK3UyGNPA1W16o4RJQCOxDaHa0eAEcXNYewP1dcoHu4jtgjEbenpoWPOYG7bjiz4HP9QlYzvLGiulduQsnnehZnhzg5MTUcBXcyR6TYvRBfuUkZkIk8BSt5m+v0KjPoScWDSmzzbBt5TgSi6EgH59GiMXbkb4AeDMO9ORnHgbT12NqEyHv+a2Z9Oc40KtPwDzfBXZ08BYhPY0gBc4kNHtqdZNhxs1w/Ev3tXnOiMhy61MmB8VeH6mAhyXJl B18wm1Kg +6j5K1b2oYN0XhfyM4nairO6aKJ/LUUVAvrGpus/ghW7ugRzjpESzoS1GnZR11OOnyeC4FD67Tu0cY3e4jDqSp9I290ApBp9PlVJFBxtXtIXiNmHSHBKfTRhEK+tSru990X5kJPRGptHb+w/HievPthOcDQ== 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: There are two interfaces to show the memblock information, memblock_dump_all() and /sys/kernel/debug/memblock/, but the content is displayed separately, let's unify them in case of more different changes over time. Signed-off-by: Kefeng Wang --- include/linux/memblock.h | 1 + mm/memblock.c | 80 ++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index f82ee3fac1cd..d68826e8c97b 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -47,6 +47,7 @@ enum memblock_flags { MEMBLOCK_MIRROR = 0x2, /* mirrored region */ MEMBLOCK_NOMAP = 0x4, /* don't add to kernel direct mapping */ MEMBLOCK_DRIVER_MANAGED = 0x8, /* always detected via a driver */ + MEMBLOCK_MAX_UNKNOWN = 0x10, /* unknow flags */ }; /** diff --git a/mm/memblock.c b/mm/memblock.c index c5c80d9bcea3..890ff9a16b1d 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1899,16 +1899,35 @@ phys_addr_t __init_memblock memblock_get_current_limit(void) return memblock.current_limit; } -static void __init_memblock memblock_dump(struct memblock_type *type) +#define memblock_printf(m, to_dmesg, fmt, args...) \ +({ \ + if (to_dmesg) \ + pr_info(fmt, ##args); \ + else \ + seq_printf(m, fmt, ##args); \ +}) + +static const char * const flagname[] __initdata_memblock = { + [ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG", + [ilog2(MEMBLOCK_MIRROR)] = "MIRROR", + [ilog2(MEMBLOCK_NOMAP)] = "NOMAP", + [ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG", + [ilog2(MEMBLOCK_MAX_UNKNOWN)] = "UNKNOWN", +}; + +static void __init_memblock memblock_dump(struct memblock_type *type, + struct seq_file *m, bool to_dmesg) { + unsigned count = ARRAY_SIZE(flagname); phys_addr_t base, end, size; enum memblock_flags flags; - int idx; struct memblock_region *rgn; + int idx, i; - pr_info(" %s.cnt = 0x%lx\n", type->name, type->cnt); + memblock_printf(m, to_dmesg, " %s.cnt = 0x%lx\n", type->name, type->cnt); for_each_memblock_type(idx, type, rgn) { + const char *fp = "NONE"; char nid_buf[32] = ""; base = rgn->base; @@ -1920,8 +1939,19 @@ static void __init_memblock memblock_dump(struct memblock_type *type) snprintf(nid_buf, sizeof(nid_buf), " on node %d", memblock_get_region_node(rgn)); #endif - pr_info(" %s[%#x]\t[%pa-%pa], %pa bytes%s flags: %#x\n", - type->name, idx, &base, &end, &size, nid_buf, flags); + if (flags) { + fp = flagname[count]; + + for (i = 0; i < count; i++) { + if (flags & (1U << i)) { + fp = flagname[i]; + break; + } + } + } + + memblock_printf(m, to_dmesg, " %s[%#x]\t[%pa-%pa], %pa bytes%s flags: %s\n", + type->name, idx, &base, &end, &size, nid_buf, fp); } } @@ -1932,10 +1962,10 @@ static void __init_memblock __memblock_dump_all(void) &memblock.memory.total_size, &memblock.reserved.total_size); - memblock_dump(&memblock.memory); - memblock_dump(&memblock.reserved); + memblock_dump(&memblock.memory, NULL, true); + memblock_dump(&memblock.reserved, NULL, true); #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP - memblock_dump(&physmem); + memblock_dump(&physmem, NULL, true); #endif } @@ -2158,41 +2188,13 @@ void __init memblock_free_all(void) } #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_ARCH_KEEP_MEMBLOCK) -static const char * const flagname[] = { - [ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG", - [ilog2(MEMBLOCK_MIRROR)] = "MIRROR", - [ilog2(MEMBLOCK_NOMAP)] = "NOMAP", - [ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG", -}; static int memblock_debug_show(struct seq_file *m, void *private) { struct memblock_type *type = m->private; - struct memblock_region *reg; - int i, j; - unsigned int count = ARRAY_SIZE(flagname); - phys_addr_t end; - - for (i = 0; i < type->cnt; i++) { - reg = &type->regions[i]; - end = reg->base + reg->size - 1; - - seq_printf(m, "%4d: ", i); - seq_printf(m, "%pa..%pa ", ®->base, &end); - seq_printf(m, "%4d ", memblock_get_region_node(reg)); - if (reg->flags) { - for (j = 0; j < count; j++) { - if (reg->flags & (1U << j)) { - seq_printf(m, "%s\n", flagname[j]); - break; - } - } - if (j == count) - seq_printf(m, "%s\n", "UNKNOWN"); - } else { - seq_printf(m, "%s\n", "NONE"); - } - } + + memblock_dump(type, m, false); + return 0; } DEFINE_SHOW_ATTRIBUTE(memblock_debug);