Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
f354747fbf
!72 [sync] PR-71: Fix the using of the uninitialized value
From: @openeuler-sync-bot 
Reviewed-by: @liqingqing_1229 
Signed-off-by: @liqingqing_1229
2024-11-06 06:44:59 +00:00
zhangyaqi
78d3763110 fix the using of the uninitialized value
(cherry picked from commit 99562889c57ca02e045ecdcbb8923957fa0bf890)
2024-11-06 14:44:26 +08:00
openeuler-ci-bot
cbc1427037
!70 [sync] PR-57: libnuma: Fix incorrect print and exit of numa_preferred/_many APIs
From: @openeuler-sync-bot 
Reviewed-by: @liqingqing_1229 
Signed-off-by: @liqingqing_1229
2024-11-05 02:48:03 +00:00
zhangnaichuan
69b931e507 libnuma: Fix incorrect print and exit of numa_preferred/_many APIs
(cherry picked from commit 4dc8519db2ea00d906fbd537a47fbf2f3803244e)
2024-11-05 10:46:57 +08:00
openeuler-ci-bot
b3942a024b
!51 [sync] PR-48: numactl: fix memory leaks when run with -H
From: @openeuler-sync-bot 
Reviewed-by: @wangbin224 
Signed-off-by: @wangbin224
2023-12-19 06:52:56 +00:00
chenhaixiang
3f8e82e282 numactl: fix memory leaks when run with -H
signed-off-by:chenhaixiang3@huawei.com
(cherry picked from commit 6cde2a7ea4f1880d1ab0d2f81cd6814bb107e05a)
2023-12-19 14:21:13 +08:00
openeuler-ci-bot
2c7bd69740
!43 [sync] PR-38: [PATCH] numastat: Update system hugepages memory info from sysfs/node/hugepages directory
From: @openeuler-sync-bot 
Reviewed-by: @liqingqing_1229 
Signed-off-by: @liqingqing_1229
2023-11-27 11:04:25 +00:00
buque
537ba4dda0 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.

(cherry picked from commit 0bd4d6897b2d2dc6e26e2f71729869127dc42945)
2023-11-27 18:38:27 +08:00
openeuler-ci-bot
284efad5dc
!35 shm.c: Replace stat64/fstat64/ftruncate64mmap64 with normal functions
From: @wuxu_buque_admin 
Reviewed-by: @yang_yanchao 
Signed-off-by: @yang_yanchao
2023-06-20 11:23:29 +00:00
buque
10505fadfa shm.c: Replace stat64/fstat64/ftruncate64mmap64 with normal functions
These functions were needed when _FILE_OFFSET_BITS was not 64, using
AC_SYS_LARGEFILE will detect it correctly and make the normal variants
of these functions behave same as their *64 counterparts.

Signed-off-by: buque <wuxu.wu@huawei.com>
2023-06-20 19:02:34 +08:00
7 changed files with 374 additions and 1 deletions

View File

@ -0,0 +1,68 @@
From 851bbd5b963a7a5d95b8fe3102cf05972dc72655 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Thu, 15 Dec 2022 12:11:13 -0800
Subject: [PATCH] shm.c: Replace stat64/fstat64/ftruncate64mmap64 with normal
functions
These functions were needed when _FILE_OFFSET_BITS was not 64, using
AC_SYS_LARGEFILE will detect it correctly and make the normal variants
of these functions behave same as their *64 counterparts.
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: buque <wuxu.wu@huawei.com>
---
shm.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/shm.c b/shm.c
index 20537d9..5d0d1ab 100644
--- a/shm.c
+++ b/shm.c
@@ -24,8 +24,8 @@
#include <sys/mman.h>
#include <sys/ipc.h>
#include <sys/shm.h>
-#include <sys/fcntl.h>
#include <sys/stat.h>
+#include <fcntl.h>
#include <stdarg.h>
#include <errno.h>
#include <unistd.h>
@@ -135,7 +135,7 @@ void attach_sysvshm(char *name, char *opt)
/* Attach a shared memory file. */
void attach_shared(char *name, char *opt)
{
- struct stat64 st;
+ struct stat st;
shmfd = open(name, O_RDWR);
if (shmfd < 0) {
@@ -146,14 +146,14 @@ void attach_shared(char *name, char *opt)
if (shmfd < 0)
nerror("cannot create file %s", name);
}
- if (fstat64(shmfd, &st) < 0)
+ if (fstat(shmfd, &st) < 0)
err("shm stat");
/* the file size must be larger than mmap shmlen + shmoffset, otherwise SIGBUS
* will be caused when we access memory, because mmaped memory is no longer in
* the range of the file laster.
*/
if ((shmlen + shmoffset) > st.st_size) {
- if (ftruncate64(shmfd, shmlen + shmoffset) < 0) {
+ if (ftruncate(shmfd, shmlen + shmoffset) < 0) {
/* XXX: we could do it by hand, but it would it
would be impossible to apply policy then.
need to fix that in the kernel. */
@@ -168,7 +168,7 @@ void attach_shared(char *name, char *opt)
/* RED-PEN For shmlen > address space may need to map in pieces.
Left for some poor 32bit soul. */
- shmptr = mmap64(NULL, shmlen, PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, shmoffset);
+ shmptr = mmap(NULL, shmlen, PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, shmoffset);
if (shmptr == (char*)-1)
err("shm mmap");
}
--
2.33.0

View 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

View 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

View 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

View File

@ -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

View 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

View File

@ -1,6 +1,6 @@
Name: numactl
Version: 2.0.16
Release: 5
Release: 10
Summary: Library for tuning for Non Uniform Memory Access machines
License: GPLv2
URL: https://github.com/numactl/numactl
@ -13,6 +13,12 @@ Patch0003: 0003-numactl-numactl-length-xxx-shm-xxx-px-doesn-t-work.patch
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-fix-fix-memory-leaks-when-run-with-H.patch
Patch0010: 0010-libnuma-Fix-unexpected-output.patch
Patch0011: 0011-libnuma-Fix-incorrect-print-and-exit-of-numa_preferr.patch
Patch0012: 0012-fix-the-using-of-the-uninitialized-value.patch
%description
Simple NUMA policy support. It consists of a numactl program to run other
@ -81,6 +87,21 @@ LD_LIBRARY_PATH=$(pwd)/.libs make check
%{_mandir}/man3/*.3*
%changelog
* Wed Nov 6 2024 zhangyaqi <zhangyaqi@kylinos.cn> - 2.0.16-10
- numademo: Fix the using of the uninitialized value
* Tue Apr 16 2024 zhangnaichuan <zhangnaichuan@huawei.com> - 2.0.16-9
- libnuma: Fix incorrect print and exit of numa_preferred/_many APIs
* Tue Dec 19 2023 chenhaixiang <chenhaixiang3@huawei.com> - 2.0.16-8
- fix: fix memory leaks when run with -H
* 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
* Mon Jun 19 2023 wuxu <wuxu.wu@huawei.com> - 2.0.16-5
- numactl.c: Fix merging of neighboring pages' policies in dump_shm and remove unused variable