linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add tests for memblock_alloc_node()
@ 2023-01-13 16:01 Claudio Migliorelli
  2023-01-19 12:58 ` Mike Rapoport
  0 siblings, 1 reply; 2+ messages in thread
From: Claudio Migliorelli @ 2023-01-13 16:01 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Rebecca Mckeever, David Hildenbrand, Shaoqin Huang,
	Karolina Drobnik, Claudio Migliorelli, linux-mm, linux-kernel

These tests are aimed at verifying the memblock_alloc_node() to work as expected, so setting the
correct NUMA node for the new allocated region. The memblock_alloc_node() is mimicked by executing
the already implemented test function run_memblock_alloc_try_nid() and by setting the flags used
internally by the memblock_alloc_node(). The core check is between the requested NUMA node and the
`nid` field inside the memblock_region structure. These two are supposed to be equal in order for
the test to succeed.

Signed-off-by: Claudio Migliorelli <claudio.migliorelli@mail.polimi.it>
---
  tools/testing/memblock/tests/alloc_nid_api.c | 43 ++++++++++++++++++++
  1 file changed, 43 insertions(+)

diff --git a/tools/testing/memblock/tests/alloc_nid_api.c b/tools/testing/memblock/tests/alloc_nid_api.c
index 2c2d60f4e3e3..9183e2219c5c 100644
--- a/tools/testing/memblock/tests/alloc_nid_api.c
+++ b/tools/testing/memblock/tests/alloc_nid_api.c
@@ -2483,6 +2483,40 @@ static int alloc_try_nid_numa_split_all_reserved_generic_check(void)
  	return 0;
  }

+/*
+ * A test that tries to allocate a memory region through the
+ * memblock_alloc_node() on a NUMA node with id `nid`. The call to the
+ * memblock_alloc_node() is mimicked using the run_memblock_alloc_try_nid()
+ * with appropriate flags, the same used internally by the memblock_alloc_node().
+ * Expected to have the correct NUMA node set for the new region.
+ */
+static int alloc_node_on_correct_nid_simple_check(void)
+{
+	int nid_req = 2;
+	void *allocated_ptr = NULL;
+#ifdef CONFIG_NUMA
+	struct memblock_region *req_node = &memblock.memory.regions[nid_req];
+#endif
+	phys_addr_t size = SZ_512;
+
+	PREFIX_PUSH();
+	setup_numa_memblock(node_fractions);
+
+	allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
+						   MEMBLOCK_LOW_LIMIT, MEMBLOCK_ALLOC_ACCESSIBLE,
+						   nid_req);
+
+	ASSERT_NE(allocated_ptr, NULL);
+	assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
+#ifdef CONFIG_NUMA
+	ASSERT_EQ(nid_req, req_node->nid);
+#endif
+
+	test_pass_pop();
+
+	return 0;
+}
+
  /* Test case wrappers for NUMA tests */
  static int alloc_try_nid_numa_simple_check(void)
  {
@@ -2621,6 +2655,14 @@ static int alloc_try_nid_numa_split_all_reserved_check(void)
  	return 0;
  }

+static int alloc_try_nid_numa_correct_node_simple_check(void)
+{
+	test_print("\tRunning %s...\n", __func__);
+	alloc_node_on_correct_nid_simple_check();
+
+	return 0;
+}
+
  int __memblock_alloc_nid_numa_checks(void)
  {
  	test_print("Running %s NUMA tests...\n",
@@ -2640,6 +2682,7 @@ int __memblock_alloc_nid_numa_checks(void)
  	alloc_try_nid_numa_large_region_check();
  	alloc_try_nid_numa_reserved_full_merge_check();
  	alloc_try_nid_numa_split_all_reserved_check();
+	alloc_try_nid_numa_correct_node_simple_check();

  	return 0;
  }
-- 
2.39.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Add tests for memblock_alloc_node()
  2023-01-13 16:01 [PATCH] Add tests for memblock_alloc_node() Claudio Migliorelli
@ 2023-01-19 12:58 ` Mike Rapoport
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Rapoport @ 2023-01-19 12:58 UTC (permalink / raw)
  To: Claudio Migliorelli
  Cc: Rebecca Mckeever, David Hildenbrand, Shaoqin Huang,
	Karolina Drobnik, linux-mm, linux-kernel

On Fri, Jan 13, 2023 at 05:01:43PM +0100, Claudio Migliorelli wrote:
> These tests are aimed at verifying the memblock_alloc_node() to work as expected, so setting the
> correct NUMA node for the new allocated region. The memblock_alloc_node() is mimicked by executing
> the already implemented test function run_memblock_alloc_try_nid() and by setting the flags used
> internally by the memblock_alloc_node(). The core check is between the requested NUMA node and the
> `nid` field inside the memblock_region structure. These two are supposed to be equal in order for
> the test to succeed.

We already have tests that verify that verify that NUMA APIs respect nid
parameter, e.g. alloc_nid_numa_simple_check().

If you'd like to add a test that verifies that memblock_alloc_node() works
as expected, don't mimic it, but use it directly.

When posting patches please format the commit log to wrap at 75 columns (see
Documentation/process/submitting-patches.rst) and use recent Linus' tree as
the base.

> Signed-off-by: Claudio Migliorelli <claudio.migliorelli@mail.polimi.it>
> ---
>  tools/testing/memblock/tests/alloc_nid_api.c | 43 ++++++++++++++++++++
>  1 file changed, 43 insertions(+)
> 
> diff --git a/tools/testing/memblock/tests/alloc_nid_api.c b/tools/testing/memblock/tests/alloc_nid_api.c
> index 2c2d60f4e3e3..9183e2219c5c 100644
> --- a/tools/testing/memblock/tests/alloc_nid_api.c
> +++ b/tools/testing/memblock/tests/alloc_nid_api.c
> @@ -2483,6 +2483,40 @@ static int alloc_try_nid_numa_split_all_reserved_generic_check(void)
>  	return 0;
>  }
> 
> +/*
> + * A test that tries to allocate a memory region through the
> + * memblock_alloc_node() on a NUMA node with id `nid`. The call to the
> + * memblock_alloc_node() is mimicked using the run_memblock_alloc_try_nid()
> + * with appropriate flags, the same used internally by the memblock_alloc_node().
> + * Expected to have the correct NUMA node set for the new region.
> + */
> +static int alloc_node_on_correct_nid_simple_check(void)
> +{
> +	int nid_req = 2;
> +	void *allocated_ptr = NULL;
> +#ifdef CONFIG_NUMA
> +	struct memblock_region *req_node = &memblock.memory.regions[nid_req];
> +#endif
> +	phys_addr_t size = SZ_512;
> +
> +	PREFIX_PUSH();
> +	setup_numa_memblock(node_fractions);
> +
> +	allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
> +						   MEMBLOCK_LOW_LIMIT, MEMBLOCK_ALLOC_ACCESSIBLE,
> +						   nid_req);
> +
> +	ASSERT_NE(allocated_ptr, NULL);
> +	assert_mem_content(allocated_ptr, size, alloc_nid_test_flags);
> +#ifdef CONFIG_NUMA
> +	ASSERT_EQ(nid_req, req_node->nid);
> +#endif
> +
> +	test_pass_pop();
> +
> +	return 0;
> +}
> +
>  /* Test case wrappers for NUMA tests */
>  static int alloc_try_nid_numa_simple_check(void)
>  {
> @@ -2621,6 +2655,14 @@ static int alloc_try_nid_numa_split_all_reserved_check(void)
>  	return 0;
>  }
> 
> +static int alloc_try_nid_numa_correct_node_simple_check(void)
> +{
> +	test_print("\tRunning %s...\n", __func__);
> +	alloc_node_on_correct_nid_simple_check();
> +
> +	return 0;
> +}
> +
>  int __memblock_alloc_nid_numa_checks(void)
>  {
>  	test_print("Running %s NUMA tests...\n",
> @@ -2640,6 +2682,7 @@ int __memblock_alloc_nid_numa_checks(void)
>  	alloc_try_nid_numa_large_region_check();
>  	alloc_try_nid_numa_reserved_full_merge_check();
>  	alloc_try_nid_numa_split_all_reserved_check();
> +	alloc_try_nid_numa_correct_node_simple_check();
> 
>  	return 0;
>  }
> -- 
> 2.39.0
> 

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-19 12:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-13 16:01 [PATCH] Add tests for memblock_alloc_node() Claudio Migliorelli
2023-01-19 12:58 ` Mike Rapoport

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).