From patchwork Thu Apr 4 23:36:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13618291 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 8142ACD1292 for ; Thu, 4 Apr 2024 23:36:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C73B66B00A0; Thu, 4 Apr 2024 19:36:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C24896B00A1; Thu, 4 Apr 2024 19:36:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC5606B00A2; Thu, 4 Apr 2024 19:36:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8F3576B00A0 for ; Thu, 4 Apr 2024 19:36:19 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B08B0160494 for ; Thu, 4 Apr 2024 23:36:18 +0000 (UTC) X-FDA: 81973460436.21.DD7C2EE Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by imf06.hostedemail.com (Postfix) with ESMTP id F36BF180016 for ; Thu, 4 Apr 2024 23:36:16 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jDN72QrU; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.46 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712273777; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=wwMKX0gZydY7uzB7iLiTmp2XTDTxbr/jmNoKdT/fzLg=; b=MNaj3eKTchRRTdZ/L3/gVN5DfhlG5gthwBkIfS1JcOVSMyma4F+8zVDRuMLhMKSyffNUND /1PbEYMu8cPW2cJ+Nti4v4HfYqZRPoYPSUlWQeAl1zueOrn8O47/gaKZz1fefAu479Jiq1 djAaa0Ao0S3F/ycSqEjjr3DwDssEkq0= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jDN72QrU; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.46 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712273777; a=rsa-sha256; cv=none; b=qxNn8xYW2ftwlMiJGT8kEYtUZde8I/4gLV8CGCg5AYReZA/Oy+UFRUYRQYTehydye5Ddy2 KIbMJDnEk6s5H+nwdH+erI8Gz3cjVeL/f7aIa2rhWvN9YHZxw23Yl2Rw7ulqBeAO+GNfu2 jGrFQLmP+PmNi5xAhsaLGew/VuAcZfw= Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a45f257b81fso216933166b.0 for ; Thu, 04 Apr 2024 16:36:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712273775; x=1712878575; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wwMKX0gZydY7uzB7iLiTmp2XTDTxbr/jmNoKdT/fzLg=; b=jDN72QrUz1X8sNWS936GGVb1D441GzBoocFiVaG3CINtpitVJU1/YD1rvLTnVwhKIb gQfkDS4SFGIvLxq/HCEtsX8TLPqAWKCZkvkkJIbIbybIyhQOHrt9mrIgUjovML24Gwbz 988T72tBKhhdi+II6pws7yvqG81gOrRvSe2GbAxgzys0rXS2mGlR7i1AJRwf5h2upazt wsZx3KSrX4GfFihT1714qbF3GFae5DMaX5yk28CbrIC4rj/VR2B75EwcZEo02PWf5RNI GRDUFn0GV5yTcj9Kc07Lr3dnLEEFWdKhv0h1ci1WrB2fvpjN5Vyhj58efb+wOR43CMmd FZ6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712273775; x=1712878575; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wwMKX0gZydY7uzB7iLiTmp2XTDTxbr/jmNoKdT/fzLg=; b=avaulCBCfo7AOglsnMu2ezqrNZqKxUPQxxJ3+P+Ml8YHUjWmaAxg5tUfnEDPL0s8vX mTkh9FKwZJXumnpcbFgSHon1OaPl2naB8MdEw3Kg4lvA59GxbqconSxJuYIjVKUriU/J Qsig6TpvwTEGjBGHNRzD/LfBWKhYde2pItFiAgfxHI7pGEmvg8pyrxuAGyDrImnbfz8O qMf0Zr5nxellt6chNwIZtGCQsT4k6VctJEPVQESgRpiQSbSKRzmB1Vk5qnW72lUWjGMW S1Vu7wwA7Q963QwT4xb1tjLP/nk1Fb2NDW2LFPmAAf86uZmO5t9wRRfilekUM7w5IkpD 55cA== X-Gm-Message-State: AOJu0YwpufSNNA+tuuRqs9XKaVIqyNSLfkEBfiN7GN56KGNQcqE29Scm iQ3lKo3Zp4FlTPoR0VZ2jovsWyqGNduV+CUa0i03hykNF5kLpkWp X-Google-Smtp-Source: AGHT+IHaAriCXp6flLKN4C2k1wazLJRMml07hwFh4bGbqyk6vXMQPBiYDzoPHR0PXjEUMS0MVWGS9A== X-Received: by 2002:a17:906:ae97:b0:a51:a486:3f1b with SMTP id md23-20020a170906ae9700b00a51a4863f1bmr85451ejb.68.1712273775185; Thu, 04 Apr 2024 16:36:15 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id jl7-20020a17090775c700b00a4e70ede2b7sm132483ejc.174.2024.04.04.16.36.14 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Apr 2024 16:36:14 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang , Paul Mackerras , Tejun Heo Subject: [Patch v2] mm/memblock: remove empty dummy entry Date: Thu, 4 Apr 2024 23:36:07 +0000 Message-Id: <20240404233607.5522-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspam-User: X-Stat-Signature: 8h1squ5qo73614wqyfsxpg679ksb1y8u X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: F36BF180016 X-HE-Tag: 1712273776-199810 X-HE-Meta: U2FsdGVkX1+qDQvTP2cYpKZWk4ewuKp9+zsPA+hWdQoG+fZf50++m2dSRnRf5/483NIRJIpubK9wY0BM7hhKchWdM+Rn5sfmwGMpaSgGi9hE2qGR1e2ImJSDvQ/SOaaH4lcHKxCRS//P5QUOUlIdKse+HsA7AxUQbQRlRbgWcLd/mvQsiVM3RDo/jhwIjj87Wh8gj3eHfjJKqFqg+f0KdE4nCNI9eccZwi7OI1zO7DewWoHG5vSuYiAJ33mq8ADlpWTVZxpjXr+itWr9s93nyXRo7+MgFdz98L5oIx1UFrhZnAuuqVvTYf0+yxWjieTZThWgSySSr19npZxQEMW/GUiKMxWlp8UZ4gJzElJUnHRrWg9ZvFAzZbR24WYdszfDjgelaug++c7naNeUNisSKGqYxm3qPjEC/8XP2St80U6ipreoRElbzlxmlERqMJHMnhMeJSW/LCSVKuQc3uoxSLO/PVCYRZa44858ZVlAqy4X10AWosD+IhsUtGKVlOjgBbgek5bGUyjgU4oh1vv7WStVtsdiBXOu5Hw39Nff9zMnd0Zq9+XmI01NEk7MBwy7Wd8hJVOYoPkRsRs18qE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mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The dummy entry is introduced in the initial implementation of lmb in commit 7c8c6b9776fb ("powerpc: Merge lmb.c and make MM initialization use it."). As the comment says the empty dummy entry is to simplify the code. /* Create a dummy zero size LMB which will get coalesced away later. * This simplifies the lmb_add() code below... */ While current code is reimplemented by Tejun in commit 784656f9c680 ("memblock: Reimplement memblock_add_region()"). This empty dummy entry seems not benefit the code any more. Let's remove it. Signed-off-by: Wei Yang CC: Paul Mackerras CC: Tejun Heo CC: Mike Rapoport --- v2: remove cnt initialization to 0 and keep special case for empty array --- mm/memblock.c | 7 ++----- tools/testing/memblock/tests/basic_api.c | 8 ++++---- tools/testing/memblock/tests/common.c | 2 -- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index d09136e040d3..98d25689cf10 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -114,12 +114,10 @@ static struct memblock_region memblock_physmem_init_regions[INIT_PHYSMEM_REGIONS struct memblock memblock __initdata_memblock = { .memory.regions = memblock_memory_init_regions, - .memory.cnt = 1, /* empty dummy entry */ .memory.max = INIT_MEMBLOCK_MEMORY_REGIONS, .memory.name = "memory", .reserved.regions = memblock_reserved_init_regions, - .reserved.cnt = 1, /* empty dummy entry */ .reserved.max = INIT_MEMBLOCK_RESERVED_REGIONS, .reserved.name = "reserved", @@ -130,7 +128,6 @@ struct memblock memblock __initdata_memblock = { #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP struct memblock_type physmem = { .regions = memblock_physmem_init_regions, - .cnt = 1, /* empty dummy entry */ .max = INIT_PHYSMEM_REGIONS, .name = "physmem", }; @@ -356,7 +353,6 @@ static void __init_memblock memblock_remove_region(struct memblock_type *type, u /* Special case for empty arrays */ if (type->cnt == 0) { WARN_ON(type->total_size != 0); - type->cnt = 1; type->regions[0].base = 0; type->regions[0].size = 0; type->regions[0].flags = 0; @@ -600,12 +596,13 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, /* special case for empty array */ if (type->regions[0].size == 0) { - WARN_ON(type->cnt != 1 || type->total_size); + WARN_ON(type->cnt != 0 || type->total_size); type->regions[0].base = base; type->regions[0].size = size; type->regions[0].flags = flags; memblock_set_region_node(&type->regions[0], nid); type->total_size = size; + type->cnt = 1; return 0; } diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c index 57bf2688edfd..f317fe691fc4 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -15,12 +15,12 @@ static int memblock_initialization_check(void) PREFIX_PUSH(); ASSERT_NE(memblock.memory.regions, NULL); - ASSERT_EQ(memblock.memory.cnt, 1); + ASSERT_EQ(memblock.memory.cnt, 0); ASSERT_EQ(memblock.memory.max, EXPECTED_MEMBLOCK_REGIONS); ASSERT_EQ(strcmp(memblock.memory.name, "memory"), 0); ASSERT_NE(memblock.reserved.regions, NULL); - ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(memblock.reserved.cnt, 0); ASSERT_EQ(memblock.memory.max, EXPECTED_MEMBLOCK_REGIONS); ASSERT_EQ(strcmp(memblock.reserved.name, "reserved"), 0); @@ -1295,7 +1295,7 @@ static int memblock_remove_only_region_check(void) ASSERT_EQ(rgn->base, 0); ASSERT_EQ(rgn->size, 0); - ASSERT_EQ(memblock.memory.cnt, 1); + ASSERT_EQ(memblock.memory.cnt, 0); ASSERT_EQ(memblock.memory.total_size, 0); test_pass_pop(); @@ -1723,7 +1723,7 @@ static int memblock_free_only_region_check(void) ASSERT_EQ(rgn->base, 0); ASSERT_EQ(rgn->size, 0); - ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(memblock.reserved.cnt, 0); ASSERT_EQ(memblock.reserved.total_size, 0); test_pass_pop(); diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock/tests/common.c index f43b6f414983..2e96e6be423e 100644 --- a/tools/testing/memblock/tests/common.c +++ b/tools/testing/memblock/tests/common.c @@ -40,13 +40,11 @@ void reset_memblock_regions(void) { memset(memblock.memory.regions, 0, memblock.memory.cnt * sizeof(struct memblock_region)); - memblock.memory.cnt = 1; memblock.memory.max = INIT_MEMBLOCK_REGIONS; memblock.memory.total_size = 0; memset(memblock.reserved.regions, 0, memblock.reserved.cnt * sizeof(struct memblock_region)); - memblock.reserved.cnt = 1; memblock.reserved.max = INIT_MEMBLOCK_RESERVED_REGIONS; memblock.reserved.total_size = 0; }