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 69963C4345F for ; Fri, 19 Apr 2024 03:15:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5BC26B007B; Thu, 18 Apr 2024 23:15:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE4E16B0082; Thu, 18 Apr 2024 23:15:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A38416B0083; Thu, 18 Apr 2024 23:15:25 -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 845386B007B for ; Thu, 18 Apr 2024 23:15:25 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3678B140605 for ; Fri, 19 Apr 2024 03:15:25 +0000 (UTC) X-FDA: 82024815810.27.A7BE26E Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) by imf02.hostedemail.com (Postfix) with ESMTP id 35DA18000B for ; Fri, 19 Apr 2024 03:15:22 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LDxtZ1OH; spf=pass (imf02.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.50 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713496523; 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=AynYQ7XdQSZsHbg9syk301hg9bIfOjH6zNzBWjF5YpA=; b=6EV3afyENWj9XsH4dMPtBPKZ7QeEla/tlEpRRQPDKwykmxJ8OwQ2EQSUCAWsaydLgpEeEU g5q4bNVEc2l5v1/bwnV8LPZE/E4WMMcSHb6Y2+/zuni35SEKFCntlKGsbNnFmJvZX8u0MN +T+5NfxZwG2RgusvGqxRS2QkHy255XA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713496523; a=rsa-sha256; cv=none; b=xMWwMujtMbzT15Bv2UozFIzj5URThQ22VWVnmN1OL2ShSrIC32hVN61c4YrP2BycLrkSS0 3pbJXwMW1jrE2b5LSmRsbaKX2/68XJTYrRFWtMuIkHvq7CXDuJ/HXyPAVObbCslAaiVcDJ YS1uXj8iB+NoJWX36bJSZF2N23USAA0= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LDxtZ1OH; spf=pass (imf02.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.50 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a519e1b0e2dso156997266b.2 for ; Thu, 18 Apr 2024 20:15:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713496521; x=1714101321; 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=AynYQ7XdQSZsHbg9syk301hg9bIfOjH6zNzBWjF5YpA=; b=LDxtZ1OHjxZ99ZiDuaBpwGvMQynJ3vangf9AvG3tfmf59kXBRNGRSSVqAXW7+rohi2 bXsfEdcXA7pzyxtNLHAlS/nBKsDXxK4qMG/MB6ehKIOX9ZlYb5m7PQaxdBwts501wpbR UhEHvAjARsDxSkTGAh4vDYUj531aeoleQIg7c2JDoF1q/nR9aTxcvO+6PGTiTWVVNJHx L45F1r8kyJvwJtwwJVa2MCvtnDmYAS6/hvcM3slA4mPlksk+Xu5c8vrOLKo0nnjXIZbt NLtX+SQ8QJ6JORFLC3OBmpPAgnSuHAEf6SDSHVYtWhqDV9RWzdGFezEjtqbXKPaz86Ql Fqzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713496521; x=1714101321; 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=AynYQ7XdQSZsHbg9syk301hg9bIfOjH6zNzBWjF5YpA=; b=LJBxTkpN3PLTLgOhbMt23xbCN+5j+Ycgk6XrzcUUmrCINtAglSJM3Ud/s754ncAgwM UtRwJxpznMU9G+ztRUCBAudHdOWBF/w/Ahz+o+MChMXWT1mb8jVsvAge3iAID3de6Q9C vO6DjTRRi0PYeQay0WMwLQT6oAeY2c23dQYrCLHPVKi9szmipmEI252WuG01C6ETffpm hbxk7yYqERNvUvCpw/DANYm/Mz39T+f/pbUj4eDK66hDr92qo9LtLUjtWptPl2gBFy89 dP8E7Vr+NyfO8BEdrEIZ4XTy8bEM8EDFFRTJzl6IYjqWStBixqgqVc2uJrClKRhP7fNm Z+dA== X-Forwarded-Encrypted: i=1; AJvYcCVKuc7yC88LOSAhzaMf2Bhnf0AfhAxgkGQfobFYlXwSzrFxy6mVndvob7m0XOFGcWySnxu6SZnn6qgNKPeCl2aCF8g= X-Gm-Message-State: AOJu0YzP7+EFxbtMkvEZCTRi4DHvLMOuI9xRtQ0f4kjYz/5wYzgrbmoH dMMnA0RVpA62AjvtDUsmnDaNZIm3tg2f3PoF5yMyZGEh/5WIwYI0 X-Google-Smtp-Source: AGHT+IEgGqs1DknQlLfumxKBDynyORUiXn9sRXfiEm5/1ljp3F8MbSKj75ZlUFJdR/D7KXHVvKPqvg== X-Received: by 2002:a17:906:2899:b0:a55:5a0a:a74b with SMTP id o25-20020a170906289900b00a555a0aa74bmr552822ejd.33.1713496521295; Thu, 18 Apr 2024 20:15:21 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id bq7-20020a170906d0c700b00a53d6b895ddsm1596596ejb.200.2024.04.18.20.15.20 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Apr 2024 20:15:20 -0700 (PDT) Date: Fri, 19 Apr 2024 03:15:20 +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: <20240419031520.fkxz56kgan4jjchk@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-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 35DA18000B X-Stat-Signature: esxuf7yy1dx69p91u5aao7qx7z6n9rag X-Rspam-User: X-HE-Tag: 1713496522-284686 X-HE-Meta: U2FsdGVkX189W5sIdntMzP6H2xhn17HQIk+17jh20EmfHDugVQisKdKIlygelDyd//SRREw1tMbNBAdYzc1mM7dsO0Y+3SU5Oa9KGdDn7tRhN9vw/hzTwpdvrylR3nodlT8vBC06zbjTxhcbi5XfkWMgCddD6FgXpyFjW5VjJOKCdoYHU/LYvQAyy4ty6+UtixQnpFhWnzZ1aQYOK6yLdaA+PFP3kyXhRIMa4/aOFrNysUpiJmwBxcOKQvo/+3dg+0jZIJlivGGUmrEAv6ampXQOvQze6md3T9vKBIQ5HNIjwoexk6ipzXuk3RxoQ9m0oy8TJs3pLAX+HA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ySibVgjmLZqzvMg0vD6bVPB088jIbcTN1oUwgNHLqCofam9gQSjsbuTQX4yhxxn1ci4D+XysMRl5i4UfP+tr2lYcJEKFWMrFh9S2qN34l96U+P2gJJF/ji9hGlaJV1zmWuDGMTLd/0KeCFrMqB/9RCG3iryVxex8nAiGzriQrUiW/dTkoNHZxj4gUl1gYAxoHnts2pNnzlYOI/R76Xhy+V7IT5njQgqW4UxeC9m1KgotPOslZuATXMgg6G4u4O4NqFCU/45+12v2ft 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: 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 come up with another version, which could address the bug fixed by commit 48c3b583bbdd ("mm/memblock: fix overlapping allocation when doubling reserved array"). Comment out the fix, the test failed since cnt mismatch after double array. Not sure you prefer to have both or just leave this version by replacing current memblock_reserve_many_check(). diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c index d2b8114921f9..fb76471108b2 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -1006,6 +1006,119 @@ static int memblock_reserve_many_check(void) return 0; } +/* Keep the gap so these memory region will not be merged. */ +#define MEMORY_BASE_OFFSET(idx, offset) ((offset) + (MEM_SIZE * 2) * (idx)) +static int memblock_reserve_many_conflict_check(void) +{ + int i, skip; + void *orig_region; + struct region r = { + .base = SZ_16K, + .size = SZ_16K, + }; + phys_addr_t new_reserved_regions_size; + + /* + * 0 1 129 + * +---+ +---+ +---+ + * |32K| |32K| .. |32K| + * +---+ +---+ +---+ + * + * Pre-allocate the range for 129 memory block + one range for double + * memblock.reserved.regions at idx 0. + * See commit 48c3b583bbdd ("mm/memblock: fix overlapping allocation + * when doubling reserved array") + */ + phys_addr_t memory_base = (phys_addr_t)malloc(130 * (2 * SZ_32K)); + phys_addr_t offset = PAGE_ALIGN(memory_base); + + PREFIX_PUSH(); + + /* Reserve the 129th memory block for all possible positions*/ + for (skip = 1; skip <= INIT_MEMBLOCK_REGIONS + 1; skip++) + { + reset_memblock_regions(); + memblock_allow_resize(); + + reset_memblock_attributes(); + /* Add a valid memory region used by double_array(). */ + memblock_add(MEMORY_BASE_OFFSET(0, offset), MEM_SIZE); + /* + * Add a memory region which will be reserved as 129th memory + * region. This is not expected to be used by double_array(). + */ + memblock_add(MEMORY_BASE_OFFSET(skip, offset), MEM_SIZE); + + for (i = 1; i <= INIT_MEMBLOCK_REGIONS + 1; i++) { + if (i == skip) + continue; + + /* Reserve some fakes memory region to fulfill the memblock. */ + memblock_reserve(MEMORY_BASE_OFFSET(i, offset), MEM_SIZE); + + if (i < skip) { + ASSERT_EQ(memblock.reserved.cnt, i); + ASSERT_EQ(memblock.reserved.total_size, i * MEM_SIZE); + } else { + ASSERT_EQ(memblock.reserved.cnt, i - 1); + ASSERT_EQ(memblock.reserved.total_size, (i - 1) * MEM_SIZE); + } + } + + orig_region = memblock.reserved.regions; + + /* This reserve the 129 memory_region, and makes it double array. */ + memblock_reserve(MEMORY_BASE_OFFSET(skip, offset), 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); + + /* + * 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; + } + + free((void *)memory_base); + + test_pass_pop(); + + return 0; +} + static int memblock_reserve_checks(void) { prefix_reset(); @@ -1021,6 +1134,7 @@ static int memblock_reserve_checks(void) memblock_reserve_between_check(); memblock_reserve_near_max_check(); memblock_reserve_many_check(); + memblock_reserve_many_conflict_check(); prefix_pop(); -- 2.34.1 >> -- >> Wei Yang >> Help you, Help me > >-- >Sincerely yours, >Mike. -- Wei Yang Help you, Help me