lib/tst_numa: Add library for NUMA related syscalls
PATCH 1/2 lib/tst_numa: Add library for NUMA related syscalls
The library implements a nodemap, which is a map of nodes (array) containing node ids for a subset of system nodes. Currently nodes can be filtered based on memory requirements, which is needed for testing memory related NUMA syscalls such as set_mempolicy() and membind() where we usually need at least two memory nodes with free memory.
It also implements counters, so that we can precisely count, for a given memory range, how much memory was allocated on each node in the map and a few simple functions for mapping, faulting and unmapping memory.
--- include/tst_numa.h | 112 ++++++++++++++++++++++++ lib/tst_numa.c | 214 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 326 insertions(+) create mode 100644 include/tst_numa.h create mode 100644 lib/tst_numa.c
include/tst_numa.h new file +112 -0
@@ -0,0 +1,112 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* Copyright (c) 2018 Cyril Hrubis <[email protected]> +*/ + +#ifndef TST_NUMA_H__ +#define TST_NUMA_H__ + +/** +* Numa nodemap. +*/ +struct tst_nodemap { +/** Number of nodes in map */ +unsigned int cnt; +/** Page allocation counters */ +unsigned int *counters; +/** Array of numa ids */ +unsigned int map[]; +}; + +/** +* Clears numa counters. The counters are lazy-allocated on first call of this function. +* +* @nodes Numa nodemap. +*/ +void tst_nodemap_reset_counters (struct tst_nodemap *nodes); + +/** +* Prints pages allocated per each node. +* +* @nodes Numa nodemap. +*/ +void tst_nodemap_print_counters (struct tst_nodemap *nodes); + +/** +* Returns a name for a mempolicy/mbind mode. +* +* @mode Numa mempolicy mode. +*/ +const char *tst_numa_mode_name (int mode); + +/** +* Maps pages into memory, if path is NULL the mapping is anonymous otherwise is backed by the file. +* +* @path Path to a file, if not NULL mapping is file based. +* @size Mapping size. +*/ +void *tst_numa_map (const char *path,size_t size); + +/* +* Writes to memory in order to get the pages faulted. +* +* @ptr Start of the mapping. +* @size Size of the mapping. +*/ +static inline void tst_numa_fault (void *ptr,size_t size) +{ +memset (ptr,'a' , size); +} + +/* +* Frees the memory. +* +* @ptr Start of the mapping. +* @size Size of the mapping. +*/ +static inline void tst_numa_unmap (void *ptr,size_t size) +{ +SAFE_MUNMAP (ptr, size); +} + +/** +* Check on which numa node resides each page of the mapping starting at ptr +* and continuing pages long and increases nodemap counters accordingly. +* +* @nodes Nodemap with initialized counters. +* @ptr Pointer to start of a mapping. +* @size Size of the mapping. +*/ +void tst_nodemap_count_pages (struct tst_nodemap *nodes,void *ptr,size_t size); + +/** +* Frees nodemap. +* +* @nodes Numa nodemap to be freed. +*/ +void tst_nodemap_free (struct tst_nodemap *nodes); + +/** +* Bitflags for tst_get_nodemap() function. +*/ +enum tst_numa_types { +TST_NUMA_ANY =0x00 , +TST_NUMA_MEM =0x01 , +}; + +/** +* Allocates and returns numa node map, which is an array of numa nodes which +* contain desired resources e.g. memory. +* +* @type Bitflags of enum tst_numa_types specifying desired resources. +* @min_mem_kb Minimal free RAM on memory nodes, if given node has less than +* requested amount of free+buffers memory it's not included in +* the resulting list of nodes. +* +* @return On success returns allocated and initialized struct tst_nodemap which contains +* array of numa node ids that contains desired resources. +*/ +struct tst_nodemap *tst_get_nodemap (int type,size_t min_mem_kb); + +#endif /* TST_NUMA_H__ */
lib/tst_numa.c new file +214 -0
214 lines not on this page · raw message
Signature · 1 line
2.19.2
[LTP] [COMMITTED] PATCH 2/2] syscalls: Add set_mempolicy numa tests.
This is initial attempt to replace numa.sh tests that despite having been fixed several times have still many shortcommings that wouldn't easy to fix. It's not finished nor 100% replacement at this point but it should be pretty good start.
The main selling points of these testcases are:
The memory allocated for the testing is tracked exactly. We are using get_mempolicy() with MPOL_F_NODE | MPOL_F_ADDR that returns the node ID on which specified address is allocated on to count pages allocated per node after we set desired memory policy.
We also check for free memory on each numa memory mode and skip nodes that don't have sufficient amount of memory for a particular test. The tests checks usuall for twice as much memory per each node in order to allow for allocations to be "misplaced".
The tests for file based shared interleaved mappings are no longer mapping a single small file but rather than that we accumulate statistic for larger amount of files over longer period of time and we also allow for small offset (currently 10%). We should probably also increase the number of samples we take as currently it's about 5MB in total on x86 although I haven't managed to make this test fail so far. This also fixes the test on Btrfs where the synthetic test that expects the pages to be distributed exactly equally fails.
--- runtest/numa | 5 + .../kernel/syscalls/set_mempolicy/.gitignore | 4 + .../kernel/syscalls/set_mempolicy/Makefile | 7 + .../syscalls/set_mempolicy/set_mempolicy.h | 21 +++ .../syscalls/set_mempolicy/set_mempolicy01.c | 120 +++++++++++++++ .../syscalls/set_mempolicy/set_mempolicy02.c | 119 +++++++++++++++ .../syscalls/set_mempolicy/set_mempolicy03.c | 113 ++++++++++++++ .../syscalls/set_mempolicy/set_mempolicy04.c | 142 ++++++++++++++++++ 8 files changed, 531 insertions(+) create mode 100644 testcases/kernel/syscalls/set_mempolicy/.gitignore create mode 100644 testcases/kernel/syscalls/set_mempolicy/Makefile create mode 100644 testcases/kernel/syscalls/set_mempolicy/set_mempolicy.h create mode 100644 testcases/kernel/syscalls/set_mempolicy/set_mempolicy01.c create mode 100644 testcases/kernel/syscalls/set_mempolicy/set_mempolicy02.c create mode 100644 testcases/kernel/syscalls/set_mempolicy/set_mempolicy03.c create mode 100644 testcases/kernel/syscalls/set_mempolicy/set_mempolicy04.c
runtest/numa +5 -0
@@ -11,3 +11,8 @@ move_pages09 move_pages09 move_pages10 move_pages10 move_pages11 move_pages11 move_pages12 move_pages12 + +set_mempolicy01 set_mempolicy01 +set_mempolicy02 set_mempolicy02 +set_mempolicy03 set_mempolicy03 +set_mempolicy04 set_mempolicy04
testcases/kernel/syscalls/set_mempolicy/.gitignore new file +4 -0
@@ -0,0 +1,4 @@ +/set_mempolicy01 +/set_mempolicy02 +/set_mempolicy03 +/set_mempolicy04
testcases/kernel/syscalls/set_mempolicy/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +LDLIBS += $(NUMA_LIBS) + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/set_mempolicy/set_mempolicy.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* Copyright (c) 2018 Cyril Hrubis <[email protected]> +*/ + +#ifndef SET_MEMPOLICY_H__ +#define SET_MEMPOLICY_H__ + +static inline void alloc_fault_count (struct tst_nodemap *nodes, +const char *file,size_t size) +{ +void *ptr; + + ptr =tst_numa_map (file, size); +tst_numa_fault (ptr, size); +tst_nodemap_count_pages (nodes, ptr, size); +tst_numa_unmap (ptr, size); +} + +#endif /* SET_MEMPOLICY_H__ */
testcases/kernel/syscalls/set_mempolicy/set_mempolicy01.c new file +120 -0
120 lines not on this page · raw message
testcases/kernel/syscalls/set_mempolicy/set_mempolicy02.c new file +119 -0
119 lines not on this page · raw message
testcases/kernel/syscalls/set_mempolicy/set_mempolicy03.c new file +113 -0
113 lines not on this page · raw message
testcases/kernel/syscalls/set_mempolicy/set_mempolicy04.c new file +142 -0
142 lines not on this page · raw message
Signature · 1 line
2.19.2
PATCH 1/2 lib/tst_numa: Add library for NUMA related syscalls
In reply to Cyril HrubisHi!
Sigh, looks like this is causing linker failures on some distributions when linker tries to resolve the symbols from tst_numa.c when linking unrelated code against the LTP library. I will look into this.
See:
https://api.travis-ci.org/v3/job/503077808/log.txt
Signature · 2 lines
Cyril Hrubis [email protected]