From patchwork Thu Apr 25 07:19:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13642907 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 46162C10F1A for ; Thu, 25 Apr 2024 07:20:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0C1F6B0095; Thu, 25 Apr 2024 03:20:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C6F026B0096; Thu, 25 Apr 2024 03:20:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D6A96B0098; Thu, 25 Apr 2024 03:20:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7E6336B0095 for ; Thu, 25 Apr 2024 03:20:01 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4AC0A16038E for ; Thu, 25 Apr 2024 07:20:01 +0000 (UTC) X-FDA: 82047205002.01.82C02CE Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) by imf23.hostedemail.com (Postfix) with ESMTP id 8B15E140016 for ; Thu, 25 Apr 2024 07:19:59 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IB44bI3a; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.45 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=1714029599; 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:in-reply-to: references:references:dkim-signature; bh=ruk7s7bdabrinkpT9zz0qoc/gy6xrlFmeWcA59VPr04=; b=wK8/72kIskdMgQKvryNcm+51Fccq/YmyWRTD7/iD8uLnBin1uhspcd41RcbJW4fx8dQA1e TE9fs2Iw2CBUt/o0svO81llPntesZMKgpml8Zr4XzJnqXpwgpOZZU5MQkTeEJQAax2U65Q Wyoc7okKxutROzKVEPFLCbHezx4/faI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IB44bI3a; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.45 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714029599; a=rsa-sha256; cv=none; b=3TEhMABSUh1p5QvYABrzbZTdHW4fVbZVlUOD43N1BPqHHeCBiKLVnmtiVSY0hG48mfXhwS 9TBfZA5PjgJa4wruXvRFSOAf+3YYFTDId6YEuskKuHXT3xkCbm0fLC+Q16380NTwya2OCE gP3x+A3JMtyKrNllUhype7jjPuNG4kc= Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5723edf0ae5so306239a12.0 for ; Thu, 25 Apr 2024 00:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714029598; x=1714634398; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=ruk7s7bdabrinkpT9zz0qoc/gy6xrlFmeWcA59VPr04=; b=IB44bI3at2aoY/jPGlkYiEw4OQhx7wIBCPMKiw8VQdZP/U/m/sjwU+J/zq6XUHWQj/ dE3L4GVtz6lIhqGX/wALe+TNq6R1H6aV27mt/XxpqR2p+kldLwbVHnAoJonESH0TrYTH b+lTT9j46ZPr7450G0wuoVByKf5DJvpkPOqyF4rwDP3tUDO5SKFv1UMnKMQo77AqZIst xlxslAAvfghJqODXUJF2dFVcBArQHucd2TKrhe9Dxw10/UmnNgCYYt6W76YxmthJaOVh bSoShGwp9dF+FoMaE7nKIraucx15p0vzYXkWVnBKHRHn3kDQYQX2jYfQSuswIunW66tq BqLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714029598; x=1714634398; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ruk7s7bdabrinkpT9zz0qoc/gy6xrlFmeWcA59VPr04=; b=utT6zwKVhuPxXjE4R6BCoXysRT+RTVR7SyrbDFRSzA2TTsmigW8fgHW2cCLNX+C9pV qZ6k3fNTWZPDGTJ2HZkQdiGBf1T4O7vVCQ7cL6fDZr6c1JPZrYYa26wDogix2jXmR3rl CqGDTaNDt4cuIgKSD5H2TXANk/daG6QOZNOhvUhN3sK6c3bZ03aFa1CjGDY7GFyd+/+b +o6CVC+iw5Y9M//d8NLoNwKMTH084C0rpusmLtDfOD4svIUZbJxmhtSiI7yWDMNBRaq/ KHnZZjplZSH8evIG2645CHWvaMEFlvbENQfHPd8WrRxF/HgD5UxFfs8RRrSJYB/5qG63 +v4A== X-Gm-Message-State: AOJu0YxV1I4jxH07EXaGXaHfcfkXw1aYgxNfHe/GhDp+Cq0fBuqqWdL7 3mocI3trojuBazSzmNx1ywZQZvJeI7VHTr1s09dc778HsGVFG/L8xh/ixI8f X-Google-Smtp-Source: AGHT+IHAg9Nww8nowt5XSgWZ1jsU+QCSk2dek0fqJysW9t4Y5P7Evy6K64Z6cQtJTP4gNycXnZ944g== X-Received: by 2002:a50:a693:0:b0:56d:fca5:4245 with SMTP id e19-20020a50a693000000b0056dfca54245mr3354485edc.10.1714029597979; Thu, 25 Apr 2024 00:19:57 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id et6-20020a056402378600b0057245a3fd4bsm130271edb.68.2024.04.25.00.19.56 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Apr 2024 00:19:56 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang Subject: [Patch v2 1/8] memblock tests: reserve the 129th memory block at all possible position Date: Thu, 25 Apr 2024 07:19:22 +0000 Message-Id: <20240425071929.18004-2-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240425071929.18004-1-richard.weiyang@gmail.com> References: <20240425071929.18004-1-richard.weiyang@gmail.com> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8B15E140016 X-Rspam-User: X-Stat-Signature: x9bj1udtzp9iw6ufc33zkhy3oixh1kzg X-HE-Tag: 1714029599-123998 X-HE-Meta: U2FsdGVkX19whHZRDnlr+nx8NBjATWtWsW7XszUWCU7F6HVrXZqyl7NnDClyBjrAHfAT0OQIVLFDqvRMfcO+ZOrxBMhigMoougK05352vI1pUuEXV/UZIH1MxlfX/lsuXz8ngQ3Weez6dfAPc+vL+4SsiAF6FiSzmVOQvi7sif6mc80bUytayU7B2yAAz4tlwNCQtTo0MElO0uuS0ScqnGCdOmJIAm52MSeFMxVZlzZ9881rh3rcG7KbqCe9pGqWDajzzKGdvzkwyvWurslDVgJBeBLr70wS4wLoTm9a9Bvxc0lExU74QmktManIvZ3pXdcFTcVae4FEcGE17InAJ575+f/8Qvo9CefoyqjXYh7Po/quPMjdAyDD3+36XlfVjXyvNf2g0urL230q2Z8WY4mI45DfV1skQJxra7ukAIsBC8VY/Bxs894yZsufCzvbEGAYgdmmlR+uUzkp2/LWkjojscQPyvdq6V1A41sf271b88rCS2/zo7hVFCmk1UDjl00Y2ntrZbeVywsw74mcH22BwxhqP2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ack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In stead of add 129th memory block at the last position, let's try all possible position. Signed-off-by: Wei Yang --- tools/testing/memblock/tests/basic_api.c | 121 ++++++++++++----------- 1 file changed, 65 insertions(+), 56 deletions(-) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c index f317fe691fc4..1ae62272867a 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -898,84 +898,93 @@ static int memblock_reserve_near_max_check(void) * memblock.memory.max, find a new valid memory as * reserved.regions. */ +/* Keep the gap so these memory region will not be merged. */ +#define MEMORY_BASE(idx) (SZ_128K + (MEM_SIZE * 2) * (idx)) static int memblock_reserve_many_check(void) { - int i; + int i, skip; void *orig_region; struct region r = { .base = SZ_16K, .size = SZ_16K, }; - phys_addr_t memory_base = SZ_128K; phys_addr_t new_reserved_regions_size; PREFIX_PUSH(); - reset_memblock_regions(); - memblock_allow_resize(); + /* Reserve the 129th memory block for all possible positions*/ + for (skip = 0; skip < INIT_MEMBLOCK_REGIONS + 1; skip++) { + reset_memblock_regions(); + memblock_allow_resize(); - /* Add a valid memory region used by double_array(). */ - dummy_physical_memory_init(); - memblock_add(dummy_physical_memory_base(), MEM_SIZE); + /* Add a valid memory region used by double_array(). */ + dummy_physical_memory_init(); + memblock_add(dummy_physical_memory_base(), MEM_SIZE); - for (i = 0; i < INIT_MEMBLOCK_REGIONS; i++) { - /* Reserve some fakes memory region to fulfill the memblock. */ - memblock_reserve(memory_base, MEM_SIZE); + for (i = 0; i < INIT_MEMBLOCK_REGIONS + 1; i++) { + if (i == skip) + continue; - ASSERT_EQ(memblock.reserved.cnt, i + 1); - ASSERT_EQ(memblock.reserved.total_size, (i + 1) * MEM_SIZE); + /* Reserve some fakes memory region to fulfill the memblock. */ + memblock_reserve(MEMORY_BASE(i), MEM_SIZE); - /* Keep the gap so these memory region will not be merged. */ - memory_base += MEM_SIZE * 2; - } + if (i < skip) { + ASSERT_EQ(memblock.reserved.cnt, i + 1); + ASSERT_EQ(memblock.reserved.total_size, (i + 1) * MEM_SIZE); + } else { + ASSERT_EQ(memblock.reserved.cnt, i); + ASSERT_EQ(memblock.reserved.total_size, i * MEM_SIZE); + } + } - orig_region = memblock.reserved.regions; + orig_region = memblock.reserved.regions; - /* This reserve the 129 memory_region, and makes it double array. */ - memblock_reserve(memory_base, MEM_SIZE); + /* This reserve the 129 memory_region, and makes it double array. */ + memblock_reserve(MEMORY_BASE(skip), MEM_SIZE); - /* - * This is the memory region size used by the doubled reserved.regions, - * and it has been reserved due to it has been used. The size is used to - * calculate the total_size that the memblock.reserved have now. - */ - new_reserved_regions_size = PAGE_ALIGN((INIT_MEMBLOCK_REGIONS * 2) * - sizeof(struct memblock_region)); - /* - * The double_array() will find a free memory region as the new - * reserved.regions, and the used memory region will be reserved, so - * there will be one more region exist in the reserved memblock. And the - * one more reserved region's size is new_reserved_regions_size. - */ - ASSERT_EQ(memblock.reserved.cnt, INIT_MEMBLOCK_REGIONS + 2); - ASSERT_EQ(memblock.reserved.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE + - new_reserved_regions_size); - ASSERT_EQ(memblock.reserved.max, INIT_MEMBLOCK_REGIONS * 2); + /* + * This is the memory region size used by the doubled reserved.regions, + * and it has been reserved due to it has been used. The size is used to + * calculate the total_size that the memblock.reserved have now. + */ + new_reserved_regions_size = PAGE_ALIGN((INIT_MEMBLOCK_REGIONS * 2) * + sizeof(struct memblock_region)); + /* + * The double_array() will find a free memory region as the new + * reserved.regions, and the used memory region will be reserved, so + * there will be one more region exist in the reserved memblock. And the + * one more reserved region's size is new_reserved_regions_size. + */ + ASSERT_EQ(memblock.reserved.cnt, INIT_MEMBLOCK_REGIONS + 2); + ASSERT_EQ(memblock.reserved.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE + + new_reserved_regions_size); + ASSERT_EQ(memblock.reserved.max, INIT_MEMBLOCK_REGIONS * 2); - /* - * Now memblock_double_array() works fine. Let's check after the - * double_array(), the memblock_reserve() still works as normal. - */ - memblock_reserve(r.base, r.size); - ASSERT_EQ(memblock.reserved.regions[0].base, r.base); - ASSERT_EQ(memblock.reserved.regions[0].size, r.size); + /* + * Now memblock_double_array() works fine. Let's check after the + * double_array(), the memblock_reserve() still works as normal. + */ + memblock_reserve(r.base, r.size); + ASSERT_EQ(memblock.reserved.regions[0].base, r.base); + ASSERT_EQ(memblock.reserved.regions[0].size, r.size); - ASSERT_EQ(memblock.reserved.cnt, INIT_MEMBLOCK_REGIONS + 3); - ASSERT_EQ(memblock.reserved.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE + - new_reserved_regions_size + - r.size); - ASSERT_EQ(memblock.reserved.max, INIT_MEMBLOCK_REGIONS * 2); + ASSERT_EQ(memblock.reserved.cnt, INIT_MEMBLOCK_REGIONS + 3); + ASSERT_EQ(memblock.reserved.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE + + new_reserved_regions_size + + r.size); + ASSERT_EQ(memblock.reserved.max, INIT_MEMBLOCK_REGIONS * 2); - dummy_physical_memory_cleanup(); + dummy_physical_memory_cleanup(); - /* - * The current reserved.regions is occupying a range of memory that - * allocated from dummy_physical_memory_init(). After free the memory, - * we must not use it. So restore the origin memory region to make sure - * the tests can run as normal and not affected by the double array. - */ - memblock.reserved.regions = orig_region; - memblock.reserved.cnt = INIT_MEMBLOCK_RESERVED_REGIONS; + /* + * The current reserved.regions is occupying a range of memory that + * allocated from dummy_physical_memory_init(). After free the memory, + * we must not use it. So restore the origin memory region to make sure + * the tests can run as normal and not affected by the double array. + */ + memblock.reserved.regions = orig_region; + memblock.reserved.cnt = INIT_MEMBLOCK_RESERVED_REGIONS; + } test_pass_pop();