Message ID | 20230518091431.299-1-ssawgyw@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp351972vqo; Thu, 18 May 2023 02:19:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5qdrVGdWzkfyRK9VZUIRbJ6nSoABr1V8EEFTK8+nr5fCuPRxr9S4UyYig69zUbb8cOZwbP X-Received: by 2002:a05:6a20:9d94:b0:101:5171:c880 with SMTP id mu20-20020a056a209d9400b001015171c880mr1124520pzb.62.1684401562624; Thu, 18 May 2023 02:19:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684401562; cv=none; d=google.com; s=arc-20160816; b=rB9zWnf8iNljSJNpAUBLOvNgQoc1elG8q6aCvvjQMCDnjOqV+3YXGBXPGwZEDIDtJ/ mZ2JbSKX+khHqmqpU8pvAZFU4Z+BgU5nKJlAa4xA0dy5Hwr99pSQD5DJMAEEjkH0JrhD wR4WUxtAO1qBjEh2E6oIEv6yN2EkI5q8u763pKahepHx5T6WEHiG7wq0xePFeAtCHwLv AUjy7W1KgzKbfnp3Ve+79A79j5hrBv0xNlfXopsldGh9SGNMTH32b4gqkzEuVCihl8dM 0DwM37tJJ89XM0vQ7JeXHLh/JlLwhEKEG6Zct7nnpdi4pgLkM9+5vzD+FU7Ni7n4HG7P cAyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=AEruk6lgv2UDdUrR3IRiS7raiUqRukdhzsBT0y7QWd8=; b=VzA4eYTQVXR3UVNBVLEuL7r64qL3xDNK038SyJ+z8RUDkrGDz9gbzJUa4lT82GvC2a uDWnBOLNcYfh4GHLHQGwg9HpLzfxkjzJo5S3j7j761ZphF6lY+1IdqgD0jbacT2pX83J aN6J7Id3wdvUF+c+KOnQZNznncRRODxuo+/CJWg/h/9MEzhaCHokxowAR2tmmZSxu0sf 4UsZTi8byl7mqSBJN1y45i7x6YAmpLXN5DaVWsMFJkCVe2f07NQ0TIp0i2uu2hd5Q1yQ Sn5wBaqfjc7NX+oGQVhziPxIIVpSafTw/bGWZXbsoY+5KZWbqge8HF35VnlAjywpPrtZ 2lGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ncwIvPQ3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h28-20020a63385c000000b0052c8999715dsi954475pgn.478.2023.05.18.02.19.05; Thu, 18 May 2023 02:19:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ncwIvPQ3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230101AbjERJPD (ORCPT <rfc822;abdi.embedded@gmail.com> + 99 others); Thu, 18 May 2023 05:15:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229985AbjERJPB (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 18 May 2023 05:15:01 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF0F81FDC for <linux-kernel@vger.kernel.org>; Thu, 18 May 2023 02:15:00 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1ae454844edso13732955ad.1 for <linux-kernel@vger.kernel.org>; Thu, 18 May 2023 02:15:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684401300; x=1686993300; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AEruk6lgv2UDdUrR3IRiS7raiUqRukdhzsBT0y7QWd8=; b=ncwIvPQ3tpE5ajVR5XQ9ZcmF3F9Lx43OHj/zr3p2G6dINoM6/uTDxjVkP3ILiSxU3s m5kzXXYADsCz5VHt+Z0yAi/YqcTYSC7gHPof3iAv8cwJCEcHtxo+w90JmhmvxjFY+W80 7RXmwGKpYjyCodNhLI4k6IsugXMbIrX9+iP9V4+sggfWyjPHclN3cT46Lkm69qI9F2Ry l3tAHFHXJ/k4hHqcv8+YzkpFuiddRQFlikw11Jlg1wJQ6Wrvlq6PdRDnOiDBgqYLlVvn 6rkChuhF85AgL3WgKUgnQT/Cn87I7mY0bHgeR6WqLnQm6n/CT7/X96L0yi3qQausmjV9 3ijw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684401300; x=1686993300; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AEruk6lgv2UDdUrR3IRiS7raiUqRukdhzsBT0y7QWd8=; b=g8/ajyCTSTtc2RbjXDNxl016GsENgjEPP9SyNs4oixZee3CBbR+OhJnRgWbVf+nlrz 320fiB3jwTx0ZCqcEXskbvBPZo3yoc32OY5RgAON4a6JWtMNE8mVbx0v2M2FqV2gZ0Tp exAgSzWklojqtLzNZSC7rgNafVVt4B5j6KIb9RwQb7MRgC4GZOG7o+7XfoL1m/G7XUTn SHHDN70FDAyqSf+6CXPpCwkrNmJId9l/Rl2/1MmSHlgLAuC/dIIHOUIJUKs2J+KYIzm3 Z/Ev32T9lehcmXf/qkS3ZUIxrLT+jDx+jsow56kArO9dTksdqztXqUTTn0SMz/fmcpa3 8Fww== X-Gm-Message-State: AC+VfDz7Gwtt8bP3a8u663gjIszI+7yToFN7VIXr5b1Zg0Z8b5bn0xlu azPpKIwPgmLpAsnbmULkEWsP2V2vkf4= X-Received: by 2002:a17:902:ced1:b0:1ad:e099:fbf9 with SMTP id d17-20020a170902ced100b001ade099fbf9mr1805522plg.42.1684401300135; Thu, 18 May 2023 02:15:00 -0700 (PDT) Received: from localhost.localdomain ([45.43.34.98]) by smtp.gmail.com with ESMTPSA id 12-20020a170902c14c00b001ae4c498d29sm862165plj.265.2023.05.18.02.14.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 02:14:59 -0700 (PDT) From: Yuwei Guan <ssawgyw@gmail.com> To: rppt@kernel.org, akpm@linux-foundation.org, tsahu@linux.ibm.com, anshuman.khandual@arm.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yuwei Guan <ssawgyw@gmail.com> Subject: [PATCH v3] memblock: Add flags and nid info in memblock debugfs Date: Thu, 18 May 2023 17:14:31 +0800 Message-Id: <20230518091431.299-1-ssawgyw@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766016128955465142?= X-GMAIL-MSGID: =?utf-8?q?1766223052893037741?= |
Series |
[v3] memblock: Add flags and nid info in memblock debugfs
|
|
Commit Message
Yuwei Guan
May 18, 2023, 9:14 a.m. UTC
Currently, the memblock debugfs can display the count of memblock_type and
the base and end of the reg. However, when memblock_mark_*() or
memblock_set_node() is executed on some range, the information in the
existing debugfs cannot make it clear why the address is not consecutive.
For example,
cat /sys/kernel/debug/memblock/memory
0: 0x0000000080000000..0x00000000901fffff
1: 0x0000000090200000..0x00000000905fffff
2: 0x0000000090600000..0x0000000092ffffff
3: 0x0000000093000000..0x00000000973fffff
4: 0x0000000097400000..0x00000000b71fffff
5: 0x00000000c0000000..0x00000000dfffffff
6: 0x00000000e2500000..0x00000000f87fffff
7: 0x00000000f8800000..0x00000000fa7fffff
8: 0x00000000fa800000..0x00000000fd3effff
9: 0x00000000fd3f0000..0x00000000fd3fefff
10: 0x00000000fd3ff000..0x00000000fd7fffff
11: 0x00000000fd800000..0x00000000fd901fff
12: 0x00000000fd902000..0x00000000fd909fff
13: 0x00000000fd90a000..0x00000000fd90bfff
14: 0x00000000fd90c000..0x00000000ffffffff
15: 0x0000000880000000..0x0000000affffffff
So we can add flags and nid to this debugfs.
For example,
cat /sys/kernel/debug/memblock/memory
0: 0x0000000080000000..0x00000000901fffff NONE 0
1: 0x0000000090200000..0x00000000905fffff NOMAP 0
2: 0x0000000090600000..0x0000000092ffffff NONE 0
3: 0x0000000093000000..0x00000000973fffff NOMAP 0
4: 0x0000000097400000..0x00000000b71fffff NONE 0
5: 0x00000000c0000000..0x00000000dfffffff NONE 0
6: 0x00000000e2500000..0x00000000f87fffff NONE 0
7: 0x00000000f8800000..0x00000000fa7fffff NOMAP 0
8: 0x00000000fa800000..0x00000000fd3effff NONE 0
9: 0x00000000fd3f0000..0x00000000fd3fefff NOMAP 0
10: 0x00000000fd3ff000..0x00000000fd7fffff NONE 0
11: 0x00000000fd800000..0x00000000fd901fff NOMAP 0
12: 0x00000000fd902000..0x00000000fd909fff NONE 0
13: 0x00000000fd90a000..0x00000000fd90bfff NOMAP 0
14: 0x00000000fd90c000..0x00000000ffffffff NONE 0
15: 0x0000000880000000..0x0000000affffffff NONE 0
Signed-off-by: Yuwei Guan <ssawgyw@gmail.com>
---
v3:
- show string value for each memblock flag
---
mm/memblock.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
Comments
On 5/18/23 14:44, Yuwei Guan wrote: > Currently, the memblock debugfs can display the count of memblock_type and > the base and end of the reg. However, when memblock_mark_*() or > memblock_set_node() is executed on some range, the information in the > existing debugfs cannot make it clear why the address is not consecutive. > > For example, > cat /sys/kernel/debug/memblock/memory > 0: 0x0000000080000000..0x00000000901fffff > 1: 0x0000000090200000..0x00000000905fffff > 2: 0x0000000090600000..0x0000000092ffffff > 3: 0x0000000093000000..0x00000000973fffff > 4: 0x0000000097400000..0x00000000b71fffff > 5: 0x00000000c0000000..0x00000000dfffffff > 6: 0x00000000e2500000..0x00000000f87fffff > 7: 0x00000000f8800000..0x00000000fa7fffff > 8: 0x00000000fa800000..0x00000000fd3effff > 9: 0x00000000fd3f0000..0x00000000fd3fefff > 10: 0x00000000fd3ff000..0x00000000fd7fffff > 11: 0x00000000fd800000..0x00000000fd901fff > 12: 0x00000000fd902000..0x00000000fd909fff > 13: 0x00000000fd90a000..0x00000000fd90bfff > 14: 0x00000000fd90c000..0x00000000ffffffff > 15: 0x0000000880000000..0x0000000affffffff > > So we can add flags and nid to this debugfs. > > For example, > cat /sys/kernel/debug/memblock/memory > 0: 0x0000000080000000..0x00000000901fffff NONE 0 > 1: 0x0000000090200000..0x00000000905fffff NOMAP 0 > 2: 0x0000000090600000..0x0000000092ffffff NONE 0 > 3: 0x0000000093000000..0x00000000973fffff NOMAP 0 > 4: 0x0000000097400000..0x00000000b71fffff NONE 0 > 5: 0x00000000c0000000..0x00000000dfffffff NONE 0 > 6: 0x00000000e2500000..0x00000000f87fffff NONE 0 > 7: 0x00000000f8800000..0x00000000fa7fffff NOMAP 0 > 8: 0x00000000fa800000..0x00000000fd3effff NONE 0 > 9: 0x00000000fd3f0000..0x00000000fd3fefff NOMAP 0 > 10: 0x00000000fd3ff000..0x00000000fd7fffff NONE 0 > 11: 0x00000000fd800000..0x00000000fd901fff NOMAP 0 > 12: 0x00000000fd902000..0x00000000fd909fff NONE 0 > 13: 0x00000000fd90a000..0x00000000fd90bfff NOMAP 0 > 14: 0x00000000fd90c000..0x00000000ffffffff NONE 0 > 15: 0x0000000880000000..0x0000000affffffff NONE 0 Although, Mike had suggested to keep these flags print last, above format looks good as well. > > Signed-off-by: Yuwei Guan <ssawgyw@gmail.com> > --- > v3: > - show string value for each memblock flag > --- > mm/memblock.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/mm/memblock.c b/mm/memblock.c > index 511d4783dcf1..5fba53f98b2d 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -2143,13 +2143,23 @@ static int memblock_debug_show(struct seq_file *m, void *private) > struct memblock_region *reg; > int i; > phys_addr_t end; > + static const char flagname[BITS_PER_LONG][8] = { > + [0 ... (BITS_PER_LONG-1)] = "?", Minor nit - Although checkpatch does not complain, should there be spaces between the operator and operands e.g (BITS_PER_LONG - 1). > + > + [ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG", > + [ilog2(MEMBLOCK_MIRROR)] = "MIRROR", > + [ilog2(MEMBLOCK_NOMAP)] = "NOMAP", > + [ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG", > + }; Also, BITS_PER_LONG sized array is really required here ? as there are just four available memblock flags. > > 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\n", ®->base, &end); > + seq_printf(m, "%pa..%pa ", ®->base, &end); > + seq_printf(m, "%8s ", reg->flags ? flagname[ilog2(reg->flags)] : "NONE"); > + seq_printf(m, "%4d\n", memblock_get_region_node(reg)); > } > return 0; > }
Anshuman Khandual <anshuman.khandual@arm.com> 于2023年5月18日周四 18:12写道: > > > > On 5/18/23 14:44, Yuwei Guan wrote: > > Currently, the memblock debugfs can display the count of memblock_type and > > the base and end of the reg. However, when memblock_mark_*() or > > memblock_set_node() is executed on some range, the information in the > > existing debugfs cannot make it clear why the address is not consecutive. > > > > For example, > > cat /sys/kernel/debug/memblock/memory > > 0: 0x0000000080000000..0x00000000901fffff > > 1: 0x0000000090200000..0x00000000905fffff > > 2: 0x0000000090600000..0x0000000092ffffff > > 3: 0x0000000093000000..0x00000000973fffff > > 4: 0x0000000097400000..0x00000000b71fffff > > 5: 0x00000000c0000000..0x00000000dfffffff > > 6: 0x00000000e2500000..0x00000000f87fffff > > 7: 0x00000000f8800000..0x00000000fa7fffff > > 8: 0x00000000fa800000..0x00000000fd3effff > > 9: 0x00000000fd3f0000..0x00000000fd3fefff > > 10: 0x00000000fd3ff000..0x00000000fd7fffff > > 11: 0x00000000fd800000..0x00000000fd901fff > > 12: 0x00000000fd902000..0x00000000fd909fff > > 13: 0x00000000fd90a000..0x00000000fd90bfff > > 14: 0x00000000fd90c000..0x00000000ffffffff > > 15: 0x0000000880000000..0x0000000affffffff > > > > So we can add flags and nid to this debugfs. > > > > For example, > > cat /sys/kernel/debug/memblock/memory > > 0: 0x0000000080000000..0x00000000901fffff NONE 0 > > 1: 0x0000000090200000..0x00000000905fffff NOMAP 0 > > 2: 0x0000000090600000..0x0000000092ffffff NONE 0 > > 3: 0x0000000093000000..0x00000000973fffff NOMAP 0 > > 4: 0x0000000097400000..0x00000000b71fffff NONE 0 > > 5: 0x00000000c0000000..0x00000000dfffffff NONE 0 > > 6: 0x00000000e2500000..0x00000000f87fffff NONE 0 > > 7: 0x00000000f8800000..0x00000000fa7fffff NOMAP 0 > > 8: 0x00000000fa800000..0x00000000fd3effff NONE 0 > > 9: 0x00000000fd3f0000..0x00000000fd3fefff NOMAP 0 > > 10: 0x00000000fd3ff000..0x00000000fd7fffff NONE 0 > > 11: 0x00000000fd800000..0x00000000fd901fff NOMAP 0 > > 12: 0x00000000fd902000..0x00000000fd909fff NONE 0 > > 13: 0x00000000fd90a000..0x00000000fd90bfff NOMAP 0 > > 14: 0x00000000fd90c000..0x00000000ffffffff NONE 0 > > 15: 0x0000000880000000..0x0000000affffffff NONE 0 > > Although, Mike had suggested to keep these flags print last, above > format looks good as well. > > > > > Signed-off-by: Yuwei Guan <ssawgyw@gmail.com> > > --- > > v3: > > - show string value for each memblock flag > > --- > > mm/memblock.c | 12 +++++++++++- > > 1 file changed, 11 insertions(+), 1 deletion(-) > > > > diff --git a/mm/memblock.c b/mm/memblock.c > > index 511d4783dcf1..5fba53f98b2d 100644 > > --- a/mm/memblock.c > > +++ b/mm/memblock.c > > @@ -2143,13 +2143,23 @@ static int memblock_debug_show(struct seq_file *m, void *private) > > struct memblock_region *reg; > > int i; > > phys_addr_t end; > > + static const char flagname[BITS_PER_LONG][8] = { > > + [0 ... (BITS_PER_LONG-1)] = "?", > > Minor nit - > > Although checkpatch does not complain, should there be spaces between > the operator and operands e.g (BITS_PER_LONG - 1). > > > + > > + [ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG", > > + [ilog2(MEMBLOCK_MIRROR)] = "MIRROR", > > + [ilog2(MEMBLOCK_NOMAP)] = "NOMAP", > > + [ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG", > > + }; > > Also, BITS_PER_LONG sized array is really required here ? as there are > just four available memblock flags. > Hi Anshuman, The main reason to use BITS_PER_LONG is to reserve. If the flagname buffer is (ilog2(MEMBLOCK_DRIVER_MANAGED) + 1), memblock_flags adds a new attribute and does not add its name in debugfs, it will cause an overflow. But BITS_PER_LONG is too wasteful, so I implement a new solution. Please help to check it. struct memblock_type *type = m->private; struct memblock_region *reg; - int i; + int i, j; phys_addr_t end; + static const char *flagname[] = { + [ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG", + [ilog2(MEMBLOCK_MIRROR)] = "MIRROR", + [ilog2(MEMBLOCK_NOMAP)] = "NOMAP", + [ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG", + }; 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\n", ®->base, &end); + seq_printf(m, "%pa..%pa ", ®->base, &end); + seq_printf(m, "%4d ", memblock_get_region_node(reg)); + if (reg->flags) { + for (j = 0; j < ARRAY_SIZE(flagname); j++) { + if (reg->flags & (1U << j)) { + seq_printf(m, "%s\n", flagname[j]); + break; + } + } + if (j == ARRAY_SIZE(flagname)) + seq_printf(m, "%s\n", "UNKNOWN"); + } else { + seq_printf(m, "%s\n", "NONE"); + } } > > > > 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\n", ®->base, &end); > > + seq_printf(m, "%pa..%pa ", ®->base, &end); > > + seq_printf(m, "%8s ", reg->flags ? flagname[ilog2(reg->flags)] : "NONE"); > > + seq_printf(m, "%4d\n", memblock_get_region_node(reg)); > > } > > return 0; > > }
On 5/18/23 19:35, Yuwei Guan wrote: > Anshuman Khandual <anshuman.khandual@arm.com> 于2023年5月18日周四 18:12写道: >> >> >> >> On 5/18/23 14:44, Yuwei Guan wrote: >>> Currently, the memblock debugfs can display the count of memblock_type and >>> the base and end of the reg. However, when memblock_mark_*() or >>> memblock_set_node() is executed on some range, the information in the >>> existing debugfs cannot make it clear why the address is not consecutive. >>> >>> For example, >>> cat /sys/kernel/debug/memblock/memory >>> 0: 0x0000000080000000..0x00000000901fffff >>> 1: 0x0000000090200000..0x00000000905fffff >>> 2: 0x0000000090600000..0x0000000092ffffff >>> 3: 0x0000000093000000..0x00000000973fffff >>> 4: 0x0000000097400000..0x00000000b71fffff >>> 5: 0x00000000c0000000..0x00000000dfffffff >>> 6: 0x00000000e2500000..0x00000000f87fffff >>> 7: 0x00000000f8800000..0x00000000fa7fffff >>> 8: 0x00000000fa800000..0x00000000fd3effff >>> 9: 0x00000000fd3f0000..0x00000000fd3fefff >>> 10: 0x00000000fd3ff000..0x00000000fd7fffff >>> 11: 0x00000000fd800000..0x00000000fd901fff >>> 12: 0x00000000fd902000..0x00000000fd909fff >>> 13: 0x00000000fd90a000..0x00000000fd90bfff >>> 14: 0x00000000fd90c000..0x00000000ffffffff >>> 15: 0x0000000880000000..0x0000000affffffff >>> >>> So we can add flags and nid to this debugfs. >>> >>> For example, >>> cat /sys/kernel/debug/memblock/memory >>> 0: 0x0000000080000000..0x00000000901fffff NONE 0 >>> 1: 0x0000000090200000..0x00000000905fffff NOMAP 0 >>> 2: 0x0000000090600000..0x0000000092ffffff NONE 0 >>> 3: 0x0000000093000000..0x00000000973fffff NOMAP 0 >>> 4: 0x0000000097400000..0x00000000b71fffff NONE 0 >>> 5: 0x00000000c0000000..0x00000000dfffffff NONE 0 >>> 6: 0x00000000e2500000..0x00000000f87fffff NONE 0 >>> 7: 0x00000000f8800000..0x00000000fa7fffff NOMAP 0 >>> 8: 0x00000000fa800000..0x00000000fd3effff NONE 0 >>> 9: 0x00000000fd3f0000..0x00000000fd3fefff NOMAP 0 >>> 10: 0x00000000fd3ff000..0x00000000fd7fffff NONE 0 >>> 11: 0x00000000fd800000..0x00000000fd901fff NOMAP 0 >>> 12: 0x00000000fd902000..0x00000000fd909fff NONE 0 >>> 13: 0x00000000fd90a000..0x00000000fd90bfff NOMAP 0 >>> 14: 0x00000000fd90c000..0x00000000ffffffff NONE 0 >>> 15: 0x0000000880000000..0x0000000affffffff NONE 0 >> >> Although, Mike had suggested to keep these flags print last, above >> format looks good as well. >> >>> >>> Signed-off-by: Yuwei Guan <ssawgyw@gmail.com> >>> --- >>> v3: >>> - show string value for each memblock flag >>> --- >>> mm/memblock.c | 12 +++++++++++- >>> 1 file changed, 11 insertions(+), 1 deletion(-) >>> >>> diff --git a/mm/memblock.c b/mm/memblock.c >>> index 511d4783dcf1..5fba53f98b2d 100644 >>> --- a/mm/memblock.c >>> +++ b/mm/memblock.c >>> @@ -2143,13 +2143,23 @@ static int memblock_debug_show(struct seq_file *m, void *private) >>> struct memblock_region *reg; >>> int i; >>> phys_addr_t end; >>> + static const char flagname[BITS_PER_LONG][8] = { >>> + [0 ... (BITS_PER_LONG-1)] = "?", >> >> Minor nit - >> >> Although checkpatch does not complain, should there be spaces between >> the operator and operands e.g (BITS_PER_LONG - 1). >> >>> + >>> + [ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG", >>> + [ilog2(MEMBLOCK_MIRROR)] = "MIRROR", >>> + [ilog2(MEMBLOCK_NOMAP)] = "NOMAP", >>> + [ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG", >>> + }; >> >> Also, BITS_PER_LONG sized array is really required here ? as there are >> just four available memblock flags. >> > Hi Anshuman, > The main reason to use BITS_PER_LONG is to reserve. > If the flagname buffer is (ilog2(MEMBLOCK_DRIVER_MANAGED) + 1), > memblock_flags adds a new attribute and does not add its name in debugfs, > it will cause an overflow. Agreed. > But BITS_PER_LONG is too wasteful, so I implement a new solution. > Please help to check it. > > struct memblock_type *type = m->private; > struct memblock_region *reg; > - int i; > + int i, j; > phys_addr_t end; > + static const char *flagname[] = { > + [ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG", > + [ilog2(MEMBLOCK_MIRROR)] = "MIRROR", > + [ilog2(MEMBLOCK_NOMAP)] = "NOMAP", > + [ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG", > + }; > > 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\n", ®->base, &end); > + seq_printf(m, "%pa..%pa ", ®->base, &end); > + seq_printf(m, "%4d ", memblock_get_region_node(reg)); > + if (reg->flags) { > + for (j = 0; j < ARRAY_SIZE(flagname); j++) { > + if (reg->flags & (1U << j)) { > + seq_printf(m, "%s\n", flagname[j]); > + break; > + } > + } > + if (j == ARRAY_SIZE(flagname)) > + seq_printf(m, "%s\n", "UNKNOWN"); > + } else { > + seq_printf(m, "%s\n", "NONE"); > + } > } Please move the static array outside, just before this function and capture ARRAY_SIZE(flagname) in a local variable to make it compact. Rest looks good. >>> >>> 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\n", ®->base, &end); >>> + seq_printf(m, "%pa..%pa ", ®->base, &end); >>> + seq_printf(m, "%8s ", reg->flags ? flagname[ilog2(reg->flags)] : "NONE"); >>> + seq_printf(m, "%4d\n", memblock_get_region_node(reg)); >>> } >>> return 0; >>> }
diff --git a/mm/memblock.c b/mm/memblock.c index 511d4783dcf1..5fba53f98b2d 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2143,13 +2143,23 @@ static int memblock_debug_show(struct seq_file *m, void *private) struct memblock_region *reg; int i; phys_addr_t end; + static const char flagname[BITS_PER_LONG][8] = { + [0 ... (BITS_PER_LONG-1)] = "?", + + [ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG", + [ilog2(MEMBLOCK_MIRROR)] = "MIRROR", + [ilog2(MEMBLOCK_NOMAP)] = "NOMAP", + [ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG", + }; 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\n", ®->base, &end); + seq_printf(m, "%pa..%pa ", ®->base, &end); + seq_printf(m, "%8s ", reg->flags ? flagname[ilog2(reg->flags)] : "NONE"); + seq_printf(m, "%4d\n", memblock_get_region_node(reg)); } return 0; }