From mboxrd@z Thu Jan 1 00:00:00 1970 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 3C60DC4345F for ; Thu, 18 Apr 2024 09:02:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8BB56B009C; Thu, 18 Apr 2024 05:02:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A3B016B009D; Thu, 18 Apr 2024 05:02:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 903446B009E; Thu, 18 Apr 2024 05:02:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 725BB6B009C for ; Thu, 18 Apr 2024 05:02:12 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 27D081C1291 for ; Thu, 18 Apr 2024 09:02:12 +0000 (UTC) X-FDA: 82022060904.04.B32C9DB Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by imf02.hostedemail.com (Postfix) with ESMTP id 2B9588001A for ; Thu, 18 Apr 2024 09:02:09 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=J4VH2LS+; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.51 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=1713430930; h=from:from:sender:reply-to: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FA04C21OtJLtW687yoIwuJFhsU/9isEzdyAMrgxPnJM=; b=EIF/K713un0/3qVWekPQD/01u2pl95Um7q6fXAhIay0HZPSapcYEtOcBLGsoJmzIsEDnns h+1tgrICKJdAg7l/KonmpWFnZ1UwxLuxoI/alipzyjINAytX7n7tqhvVyTgDVqHjgglmhe dtkgoIejD3qRwkvcS2uy2Y67cV9zreA= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=J4VH2LS+; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713430930; a=rsa-sha256; cv=none; b=XLQlo+46Wo7E5sZNQekOejE7Yx4y35Pr+wFBBCSuJ7DqVI6bGdmpYiaiUHCguXIXNjr0kr TqKO23GppmmnPpbvgHYDdq11+4A1+9JCiZx/ow1HrSuTNAKHfXEvE2R97iWKHimr2kHzXy sLVfbw3P3Oz4uQBShjlHBtiRoliqFgI= Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-57042f84cabso703665a12.2 for ; Thu, 18 Apr 2024 02:02:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713430928; x=1714035728; darn=kvack.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=FA04C21OtJLtW687yoIwuJFhsU/9isEzdyAMrgxPnJM=; b=J4VH2LS+NR9QvQJBQiry71v/AL5c3uNGVGJ+vNk5BmtqKiYmHqP/8CkVUguLzDAUmU 7cYRX0Iunteg23fVCWQo2oYW3uVBqczCm4AWOyekSGNUhH1eqbDFDtK/l142CttSZDxK 1BlNDRTADm23EUFw5Fm5eH/+HVgsvbpZkh/h0SwiTBgwLuqt6STp8b7hm8PEx8GZsX8r EqFc1kYeu/oFGkJFCHPqR6KS/oARy7mtUcaqcVutDBgsWaIEbvaG96wOIvRwkp4cPHVn PDAAysqYuUupgwPBHUs5UDEYfgn8Jw3cGD1eKoXrcFOoGPYbj6qIiION+kuvAmWXWJqI N7SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713430928; x=1714035728; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=FA04C21OtJLtW687yoIwuJFhsU/9isEzdyAMrgxPnJM=; b=HO/+FBYrjps0u+VXDZb9zdLvcBVJkzMB7lAsQzUO3UK4LJ7Wc5pFUafwjGtApkHxnE aH6Qn/ef6iZE2KCykXiPB8f+J0FOBYLi4hNbo4fNRRB2UQh6si9zSglpmImljFVcZDLs uS11wjs/WaZABi7S6MAfWMyEcggHDYoHMZdXww47LuuLwLpV/uuAMChZnQ7cIpPxD6Rp t0K7jsMLAZfwsgalml4VmtbAHyGcz9/ZXKGjrxsLApbABIPbQ0EwsMKwIjJCXYpDcGmI YTeBFtI8EQhTtQ25crvCUKpV2JBfpVMeYqIA1v9vUug61kg/8PpsbhvmYQZrxDfW0t1H f2sw== X-Forwarded-Encrypted: i=1; AJvYcCV/gs1FoA1fzuIKf/9lO1CG7A66urXhSb6IKRhmQ5CHZjxAmntVtcgMmlRaVn+813N7ITSTRezcwubE1I73yx/kvMA= X-Gm-Message-State: AOJu0Yzc2VlyUNHIzGD0gZ1TsxJrLeW6IK9iSSLdhY8xDYvp0fl1wRCz 8qKcWf8RWf6tN+R/u0EY0nexJOmv+61gQyjj7fHgXctLfZYa7lLA X-Google-Smtp-Source: AGHT+IETwqm9H0a31kzO9N+Xnfh/mG/5RZUCNM0GRUx2FkdUYmKbneTFwwUTCEIv63OWFzo5MSHZvQ== X-Received: by 2002:a17:906:d28e:b0:a4e:21e0:2e6e with SMTP id ay14-20020a170906d28e00b00a4e21e02e6emr1357031ejb.5.1713430928199; Thu, 18 Apr 2024 02:02:08 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id c19-20020a170906155300b00a526a99ccecsm612780ejd.42.2024.04.18.02.02.06 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Apr 2024 02:02:06 -0700 (PDT) Date: Thu, 18 Apr 2024 09:02:06 +0000 From: Wei Yang To: Mike Rapoport Cc: Wei Yang , akpm@linux-foundation.org, linux-mm@kvack.org Subject: Re: [PATCH 2/6] memblock tests: add the 129th memory block at all possible position Message-ID: <20240418090206.fgh42utxgvkqx3oc@master> Reply-To: Wei Yang References: <20240414004531.6601-1-richard.weiyang@gmail.com> <20240414004531.6601-2-richard.weiyang@gmail.com> <20240416125531.v7we4lo222pgyr2b@master> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 2B9588001A X-Stat-Signature: ed4dw8ykbkfonmixga4y17mgdobcqi1w X-HE-Tag: 1713430929-420584 X-HE-Meta: U2FsdGVkX19Uae3cdGlwByuJYmIgzb5V4WhV+8OSjgey8FfKlnya8ecX+P9M/dr70B6MEI1tRYn5ZfqcrpWMOu1TmOzhq2+ngLw2iU09Lz0AivZjmtoXF3G4R3uHl6Pf1S8lwbPUQIkmERsUYoHzMCVmkrI4W4LOUPWLMA2j6GpKjvR8eV2wOjroAUW14QfrnbQXyeqnmZmuvTZ7MpLv0YjdiktD6Z51XTmNcQ63LpXk6mIhVvoBj2WmBxXGp5uXDS7M6XzS3W/wXH8TbhL++eFjZTJztFAP1XKZh5hKwqQsckaHAGpDpy6OAj5PHf23Cmk3sQ2AWwj7IpIUR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K2eul13WIBog87OKuFNg6dLMvKgiB3wa9+wZ03txdis2vFM/aSgzCjgo73zQBrn0SJ5tzL5ZNJmr2UXMujn5iSxYCVd2OALCPIqGbWM2qYapa5q6LweO1w/0gQLHICrKLJx1OYQv0sMySPKXyATl8Ocw7KRv3hv4cOuXc8K3kE/WTPht+VHRh/9XLFvCuMELUwDSNFcNZifEy37/3I7dTTz8PB81iO+pZJz150gR9mg3vQlDmAFSQqzn3hzCHVzTCS47nzSbT6uQUp5xHh8XTQA1bY4oy+b4XhMnPq3l1Q8dnd X-Bogosity: Ham, tests=bogofilter, spamicity=0.000198, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Apr 17, 2024 at 08:51:14AM +0300, Mike Rapoport wrote: >On Tue, Apr 16, 2024 at 12:55:31PM +0000, Wei Yang wrote: >> On Mon, Apr 15, 2024 at 06:19:42PM +0300, Mike Rapoport wrote: >> >On Sun, Apr 14, 2024 at 12:45:27AM +0000, Wei Yang wrote: >> >> After previous change, we may double the array based on the position of >> >> the new range. >> >> >> >> Let's make sure the 129th memory block would double the size correctly >> >> at all possible position. >> > >> >Rather than rewrite an existing test, just add a new one. >> >> Ok, will add a new one for this. >> >> >Besides, it would be more interesting to test additions to >> >memblock.reserved and a mix of memblock_add() and memblock_reserve() that >> >will require resizing the memblock arrays. >> >> I don't get this very clearly. Would you mind give more hint? > >There is memblock_reserve_many_check() that verifies that memblock.reserved >is properly resized. I think it's better to add test that adds 129th block >at multiple locations to memblock.reserved. > I write a draft as below, is this what you expect? diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c index f1569ebb9872..d2b8114921f9 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -912,84 +912,94 @@ 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; - - /* This reserve the 129 memory_region, and makes it double array. */ - memblock_reserve(memory_base, 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); - - /* - * 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); - - 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; + orig_region = memblock.reserved.regions; + + /* 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); + + /* + * 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); + + 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; + } test_pass_pop(); -- 2.34.1 >> -- >> Wei Yang >> Help you, Help me > >-- >Sincerely yours, >Mike. -- Wei Yang Help you, Help me