From patchwork Fri May 26 12:05:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13256825 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 9158EC7EE23 for ; Fri, 26 May 2023 11:49:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 11D96900004; Fri, 26 May 2023 07:49:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CE5A900002; Fri, 26 May 2023 07:49:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2715900004; Fri, 26 May 2023 07:49:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E1B63900002 for ; Fri, 26 May 2023 07:49:03 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A877FAE9AC for ; Fri, 26 May 2023 11:49:03 +0000 (UTC) X-FDA: 80832234966.12.1344F4F Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf10.hostedemail.com (Postfix) with ESMTP id 88188C0017 for ; Fri, 26 May 2023 11:49:00 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf10.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=1685101741; 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=ZIDFqaeOyP4BCIJdTt7TUPLqmi1YqcfyYC5K6usJDLQ=; b=Wj9BbNvVOmFvwacquvARPJ1aphtBXWVKxnCybUo75dWqtrDiBrL+yVLUzCiYatA0CTavKZ 1+I01JqfCjm6QsAUL1/yZsE1VGeK+0XhtrViHNb1bcRoMW7yGSetIfRA4xMlntYTbB0B89 LybwS5K3NQ0Y5BWbw0ORrcyQWMcPSCg= 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 wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685101741; a=rsa-sha256; cv=none; b=4pfBUbd5lGcYmb8rG9h63vZgCaN9PrId/g85EXF+0CP4Vs8nh21URLatbqysBPFs4QXjOf jGT9hraAHuxRlnjHO4pWYvrPXqeLWtURpID770Dc3aW9W3Me5b8mehjaz11+9noyK2NCWi GWGQ+noz4lYFFj64Uug4LwTIMpUBeIc= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QSNS52ZJlzsR59; Fri, 26 May 2023 19:46:45 +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; Fri, 26 May 2023 19:48:54 +0800 From: Kefeng Wang To: Mike Rapoport , Andrew Morton , CC: , , , , Kefeng Wang Subject: [PATCH -next v2] memblock: unify memblock dump and debugfs show Date: Fri, 26 May 2023 20:05:05 +0800 Message-ID: <20230526120505.123693-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: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 88188C0017 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: b3y1f1gc99w3mfqpf1mom9hw98gygsdu X-HE-Tag: 1685101740-285286 X-HE-Meta: U2FsdGVkX19/J1ypXeikHH1quGRD/cY7aRFo++fek/qu414b9/G8Km3ioHXfmdzUGye4VArCma7yvo05y+XZNQDGsoyuAfqjv+RvE97/RkyGY+MqYizLciO428NG7TShOlq8RInJz/52YJADoULK3lkJO2WmsbVmbs/Zju7heZrwm4DRukCLyfFMBe2renjki90Jru3dvm6Xvctxi/UxgIVj4DBNbLg2NVYiDIVsBeW5XuINC+biIiS+N2yYr6ffQD9Xq0YEZucNp7dHC9G6IEs/AwEj/dJGaJdspOKabljUxfOnqS7+HA/Ia7L7qY3jESy0t+PiUT1CYUSPzRFv2vvwQpKADmfIdmEXbeqW4p482zZhZmytEQ21u/ruwAuuXk+a98bdUUxe1hIYlJdCBCq1b4thI4oxh/BJ4opJfdVwGUJZaCSkr87TqBO1YUSYccKTvytzhLfWDSAIg9N20KplnX35lasF4Uv+mEn9myUY3dG5ArgEsOEw874IDpTXMFe30/2uUG2PFG/VJBPqN4FiHDc5xNAoni5vZYxUlSngSJcjk0Y0RSlY0XmyXmTLSc1etSEPGW+d9rjAhtw6tTHjDulvZn4ZIy797fE/Du53QfQ8naUmzuyfA5lY+sn+T2ZIsL2G7JY2JBQPFF4aKE8uchmx9YddSleR4eOLQosXyFlKWfAQY9la8RxH1/P2BpdwXKZT7ZEiyBY/c59/vTgPWEtf/wg54I1PQn6HCbQ65k5DOntQ+mJ2GNrR28MSxXstPgHtk2HwMA8ajyXkYm0hazLwoFjXUqdMghJJaGHRHEqAE7XrZm4VInsOcNtqb+lH13PDHRFnLxsN0JooZJvsfHiAdp9AfAXe5J16xFimYaXhYSfyRhrSK/bgahghDw9IiY7oVw27mV60kdaxcvl+uBFhIm9Yrw3SjPz3+Zn02u2ga6CM1CZ2Dk5tjwA+F8dKBNS936XCjawLZdL xoyGW5ZW h/atT+RGkuazxKQK6/z1EkR39O/4B4K/aCworwq4XjMAaCbHeb5vwQ59tpiEgSe8MsqeVdfuqGxLaTovhnJFEJJPdBZxuCrOYPwVD+Oue6PZK16TdIbdHcZPFZPseE3J5RJWsXj+YiM/c23+lAZAW5oPT0w== 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 --- v2: - fix wrong count since we add MEMBLOCK_MAX_UNKNOWN - drop __initdata_memblock for flagname 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..04eb7c665026 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[] = { + [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) - 1; 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);