linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Rebecca Mckeever <remckee0@gmail.com>
To: "Huang, Shaoqin" <shaoqin.huang@intel.com>
Cc: Mike Rapoport <rppt@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	David Hildenbrand <david@redhat.com>
Subject: Re: [PATCH 8/8] memblock tests: add tests for memblock_trim_memory
Date: Sat, 20 Aug 2022 01:40:26 -0700	[thread overview]
Message-ID: <20220820084026.GA13533@sophie> (raw)
In-Reply-To: <9f6a0b68-6777-dd88-929c-2d4303b28984@intel.com>

On Tue, Aug 16, 2022 at 09:46:11AM +0800, Huang, Shaoqin wrote:
> 
> 
> On 8/14/2022 1:54 PM, Rebecca Mckeever wrote:
> > Add tests for memblock_trim_memory() for the following scenarios:
> > - all regions aligned
> > - one region unalign that is smaller than the alignment
> > - one region unaligned at the base
> > - one region unaligned at the end
> > 
> > Signed-off-by: Rebecca Mckeever <remckee0@gmail.com>
> > ---
> >   tools/testing/memblock/tests/basic_api.c | 223 +++++++++++++++++++++++
> >   1 file changed, 223 insertions(+)
> > 
> > diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c
> > index d7f008e7a12a..c8bb44f20846 100644
> > --- a/tools/testing/memblock/tests/basic_api.c
> > +++ b/tools/testing/memblock/tests/basic_api.c
> > @@ -8,6 +8,7 @@
> >   #define FUNC_RESERVE					"memblock_reserve"
> >   #define FUNC_REMOVE					"memblock_remove"
> >   #define FUNC_FREE					"memblock_free"
> > +#define FUNC_TRIM					"memblock_trim_memory"
> >   static int memblock_initialization_check(void)
> >   {
> > @@ -1723,6 +1724,227 @@ static int memblock_bottom_up_checks(void)
> >   	return 0;
> >   }
> > +/*
> > + * A test that tries to trim memory when both ends of the memory region are
> > + * aligned. Expect that the memory will not be trimmed. Expect the counter to
> > + * not be updated.
> > + */
> > +static int memblock_trim_memory_aligned_check(void)
> > +{
> > +	struct memblock_region *rgn;
> > +	phys_addr_t alignment = SMP_CACHE_BYTES;
> > +
> > +	rgn = &memblock.memory.regions[0];
> > +
> > +	struct region r = {
> > +		.base = alignment,
> > +		.size = alignment * 4
> > +	};
> > +
> > +	PREFIX_PUSH();
> > +
> > +	reset_memblock_regions();
> > +	memblock_add(r.base, r.size);
> > +	memblock_trim_memory(alignment);
> > +
> > +	ASSERT_EQ(rgn->base, r.base);
> > +	ASSERT_EQ(rgn->size, r.size);
> > +
> > +	ASSERT_EQ(memblock.memory.cnt, 1);
> > +
> > +	test_pass_pop();
> > +
> > +	return 0;
> > +}
> > +
> > +/*
> > + * A test that tries to trim memory when there are two available regions, r1 and
> > + * r2. Region r1 is aligned on both ends and region r2 is unaligned on one end
> > + * and smaller than the alignment:
> > + *
> > + *                                     alignment
> > + *                                     |--------|
> > + * |        +-----------------+        +------+   |
> > + * |        |        r1       |        |  r2  |   |
> > + * +--------+-----------------+--------+------+---+
> > + *          ^        ^        ^        ^      ^
> > + *          |________|________|________|      |
> > + *                            |               Unaligned address
> > + *                Aligned addresses
> > + *
> > + * Expect that r1 will not be trimmed and r2 will be removed. Expect the
> > + * counter to be updated.
> > + */
> > +static int memblock_trim_memory_too_small_check(void)
> > +{
> > +	struct memblock_region *rgn;
> > +	phys_addr_t alignment = SMP_CACHE_BYTES;
> > +
> > +	rgn = &memblock.memory.regions[0];
> > +
> > +	struct region r1 = {
> > +		.base = alignment,
> > +		.size = alignment * 2
> > +	};
> > +	struct region r2 = {
> > +		.base = alignment * 4,
> > +		.size = alignment - SZ_2
> > +	};
> > +
> > +	PREFIX_PUSH();
> > +
> > +	reset_memblock_regions();
> > +	memblock_add(r1.base, r1.size);
> > +	memblock_add(r2.base, r2.size);
> > +	memblock_trim_memory(alignment);
> > +
> > +	ASSERT_EQ(rgn->base, r1.base);
> > +	ASSERT_EQ(rgn->size, r1.size);
> > +
> > +	ASSERT_EQ(memblock.memory.cnt, 1);
> > +
> > +	test_pass_pop();
> > +
> > +	return 0;
> > +}
> > +
> > +/*
> > + * A test that tries to trim memory when there are two available regions, r1 and
> > + * r2. Region r1 is aligned on both ends and region r2 is unaligned at the base
> > + * and aligned at the end:
> > + *
> > + *                               Unaligned address
> > + *                                       |
> > + *                                       v
> > + * |        +-----------------+          +---------------+   |
> > + * |        |        r1       |          |      r2       |   |
> > + * +--------+-----------------+----------+---------------+---+
> > + *          ^        ^        ^        ^        ^        ^
> > + *          |________|________|________|________|________|
> > + *                            |
> > + *                    Aligned addresses
> > + *
> > + * Expect that r1 will not be trimmed and r2 will be trimmed at the base.
> > + * Expect the counter to not be updated.
> > + */
> > +static int memblock_trim_memory_unaligned_base_check(void)
> > +{
> > +	struct memblock_region *rgn1, *rgn2;
> > +	phys_addr_t alignment = SMP_CACHE_BYTES;
> > +	phys_addr_t offset = SZ_2;
> > +	phys_addr_t r2_base, r2_size;
> > +
> > +	rgn1 = &memblock.memory.regions[0];
> > +	rgn2 = &memblock.memory.regions[1];
> > +
> > +	struct region r1 = {
> > +		.base = alignment,
> > +		.size = alignment * 2
> > +	};
> > +	struct region r2 = {
> > +		.base = alignment * 4 + offset,
> > +		.size = alignment * 2 - offset
> > +	};
> > +
> > +	PREFIX_PUSH();
> > +
> > +	r2_base = r2.base + (alignment - offset);
> > +	r2_size = r2.size - (alignment - offset);
> 
> Also the variable name.
> 
> > +
> > +	reset_memblock_regions();
> > +	memblock_add(r1.base, r1.size);
> > +	memblock_add(r2.base, r2.size);
> > +	memblock_trim_memory(alignment);
> > +
> > +	ASSERT_EQ(rgn1->base, r1.base);
> > +	ASSERT_EQ(rgn1->size, r1.size);
> > +
> > +	ASSERT_EQ(rgn2->base, r2_base);
> > +	ASSERT_EQ(rgn2->size, r2_size);
> > +
> > +	ASSERT_EQ(memblock.memory.cnt, 2);
> > +
> > +	test_pass_pop();
> > +
> > +	return 0;
> > +}
> > +
> > +/*
> > + * A test that tries to trim memory when there are two available regions, r1 and
> > + * r2. Region r1 is aligned on both ends and region r2 is aligned at the base
> > + * and unaligned at the end:
> > + *
> > + *                                             Unaligned address
> > + *                                                     |
> > + *                                                     v
> > + * |        +-----------------+        +---------------+   |
> > + * |        |        r1       |        |      r2       |   |
> > + * +--------+-----------------+--------+---------------+---+
> > + *          ^        ^        ^        ^        ^        ^
> > + *          |________|________|________|________|________|
> > + *                            |
> > + *                    Aligned addresses
> > + *
> > + * Expect that r1 will not be trimmed and r2 will be trimmed at the base.
> 								^
> 							at the end.

I forgot to make this change in v2. I will include it in v3.

> > + * Expect the counter to not be updated.
> > + */
> > +static int memblock_trim_memory_unaligned_end_check(void)
> > +{
> > +	struct memblock_region *rgn1, *rgn2;
> > +	phys_addr_t alignment = SMP_CACHE_BYTES;
> > +	phys_addr_t offset = SZ_2;
> > +	phys_addr_t r2_size;
> > +
> > +	rgn1 = &memblock.memory.regions[0];
> > +	rgn2 = &memblock.memory.regions[1];
> > +
> > +	struct region r1 = {
> > +		.base = alignment,
> > +		.size = alignment * 2
> > +	};
> > +	struct region r2 = {
> > +		.base = alignment * 4,
> > +		.size = alignment * 2 - offset
> > +	};
> > +
> > +	PREFIX_PUSH();
> > +
> > +	r2_size = r2.size - (alignment - offset);
> > +
> > +	reset_memblock_regions();
> > +	memblock_add(r1.base, r1.size);
> > +	memblock_add(r2.base, r2.size);
> > +	memblock_trim_memory(alignment);
> > +
> > +	ASSERT_EQ(rgn1->base, r1.base);
> > +	ASSERT_EQ(rgn1->size, r1.size);
> > +
> > +	ASSERT_EQ(rgn2->base, r2.base);
> > +	ASSERT_EQ(rgn2->size, r2_size);
> > +
> > +	ASSERT_EQ(memblock.memory.cnt, 2);
> > +
> > +	test_pass_pop();
> > +
> > +	return 0;
> > +}
> > +
> > +static int memblock_trim_memory_checks(void)
> > +{
> > +	prefix_reset();
> > +	prefix_push(FUNC_TRIM);
> > +	test_print("Running %s tests...\n", FUNC_TRIM);
> > +
> > +	memblock_trim_memory_aligned_check();
> > +	memblock_trim_memory_too_small_check();
> > +	memblock_trim_memory_unaligned_base_check();
> > +	memblock_trim_memory_unaligned_end_check();
> > +
> > +	prefix_pop();
> > +
> > +	return 0;
> > +}
> > +
> >   int memblock_basic_checks(void)
> >   {
> >   	memblock_initialization_check();
> > @@ -1731,6 +1953,7 @@ int memblock_basic_checks(void)
> >   	memblock_remove_checks();
> >   	memblock_free_checks();
> >   	memblock_bottom_up_checks();
> > +	memblock_trim_memory_checks();
> >   	return 0;
> >   }
> 
> Others looks good.

Thanks,
Rebecca


      reply	other threads:[~2022-08-20  8:42 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-14  5:53 [PATCH 0/8] memblock tests: update and extend memblock simulator Rebecca Mckeever
2022-08-14  5:53 ` [PATCH 1/8] memblock tests: update tests to check if memblock_alloc zeroed memory Rebecca Mckeever
2022-08-15  8:50   ` Huang, Shaoqin
2022-08-16  2:15     ` Rebecca Mckeever
2022-08-16  2:24       ` Huang, Shaoqin
2022-08-14  5:53 ` [PATCH 2/8] memblock tests: update zeroed memory check for memblock_alloc_* tests Rebecca Mckeever
2022-08-15  8:59   ` Huang, Shaoqin
2022-08-14  5:53 ` [PATCH 3/8] memblock tests: add labels to verbose output for generic alloc tests Rebecca Mckeever
2022-08-15  9:15   ` Huang, Shaoqin
2022-08-16  2:39     ` Rebecca Mckeever
2022-08-16  3:08       ` Huang, Shaoqin
2022-08-19  5:03         ` Rebecca Mckeever
2022-08-19  8:39           ` Huang, Shaoqin
2022-08-14  5:53 ` [PATCH 4/8] memblock tests: add additional tests for basic api and memblock_alloc Rebecca Mckeever
2022-08-15 10:19   ` Huang, Shaoqin
2022-08-14  5:53 ` [PATCH 5/8] memblock tests: update alloc_api to test memblock_alloc_raw Rebecca Mckeever
2022-08-14  5:53 ` [PATCH 6/8] memblock tests: update alloc_nid_api to test memblock_alloc_try_nid_raw Rebecca Mckeever
2022-08-16  1:24   ` Huang, Shaoqin
2022-08-14  5:53 ` [PATCH 7/8] memblock tests: add tests for memblock_*bottom_up functions Rebecca Mckeever
2022-08-16  1:46   ` Huang, Shaoqin
2022-08-14  5:54 ` [PATCH 8/8] memblock tests: add tests for memblock_trim_memory Rebecca Mckeever
2022-08-16  1:46   ` Huang, Shaoqin
2022-08-20  8:40     ` Rebecca Mckeever [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220820084026.GA13533@sophie \
    --to=remckee0@gmail.com \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rppt@kernel.org \
    --cc=shaoqin.huang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).