Compare commits
10 Commits
a9ec9b71cf
...
43324c9544
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43324c9544 | ||
|
|
8e38f39b5e | ||
|
|
9b7875fd69 | ||
|
|
68883f1f88 | ||
|
|
bdd3e299b4 | ||
|
|
f7bc85f23b | ||
|
|
0c9136a214 | ||
|
|
728a187a22 | ||
|
|
4e291aa446 | ||
|
|
ce3056a463 |
147
0008-numastat-Update-system-hugepages-memory-info-from-sy.patch
Normal file
147
0008-numastat-Update-system-hugepages-memory-info-from-sy.patch
Normal file
@ -0,0 +1,147 @@
|
||||
From 248823314e04437aa85a159d4b532ed544d361f8 Mon Sep 17 00:00:00 2001
|
||||
From: Chunsheng Luo <luochunsheng@huawei.com>
|
||||
Date: Mon, 12 Dec 2022 12:02:36 +0800
|
||||
Subject: [PATCH] numastat: Update system hugepages memory info from
|
||||
sysfs/node/hugepages directory
|
||||
|
||||
`numastat -m` gets hugepages memory just from /sys/devices/system/node/node$/meminfo,
|
||||
it is not the entire hugepages memory of the system, just the default huge page.
|
||||
|
||||
Update the entire hugepages memory information from the /sys/devices/system/node/node$/hugepages directory.
|
||||
|
||||
Signed-off-by: buque <wuxu.wu@huawei.com>
|
||||
---
|
||||
numastat.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
|
||||
1 file changed, 95 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/numastat.c b/numastat.c
|
||||
index 6a922f3..cc2249f 100644
|
||||
--- a/numastat.c
|
||||
+++ b/numastat.c
|
||||
@@ -41,6 +41,9 @@ end of this file.
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
+#include <dirent.h>
|
||||
+#include <sys/stat.h>
|
||||
+#include <errno.h>
|
||||
|
||||
#define STRINGIZE(s) #s
|
||||
#define STRINGIFY(s) STRINGIZE(s)
|
||||
@@ -50,6 +53,8 @@ end of this file.
|
||||
|
||||
#define BUF_SIZE 2048
|
||||
#define SMALL_BUF_SIZE 128
|
||||
+#define PATH_LEN 128
|
||||
+#define DNAME_LEN 64
|
||||
|
||||
// Don't assume nodes are sequential or contiguous.
|
||||
// Need to discover and map node numbers.
|
||||
@@ -794,6 +799,88 @@ static char *command_name_for_pid(int pid)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+/* update hugepages info from /sys/devices/system/node/node$/hugepages/hugepages-$ */
|
||||
+static double update_hugepages_info(int node_ix, const char *token)
|
||||
+{
|
||||
+ char *fname;
|
||||
+ DIR *d = NULL;
|
||||
+ struct dirent *dp = NULL;
|
||||
+ struct stat st;
|
||||
+ char top_path[64];
|
||||
+
|
||||
+ if (!strncmp(token, "HugePages_Total", 15)) {
|
||||
+ fname = "nr_hugepages";
|
||||
+ } else if(!strncmp(token, "HugePages_Free", 14)) {
|
||||
+ fname = "free_hugepages";
|
||||
+ } else if (!strncmp(token, "HugePages_Surp", 14)) {
|
||||
+ fname = "surplus_hugepages";
|
||||
+ } else {
|
||||
+ return -EINVAL;
|
||||
+ }
|
||||
+
|
||||
+ snprintf(top_path, sizeof(top_path), "/sys/devices/system/node/node%d/hugepages", node_ix);
|
||||
+
|
||||
+ if(stat(top_path, &st) < 0 || !S_ISDIR(st.st_mode)) {
|
||||
+ printf("invalid path: %s\n", top_path);
|
||||
+ return -ENOENT;
|
||||
+ }
|
||||
+
|
||||
+ if(!(d = opendir(top_path))) {
|
||||
+ fprintf(stderr, "opendir[%s] error: %s\n", top_path, strerror(errno));
|
||||
+ return -ENOENT;
|
||||
+ }
|
||||
+
|
||||
+ const char *delimiters = "-";
|
||||
+ double total = 0;
|
||||
+ char *huge_dname;
|
||||
+ char *fpath;
|
||||
+ char *buf;
|
||||
+
|
||||
+ huge_dname = (char *)malloc(DNAME_LEN);
|
||||
+ fpath = (char *)malloc(PATH_LEN);
|
||||
+ buf = (char *)malloc(SMALL_BUF_SIZE);
|
||||
+
|
||||
+ /* Traversing directories /sys/devices/system/node/node%d/hugepages */
|
||||
+ while((dp = readdir(d)) != NULL) {
|
||||
+ if((!strncmp(dp->d_name, ".", 1)) || (!strncmp(dp->d_name, "..", 2)))
|
||||
+ continue;
|
||||
+
|
||||
+ if ((dp->d_type != DT_DIR) || strncmp(dp->d_name, "hugepages-", 10))
|
||||
+ continue;
|
||||
+
|
||||
+ /* Get huge pages size from d_name d_name: example hugepages-1048576kB */
|
||||
+ memset(huge_dname, 0, DNAME_LEN);
|
||||
+ memcpy(huge_dname, dp->d_name, strlen(dp->d_name));
|
||||
+
|
||||
+ /* Example: /sys/devices/system/node/node%d/hugepages/hugepages-1048576kB/nr_hugepages */
|
||||
+ snprintf(fpath, PATH_LEN, "%s/%s/%s", top_path, huge_dname, fname);
|
||||
+
|
||||
+ char *pagesz_str = strtok(huge_dname, delimiters);
|
||||
+ pagesz_str = strtok(NULL, pagesz_str);
|
||||
+ memset(strstr(pagesz_str, "kB"), 0, 2);
|
||||
+ unsigned long hugepage_size = strtol(pagesz_str, NULL, 10);
|
||||
+ hugepage_size *= KILOBYTE;
|
||||
+
|
||||
+ /* Get the number of pages */
|
||||
+ FILE *fs = fopen(fpath, "r");
|
||||
+ if (!fs) {
|
||||
+ printf("cannot open %s: %s\n", fpath, strerror(errno));
|
||||
+ continue;
|
||||
+ }
|
||||
+ fgets(buf, SMALL_BUF_SIZE, fs);
|
||||
+ unsigned long nr_pages = strtol(buf, NULL, 10);
|
||||
+ fclose(fs);
|
||||
+
|
||||
+ total += nr_pages * hugepage_size;
|
||||
+ }
|
||||
+ closedir(d);
|
||||
+ free(huge_dname);
|
||||
+ free(fpath);
|
||||
+ free(buf);
|
||||
+
|
||||
+ return total;
|
||||
+}
|
||||
+
|
||||
static void show_info_from_system_file(char *file, meminfo_p meminfo, int meminfo_rows, int tok_offset)
|
||||
{
|
||||
// Setup and init table
|
||||
@@ -873,7 +960,14 @@ static void show_info_from_system_file(char *file, meminfo_p meminfo, int meminf
|
||||
if (tokens < 4) {
|
||||
multiplier = page_size_in_bytes;
|
||||
} else if (!strncmp("HugePages", tok[2], 9)) {
|
||||
- multiplier = huge_page_size_in_bytes;
|
||||
+ /* update hugepages info more detail from sysfs/hugepages directory */
|
||||
+ double new = update_hugepages_info(node_ix_map[node_ix], tok[2]);
|
||||
+ if (new > 0) {
|
||||
+ value = new;
|
||||
+ } else {
|
||||
+ /* fall back old way */
|
||||
+ multiplier = huge_page_size_in_bytes;
|
||||
+ }
|
||||
} else if (!strncmp("kB", tok[4], 2)) {
|
||||
multiplier = KILOBYTE;
|
||||
}
|
||||
--
|
||||
2.33.0
|
||||
|
||||
41
0009-riscv64-remove-flag-latomic.patch
Normal file
41
0009-riscv64-remove-flag-latomic.patch
Normal file
@ -0,0 +1,41 @@
|
||||
From a37ca95db184fb97c55a294449fe7622a5aecdda Mon Sep 17 00:00:00 2001
|
||||
From: laokz <zhangkai@iscas.ac.cn>
|
||||
Date: Tue, 18 Jul 2023 19:37:14 +0800
|
||||
Subject: [PATCH] riscv64: remove flag -latomic
|
||||
|
||||
Because openEuler gcc already support inline subword atomic
|
||||
for RISC-V, remove the redundant flag.
|
||||
---
|
||||
Makefile.am | 3 ---
|
||||
Makefile.in | 1 -
|
||||
2 files changed, 4 deletions(-)
|
||||
|
||||
diff --git a/Makefile.am b/Makefile.am
|
||||
index d64df5d..ba6cd48 100644
|
||||
--- a/Makefile.am
|
||||
+++ b/Makefile.am
|
||||
@@ -41,9 +41,6 @@ memhog_LDADD = libnuma.la
|
||||
|
||||
libnuma_la_SOURCES = libnuma.c syscall.c distance.c affinity.c affinity.h sysfs.c sysfs.h rtnetlink.c rtnetlink.h versions.ldscript
|
||||
libnuma_la_LDFLAGS = -version-info 1:0:0 -Wl,--version-script,$(srcdir)/versions.ldscript -Wl,-init,numa_init -Wl,-fini,numa_fini
|
||||
-if RISCV64
|
||||
-libnuma_la_LDFLAGS += -latomic
|
||||
-endif
|
||||
|
||||
check_PROGRAMS = \
|
||||
test/distance \
|
||||
diff --git a/Makefile.in b/Makefile.in
|
||||
index 8cbad1c..a196ea0 100644
|
||||
--- a/Makefile.in
|
||||
+++ b/Makefile.in
|
||||
@@ -95,7 +95,6 @@ target_triplet = @target@
|
||||
bin_PROGRAMS = numactl$(EXEEXT) numastat$(EXEEXT) numademo$(EXEEXT) \
|
||||
migratepages$(EXEEXT) migspeed$(EXEEXT) memhog$(EXEEXT)
|
||||
@HAVE_TREE_VECTORIZE_TRUE@am__append_1 = -ftree-vectorize
|
||||
-@RISCV64_TRUE@am__append_2 = -latomic
|
||||
check_PROGRAMS = test/distance$(EXEEXT) test/ftok$(EXEEXT) \
|
||||
test/mbind_mig_pages$(EXEEXT) test/migrate_pages$(EXEEXT) \
|
||||
test/move_pages$(EXEEXT) test/mynode$(EXEEXT) \
|
||||
--
|
||||
2.40.1
|
||||
|
||||
27
0010-fix-fix-memory-leaks-when-run-with-H.patch
Normal file
27
0010-fix-fix-memory-leaks-when-run-with-H.patch
Normal file
@ -0,0 +1,27 @@
|
||||
From 8daaae302b214539bba6b002c7c40b700ddcdc4b Mon Sep 17 00:00:00 2001
|
||||
From: will_niutao <vincenttom@users.noreply.github.com>
|
||||
Date: Thu, 24 Aug 2023 11:08:23 +0800
|
||||
Subject: [PATCH] fix: fix memory leaks when run with -H
|
||||
|
||||
Conflict: NA
|
||||
Reference: https://github.com/numactl/numactl/commit/8daaae302b214539bba6b002c7c40b700ddcdc4b
|
||||
---
|
||||
numactl.c | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/numactl.c b/numactl.c
|
||||
index 47cbf39..562f319 100755
|
||||
--- a/numactl.c
|
||||
+++ b/numactl.c
|
||||
@@ -242,6 +242,8 @@ static void print_node_cpus(int node)
|
||||
printf(" %d", i);
|
||||
}
|
||||
putchar('\n');
|
||||
+
|
||||
+ numa_free_cpumask(cpus);
|
||||
}
|
||||
|
||||
static void hardware(void)
|
||||
--
|
||||
2.39.3
|
||||
|
||||
49
0011-libnuma-Fix-unexpected-output.patch
Normal file
49
0011-libnuma-Fix-unexpected-output.patch
Normal file
@ -0,0 +1,49 @@
|
||||
From e763e8c86d9f10761a75c2be8510a79f25d63831 Mon Sep 17 00:00:00 2001
|
||||
From: Chunsheng Luo <luochunsheng@ustc.edu>
|
||||
Date: Thu, 25 Jan 2024 23:54:56 +0800
|
||||
Subject: [PATCH] libnuma: Fix unexpected output
|
||||
|
||||
When errno is 0, numa_error(__FILE__) will print "xx: Success",
|
||||
which is not as expected
|
||||
|
||||
Signed-off-by: Chunsheng Luo <luochunsheng@ustc.edu>
|
||||
Reported-by: Ajay Panyala
|
||||
|
||||
Conflict: NA
|
||||
Reference:https://github.com/numactl/numactl/commit/e763e8c86d9f10761a75c2be8510a79f25d63831
|
||||
---
|
||||
libnuma.c | 9 +++++++--
|
||||
1 file changed, 7 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/libnuma.c b/libnuma.c
|
||||
index 8b07ab0..e898297 100644
|
||||
--- a/libnuma.c
|
||||
+++ b/libnuma.c
|
||||
@@ -1882,8 +1882,10 @@ static struct bitmask *__numa_preferred(void)
|
||||
policy != MPOL_BIND)
|
||||
return bmp;
|
||||
|
||||
- if (numa_bitmask_weight(bmp) > 1)
|
||||
+ if (numa_bitmask_weight(bmp) > 1) {
|
||||
+ errno = EINVAL;
|
||||
numa_error(__FILE__);
|
||||
+ }
|
||||
|
||||
return bmp;
|
||||
}
|
||||
@@ -1903,8 +1905,11 @@ int numa_preferred(void)
|
||||
static void __numa_set_preferred(struct bitmask *bmp)
|
||||
{
|
||||
int nodes = numa_bitmask_weight(bmp);
|
||||
- if (nodes > 1)
|
||||
+ if (nodes > 1) {
|
||||
+ errno = EINVAL;
|
||||
numa_error(__FILE__);
|
||||
+ }
|
||||
+
|
||||
setpol(nodes ? MPOL_PREFERRED : MPOL_LOCAL, bmp);
|
||||
}
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
From 00dd4c32240694ae8619ed5445e4ffbc463f8eb0 Mon Sep 17 00:00:00 2001
|
||||
From: Chunsheng Luo <luochunsheng@ustc.edu>
|
||||
Date: Fri, 26 Jan 2024 00:30:13 +0800
|
||||
Subject: [PATCH] libnuma: Fix incorrect print and exit of numa_preferred/_many
|
||||
APIs
|
||||
|
||||
Only when policy is preferred, numa_bitmask_weight will be judged,
|
||||
because mbind and preferred_many support multiple nodes.
|
||||
|
||||
fixes: 87c6834("libnuma: Convert preferred node into a mask")
|
||||
|
||||
Signed-off-by: Chunsheng Luo <luochunsheng@ustc.edu>
|
||||
|
||||
Conflict: NA
|
||||
Reference: https://github.com/numactl/numactl/commit/00dd4c32240694ae8619ed5445e4ffbc463f8eb0
|
||||
---
|
||||
libnuma.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/libnuma.c b/libnuma.c
|
||||
index e898297..ef93558 100644
|
||||
--- a/libnuma.c
|
||||
+++ b/libnuma.c
|
||||
@@ -1882,7 +1882,7 @@ static struct bitmask *__numa_preferred(void)
|
||||
policy != MPOL_BIND)
|
||||
return bmp;
|
||||
|
||||
- if (numa_bitmask_weight(bmp) > 1) {
|
||||
+ if (policy == MPOL_PREFERRED && numa_bitmask_weight(bmp) > 1) {
|
||||
errno = EINVAL;
|
||||
numa_error(__FILE__);
|
||||
}
|
||||
--
|
||||
2.27.0
|
||||
|
||||
26
0013-fix-the-using-of-the-uninitialized-value.patch
Normal file
26
0013-fix-the-using-of-the-uninitialized-value.patch
Normal file
@ -0,0 +1,26 @@
|
||||
From 119eb590f5f0b89611d46cdec805b22767f8a6c0 Mon Sep 17 00:00:00 2001
|
||||
From: Pingfan Liu <piliu@redhat.com>
|
||||
Date: Wed, 17 Apr 2024 10:36:34 +0800
|
||||
Subject: [PATCH] numademo: Fix the using of the uninitialized value
|
||||
|
||||
Signed-off-by: Pingfan Liu <piliu@redhat.com>
|
||||
---
|
||||
numademo.c | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/numademo.c b/numademo.c
|
||||
index 374afd3..8886d7f 100644
|
||||
--- a/numademo.c
|
||||
+++ b/numademo.c
|
||||
@@ -248,6 +248,8 @@ static void memtest(char *name, unsigned char *mem)
|
||||
|
||||
#endif
|
||||
default:
|
||||
+ gettimeofday(&start,NULL);
|
||||
+ gettimeofday(&end,NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
23
numactl.spec
23
numactl.spec
@ -1,6 +1,6 @@
|
||||
Name: numactl
|
||||
Version: 2.0.16
|
||||
Release: 6
|
||||
Release: 11
|
||||
Summary: Library for tuning for Non Uniform Memory Access machines
|
||||
License: GPLv2
|
||||
URL: https://github.com/numactl/numactl
|
||||
@ -14,6 +14,12 @@ Patch0004: 0004-fix-wrong-nodemask_sz-when-CONFIG_NODES_SHIFT-is-les.patch
|
||||
Patch0005: 0005-numactl.c-Remove-unused-variable.patch
|
||||
Patch0006: 0006-numactl.c-Fix-merging-of-neighboring-pages-policies-.patch
|
||||
Patch0007: 0007-shm.c-Replace-stat64-fstat64-ftruncate64mmap64-with-.patch
|
||||
Patch0008: 0008-numastat-Update-system-hugepages-memory-info-from-sy.patch
|
||||
Patch0009: 0009-riscv64-remove-flag-latomic.patch
|
||||
Patch0010: 0010-fix-fix-memory-leaks-when-run-with-H.patch
|
||||
Patch0011: 0011-libnuma-Fix-unexpected-output.patch
|
||||
Patch0012: 0012-libnuma-Fix-incorrect-print-and-exit-of-numa_preferr.patch
|
||||
Patch0013: 0013-fix-the-using-of-the-uninitialized-value.patch
|
||||
|
||||
%description
|
||||
Simple NUMA policy support. It consists of a numactl program to run other
|
||||
@ -82,6 +88,21 @@ LD_LIBRARY_PATH=$(pwd)/.libs make check
|
||||
%{_mandir}/man3/*.3*
|
||||
|
||||
%changelog
|
||||
* Tue Jul 2 2024 zhangyaqi <zhangyaqi@kylinos.cn> - 2.0.16-11
|
||||
- numademo: Fix the using of the uninitialized value
|
||||
|
||||
* Tue Apr 16 2024 zhangnaichuan <zhangnaichuan@huawei.com> - 2.0.16-10
|
||||
- libnuma: Fix incorrect print and exit of numa_preferred/_many APIs
|
||||
|
||||
* Tue Dec 19 2023 chenhaixiang <chenhaixiang3@huawei.com> - 2.0.16-9
|
||||
- fix: fix memory leaks when run with -H
|
||||
|
||||
* Wed Jul 19 2023 laokz <zhangkai@iscas.ac.cn> - 2.0.16-8
|
||||
- Makefile: remove redundant -latomic flag for riscv64
|
||||
|
||||
* Sun Jun 25 2023 wuxu <wuxu.wu@huawei.com> - 2.0.16-7
|
||||
- numastat: Update system hugepages memory info from sysfs/node/hugepages directory
|
||||
|
||||
* Tue Jun 20 2023 wuxu <wuxu.wu@huawei.com> - 2.0.16-6
|
||||
- shm.c: Replace stat64/fstat64/ftruncate64mmap64 with normal functions
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user