Add support for a "same" numamask to numactl
PATCH 1/8 Add support for a "same" numamask to numactl
From: Andi Kleen <[email protected]>
With more complicated node masks it gets a bit annoying to type them multiple times, e.g. for -c and -m. Add a "same" alias that just refers to the previous nodemask.
Since this is only well defined on the command line implement it in numactl only.
--- CHANGES | 3 +++ numactl.8 | 4 +++- numactl.c | 22 ++++++++++++++++++---- 4 files changed, 24 insertions(+), 5 deletions(-)
CHANGES +3 -0
@@ -356,3 +356,6 @@ newer: - 110818 Checking of sucessful allocations in numademo (Petr Holasek) 2.0.8-rc2 - 110823 Fix of numactl (--touch) warnings and man page (Cliff W.) + + +- Add "same" nodemask alias to numactl (Andi Kleen)
numactl.8 +3 -1
@@ -95,7 +95,9 @@ may be specifed as +N,N,N or +N-N or +N,N-N and so forth. The + indicates that the node numbers are relative to the process' set of allowed nodes in its current cpuset. A !N-N notation indicates the inverse of N-N, in other words all nodes -except N-N. If used with + notation, specify !+N-N. +except N-N. If used with + notation, specify !+N-N. When +.I same +is specified the previous nodemask specified on the command line is used. .TP .B \-\-membind=nodes, \-m nodes Only allocate memory from nodes. Allocation will fail when there
numactl.c +18 -4
@@ -366,6 +366,20 @@ void check_shmbeyond(char *msg) } } +static struct bitmask *numactl_parse_nodestring (char *s) +{ +static char *last; + +if (s[0 ] =='s' && !strcmp (s,"same" )) { +if (!last) +usage_msg ("same needs previous node specification" ); + s = last; + }else { + last = s; + } +return numa_parse_nodestring (s); +} +int main (int ac,char **av) {int c, i, nnodes=0 ;
@@ -386,7 +400,7 @@ int main(int ac, char **av)exit (0 );case 'i' :/* --interleave */ checknuma (); - mask =numa_parse_nodestring (optarg); + mask =numactl_parse_nodestring (optarg);if (!mask) {printf ("<%s> is invalid\n" , optarg);usage ();
@@ -404,7 +418,7 @@ int main(int ac, char **av)case 'c' :/* --cpubind */ dontshm ("-c/--cpubind/--cpunodebind" );checknuma (); - mask =numa_parse_nodestring (optarg); + mask =numactl_parse_nodestring (optarg);if (!mask) {printf ("<%s> is invalid\n" , optarg);usage ();
@@ -435,7 +449,7 @@ int main(int ac, char **av)case 'm' :/* --membind */ checknuma ();setpolicy (MPOL_BIND ); - mask =numa_parse_nodestring (optarg); + mask =numactl_parse_nodestring (optarg);if (!mask) {printf ("<%s> is invalid\n" , optarg);usage ();
@@ -453,7 +467,7 @@ int main(int ac, char **av)case 'p' :/* --preferred */ checknuma ();setpolicy (MPOL_PREFERRED ); - mask =numa_parse_nodestring (optarg); + mask =numactl_parse_nodestring (optarg);if (!mask) {printf ("<%s> is invalid\n" , optarg);usage ();
PATCH 2/8 Use constructors for numa_init/exit
From: Andi Kleen <[email protected]>
This fixes the static library -- the init code is not called here. So use a constructor. This may lead to the functions being called twice, but we check for that
--- libnuma.c | 27 +++++++++++++++------------ 1 files changed, 15 insertions(+), 12 deletions(-)
libnuma.c +15 -12
@@ -82,11 +82,14 @@ static void set_sizes(void);* * The v1 library depends upon nodemask_t's of all nodes and no nodes. */ -void +void __attribute__((constructor))numa_init (void ) {int max,i; +if (sizes_set) +return ; +set_sizes ();/* numa_all_nodes should represent existing nodes on this system */ max =numa_num_configured_nodes ();
@@ -95,19 +98,19 @@ numa_init(void)memset (&numa_no_nodes,0 ,sizeof (numa_no_nodes)); } -void +#define FREE_AND_ZERO (x) if (x) { \ + numa_bitmask_free(x); \ + x = NULL; \ + } + +void __attribute__((destructor))numa_fini (void ) { -if (numa_all_cpus_ptr) -numa_bitmask_free (numa_all_cpus_ptr); -if (numa_all_nodes_ptr) -numa_bitmask_free (numa_all_nodes_ptr); -if (numa_no_nodes_ptr) -numa_bitmask_free (numa_no_nodes_ptr); -if (numa_memnode_ptr) -numa_bitmask_free (numa_memnode_ptr); -if (numa_nodes_ptr) -numa_bitmask_free (numa_nodes_ptr); +FREE_AND_ZERO (numa_all_cpus_ptr); +FREE_AND_ZERO (numa_all_nodes_ptr); +FREE_AND_ZERO (numa_no_nodes_ptr); +FREE_AND_ZERO (numa_memnode_ptr); +FREE_AND_ZERO (numa_nodes_ptr); }/*
Signature · 1 line
1.7.5.4
PATCH 3/8 Use glibc syscall if possible
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Modern glibcs seem to have a working 6 argument syscall, so use the glibc syscall stub if possible.
--- syscall.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
syscall.c +9 -1
@@ -115,7 +115,15 @@#endif -#if defined(__x86_64__) +#if defined(__GLIBC__) &&__GLIBC_PREREQ (2 ,11 ) + +/* glibc 2.11 seems to have working 6 argument sycall. Use the +glibc supplied syscall in this case. +The version cut-off is rather arbitary and could be probably +earlier. */ + +#define syscall6 syscall +#elif defined(__x86_64__)/* 6 argument calls on x86-64 are often buggy in both glibc and asm/unistd.h. Add a working version here. */ long syscall6 (long call,long a,long b,long c,long d,long e,long f)
Signature · 1 line
1.7.5.4
PATCH 4/8 Run full test suite before exiting
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Show all the problems before exiting in regress1.
--- test/regress | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-)
test/regress +9 -2
@@ -26,6 +26,8 @@ DOUBLEPAGES=$[ $PAGES * 2 ] DOUBLEPAGES=$[ $DOUBLEPAGES - 200 ] NEEDPAGES=$[ $DOUBLEPAGES + $DOUBLEPAGES / 5 ] # 20% spare +EXIT=0 + declare -i maxnode declare -a node
@@ -37,7 +39,7 @@ numactl() { failed() { echo '=======FAILED' echo "Check if machine doesn't have background jobs and try again" - exit 1 + EXIT=1 } # nstat statname node
@@ -203,7 +205,12 @@ main() diff -u A B rm A B - echo '========SUCCESS' + if [ "$EXIT" = 0 ] ; then + echo '========SUCCESS' + else + echo '========FAILURE' + exit 1 + fi } # =========================================================================
Signature · 1 line
1.7.5.4
PATCH 5/8 Add IO affinity support to libnuma
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
This adds new higher level node specifiers to libnuma/numactl. You can specify IO devices and libnuma automatically resolves the underlying device if the kernel knows about it.
For example:
netdev:eth0 node of net device eth0
file:/foo/bar node of block device /foo/bar is on
ip:hostname node of net device the route to hostname is pointing to
block:sda3 node of block device sda3 (as known by the kernel)
pci:0.0.1 node of pci device 0.0.1
There are obvious limits to this: in some cases there's no unique node (like device on RAID). Various IO layers do not export the necessary information to map back to a PCI device And then on many common systems the kernel doesn't actually know the node for a PCI device because of ACPI limitations (but this will hopefully improve).
Still with these caveats it's a useful extension.
--- CHANGES | 1 + Makefile | 25 +++- affinity.c | 343 +++++++++++++++++++++++++++++++++++++++++++++++++++++ affinity.h | 6 + libnuma.c | 22 +++- numactl.8 | 48 ++++++-- numactl.c | 6 + numaint.h | 19 +++ rtnetlink.c | 90 ++++++++++++++ rtnetlink.h | 5 + sysfs.c | 69 +++++++++++ sysfs.h | 4 + test/node-parse.c | 26 ++++ test/regress-io | 46 +++++++ 15 files changed, 685 insertions(+), 25 deletions(-) create mode 100644 affinity.c create mode 100644 affinity.h create mode 100644 rtnetlink.c create mode 100644 rtnetlink.h create mode 100644 sysfs.c create mode 100644 sysfs.h delete mode 100755 test/move_pages create mode 100644 test/node-parse.c create mode 100755 test/regress-io
CHANGES +1 -0
@@ -359,3 +359,4 @@ newer: - Add "same" nodemask alias to numactl (Andi Kleen) +- Add IO affinity support (Andi Kleen)
Makefile +19 -6
@@ -31,10 +31,11 @@ CLEANFILES := numactl.o libnuma.o numactl numademo numademo.o distance.o \ test/after test/before threadtest test_move_pages \ test/mbind_mig_pages test/migrate_pages \ migratepages migspeed migspeed.o libnuma.a \ - test/move_pages test/realloc_test + test/move_pages test/realloc_test sysfs.o affinity.o \ + test/node-parse rtnetlink.o SOURCES := bitops.c libnuma.c distance.c memhog.c numactl.c numademo.c \ numamon.c shm.c stream_lib.c stream_main.c syscall.c util.c mt.c \ - clearcache.c test/*.c + clearcache.c test/*.c affinity.c sysfs.c rtnetlink.c prefix := /usr libdir := ${prefix}/$(shell ./getlibdir)
@@ -43,7 +44,8 @@ docdir := ${prefix}/share/doc all: numactl migratepages migspeed libnuma.so numademo numamon memhog \ test/tshared stream test/mynode test/pagesize test/ftok test/prefered \ test/randmap test/nodemap test/distance test/tbitmap test/move_pages \ - test/mbind_mig_pages test/migrate_pages test/realloc_test libnuma.a + test/mbind_mig_pages test/migrate_pages test/realloc_test libnuma.a \ + test/node-parse numactl: numactl.o util.o shm.o bitops.o libnuma.so
@@ -81,7 +83,7 @@ stream_main.o: stream_main.c libnuma.so.1: versions.ldscript -libnuma.so.1: libnuma.o syscall.o distance.o +libnuma.so.1: libnuma.o syscall.o distance.o affinity.o sysfs.o rtnetlink.o ${CC} ${LDFLAGS} -shared -Wl,-soname=libnuma.so.1 -Wl,--version-script,versions.ldscript -Wl,-init,numa_init -Wl,-fini,numa_fini -o libnuma.so.1 $(filter-out versions.ldscript,$^) libnuma.so: libnuma.so.1
@@ -91,7 +93,7 @@ libnuma.o : CFLAGS += -fPIC AR ?= ar RANLIB ?= ranlib -libnuma.a: libnuma.o syscall.o distance.o +libnuma.a: libnuma.o syscall.o distance.o sysfs.o affinity.o rtnetlink.o $(AR) rc $@ $^ $(RANLIB) $@
@@ -99,6 +101,12 @@ distance.o : CFLAGS += -fPIC syscall.o : CFLAGS += -fPIC +affinity.o : CFLAGS += -fPIC + +sysfs.o : CFLAGS += -fPIC + +rtnetlink.o : CFLAGS += -fPIC + test/tshared: test/tshared.o libnuma.so test/mynode: test/mynode.o libnuma.so
@@ -125,6 +133,8 @@ test/migrate_pages: test/migrate_pages.c libnuma.so test/realloc_test: test/realloc_test.c libnuma.so +test/node-parse: test/node-parse.c libnuma.so util.o + .PHONY: install all clean html depend MANPAGES := numa.3 numactl.8 numastat.8 migratepages.8 migspeed.8
@@ -190,4 +200,7 @@ regress1: regress2: cd test ; ./regress2 -test: all regress1 regress2 test_numademo +regress3: + cd test ; ./regress-io + +test: all regress1 regress2 test_numademo regress3
affinity.c new file +343 -0
343 lines not on this page · raw message
affinity.h new file +6 -0
@@ -0,0 +1,6 @@ +enum { +NO_IO_AFFINITY =-2 +}; + +int resolve_affinity (char *id,struct bitmask *mask); +
libnuma.c +17 -5
@@ -35,6 +35,7 @@#include "numaif.h" #include "numaint.h" #include "util.h" +#include "affinity.h" #define WEAK __attribute__((weak))
@@ -1776,12 +1777,23 @@ numa_parse_nodestring(char *s) s++; } do { - int i; unsigned long arg; - if (!strcmp(s,"all")) { - copy_bitmask_to_bitmask(numa_all_nodes_ptr, mask); - s+=4; - break; + int i; + if (isalpha(*s)) { + int n; + if (!strcmp(s,"all")) { + copy_bitmask_to_bitmask(numa_all_nodes_ptr, + mask); + s+=4; + break; + } + n = resolve_affinity(s, mask); + if (n != NO_IO_AFFINITY) { + if (n < 0) + goto err; + s += strlen(s) + 1; + break; + } } arg = get_nr(s, &end, numa_all_nodes_ptr, relative); if (end == s) {
numactl.8 +34 -14
73 lines not on this page · raw message
numactl.c +6 -0
@@ -73,6 +73,12 @@ void usage(void)"\n" "memory policy is --interleave, --preferred, --membind, --localalloc\n" "nodes is a comma delimited list of node numbers or A-B ranges or all.\n" +"Instead of a number a node can also be:\n" +" netdev:DEV the node connected to network device DEV\n" +" file:PATH the node the block device of path is connected to\n" +" ip:HOST the node of the network device host routes through\n" +" block:PATH the node of block device path\n" +" pci:[seg:]bus:dev[:func] The node of a PCI device\n" "cpus is a comma delimited list of cpu numbers or A-B ranges or all\n" "all ranges can be inverted with !\n" "all numbers and ranges can be made cpuset-relative with +\n"
numaint.h +19 -0
@@ -16,6 +16,7 @@ extern int numa_sched_getaffinity_v2_int(pid_t pid, struct bitmask *mask);#define CPU_LONGS (x) (CPU_BYTES(x) / sizeof(long))#define make_internal_alias (x) extern __typeof (x) x##_int __attribute((alias(#x), visibility("hidden"))) +#define hidden __attribute__((visibility("hidden")))enum numa_warn { W_nosysfs,
@@ -29,6 +30,24 @@ enum numa_warn { W_memory, W_cpuparse, W_nodeparse, + W_blockdev1, + W_blockdev2, + W_blockdev3, + W_blockdev4, + W_blockdev5, + W_netlink1, + W_netlink2, + W_netlink3, + W_net1, + W_net2, + W_class1, + W_class2, + W_pci1, + W_pci2, + W_node_parse1, + W_node_parse2, + W_nonode, + W_badchar, };#define howmany (x,y) (((x)+((y)-1))/(y))
rtnetlink.c new file +90 -0
90 lines not on this page · raw message
rtnetlink.h new file +5 -0
@@ -0,0 +1,5 @@ +hidden int +rta_put_address (struct nlmsghdr *msg,int type,struct sockaddr *adr); +hidden struct rtattr *rta_get(struct nlmsghdr *m, struct rtattr *p, int offset); +hidden void *rta_put(struct nlmsghdr *m, int type, int len); +hidden int rtnetlink_request(struct nlmsghdr *msg, int buflen, struct sockaddr_nl *adr);
sysfs.c new file +69 -0
69 lines not on this page · raw message
sysfs.h new file +4 -0
@@ -0,0 +1,4 @@ +struct bitmask ; +hidden char *sysfs_read(char *name); +hidden int sysfs_node_read(struct bitmask *mask, char *fmt, ...); +
test/node-parse.c new file +26 -0
@@ -0,0 +1,26 @@ +/* Test wrapper for the nodemask parser */ +#include <stdio.h> +#include "numa.h" +#include "util.h" + +/* For util.c. Fixme. */ +void usage (void ) +{ +exit (1 ); +} + +int main (int ac,char **av) +{ +int err =0 ; +while (*++av) { +struct bitmask *mask =numa_parse_nodestring (*av); +if (!mask) { +printf ("Failed to convert `%s'\n" , *av); + err |=1 ; +continue ; + } +printmask ("result" , mask); +numa_bitmask_free (mask); + } +return err; +}
test/regress-io new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
1.7.5.4
PATCH 6/8 Clean regression test temp files
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
--- Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
@@ -32,7 +32,7 @@ CLEANFILES := numactl.o libnuma.o numactl numademo numademo.o distance.o \ test/mbind_mig_pages test/migrate_pages \ migratepages migspeed migspeed.o libnuma.a \ test/move_pages test/realloc_test sysfs.o affinity.o \ - test/node-parse rtnetlink.o + test/node-parse rtnetlink.o test/A SOURCES := bitops.c libnuma.c distance.c memhog.c numactl.c numademo.c \ numamon.c shm.c stream_lib.c stream_main.c syscall.c util.c mt.c \ clearcache.c test/*.c affinity.c sysfs.c rtnetlink.c
Signature · 1 line
1.7.5.4
PATCH 7/8 memhog: add option to disable transparent huge pages
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Transparent Hugepages confuse the page accounting in the test suite. Add an option to memhog (-H) to disable them.
--- memhog.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
memhog.c +9 -0
@@ -20,6 +20,7 @@#include <sys/mman.h> #include <sys/fcntl.h> #include <string.h> +#include <stdbool.h> #include "numa.h" #include "numaif.h" #include "util.h"
@@ -37,6 +38,7 @@ void usage(void) {printf ("memhog [-rNUM] size[kmg] [policy [nodeset]]\n" );printf ("-rNUM repeat memset NUM times\n" ); +printf ("-H disable transparent hugepages\n" );print_policies ();exit (1 ); }
@@ -66,6 +68,7 @@ int main(int ac, char **av)int loose =0 ;int i;int fd =-1 ; +bool disable_hugepage = false; nodes =numa_allocate_nodemask (); gnodes =numa_allocate_nodemask ();
@@ -80,6 +83,9 @@ int main(int ac, char **av)case 'r' : repeat =atoi (av[1 ] +2 );break ; +case 'H' : + disable_hugepage = true; +break ;default :usage (); }
@@ -113,6 +119,9 @@ int main(int ac, char **av)if (mbind (map, length, policy, nodes->maskp, nodes->size,0 ) <0 )terr ("mbind" ); + +if (disable_hugepage) +madvise (map, length,MADV_NOHUGEPAGE ); gpolicy =-1 ;if (get_mempolicy (&gpolicy, gnodes->maskp, gnodes->size, map,MPOL_F_ADDR ) <0 )
Signature · 1 line
1.7.5.4
PATCH 8/8 Disable transparent huge pages in test suite
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
This fixes the test suite on systems that force THP, because the node hit accounting cannot deal with large pages.
--- test/regress | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
test/regress +4 -4
@@ -79,8 +79,8 @@ probe_hardware() # ========================================================================= _test_process_state() { - echo '=>testing numactl' "$@" "memhog $SIZE" - numactl "$@" memhog $SIZE || failed + echo '=>testing numactl' "$@" "memhog -H $SIZE" + numactl "$@" memhog -H $SIZE || failed } test_process_state()
@@ -132,8 +132,8 @@ test_process_state() # test mbind _test_mbind() { - echo '=>testing memhog' "$@" - memhog $SIZE "$@" || failed + echo '=>testing memhog -H' "$@" + memhog -H $SIZE "$@" || failed } test_mbind()
Signature · 1 line
1.7.5.4
numactl/libnuma 2.0.8-rc3
In reply to Andi KleenAll 8 of Andi's recent patches are in numactl-2.0.8-rc3.tar.gz
(ftp://oss.sgi.com/www/projects/libnuma/download/)
2.0.8-rc3
- 111214 Add "same" nodemask alias to numactl (Andi Kleen)
- 111214 Add constructors for numa_init/exit (Andi Kleen)
- 111214 Add use of glibc syscall stub where possible (Andi Kleen)
- 111214 Fix regress1 to show all the problems before exiting (Andi Kleen)
- 111214 Add IO affinity support (Andi Kleen)
- 111214 Clean regression test temp files (Andi Kleen)
- 111214 Add an option to memhog to disable transparent huge pages (Andi Kleen)
- 111214 Fix the test suite on systems that force THP, disable them (Andi Kleen)
Andi welcomes further testing.
-Cliff
Signature · 4 lines
Cliff Wickman SGI [email protected] (651) 683-3824