Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
0ce12d6162
!91 etmem: add debug info for etmem
From: @twicy 
Reviewed-by: @liubo254 
Signed-off-by: @liubo254
2024-04-08 07:06:02 +00:00
tangyuchen
037d55260b etmem: add debug info for etmem
Signed-off-by: tangyuchen <tangyuchen5@huawei.com>
2024-04-08 11:02:22 +08:00
openeuler-ci-bot
d010facc19
!80 [sync] PR-79: fix project stop cmd timeout problem
From: @openeuler-sync-bot 
Reviewed-by: @liuzhiqiang26 
Signed-off-by: @liuzhiqiang26
2023-08-25 03:43:11 +00:00
volcanodragon
5c076ae35c fix project stop cmd timeout
(cherry picked from commit 3d3a775e048cd8ba5e7dc139d6afa036862c16b3)
2023-08-24 19:13:26 +08:00
openeuler-ci-bot
cb12ba453a
!70 [sync] PR-69: backport bugfix patch from upstream
From: @openeuler-sync-bot 
Reviewed-by: @liuzhiqiang26 
Signed-off-by: @liuzhiqiang26
2023-06-14 03:31:14 +00:00
liubo
ab68896f27 etmem: backport bugfix patch from upstream
1. remove unnecessary log code during the
permission check.
2. fix memory leak and fp leak.
3. fix multiple etmemd and too many err log problem.

Signed-off-by: liubo <liubo254@huawei.com>
(cherry picked from commit 7c109accd61df6d6b12b4aff89445acecd3ee555)
2023-06-14 09:21:57 +08:00
openeuler-ci-bot
cbae29c521
!61 [sync] PR-59: add loongarch64 support
From: @openeuler-sync-bot 
Reviewed-by: @liuzhiqiang26 
Signed-off-by: @liuzhiqiang26
2023-02-21 07:26:25 +00:00
Jingyun Hua
650576812e add loongarch64 support
Signed-off-by: Jingyun Hua <huajingyun@loongson.cn>
(cherry picked from commit d1664f643b82d03dbca56fefaee1355c09f9cbda)
2023-02-21 14:22:47 +08:00
openeuler-ci-bot
945413c3c8
!57 [sync] PR-55: Modify License to MulanPSL-2.0 in the spec
From: @openeuler-sync-bot 
Reviewed-by: @liuzhiqiang26 
Signed-off-by: @liuzhiqiang26
2022-12-02 06:18:10 +00:00
liubo
585e401e9e etmem : Modify License to MulanPSL-2.0 in the spec
The License in the spec file is originally Mulan PSL V2,
which is not a standard description.
Therefore, the License is changed to MulanPSL-2.0.

Signed-off-by: liubo <liubo254@huawei.com>
(cherry picked from commit 74ad89685b3a84256b02d6671ae512a859009b35)
2022-12-02 09:52:23 +08:00
7 changed files with 695 additions and 6 deletions

View File

@ -0,0 +1,60 @@
From 90ea095a30002d05b139b076eee4e7662fabc5e1 Mon Sep 17 00:00:00 2001
From: Jingyun Hua <huajingyun@loongson.cn>
Date: Tue, 10 Jan 2023 09:39:22 +0800
Subject: [PATCH] add loongarch64 support
Add compile options -march=loongarch64 for loongarch64 platform.
Signed-off-by: Jingyun Hua <huajingyun@loongson.cn>
---
etmem/CMakeLists.txt | 6 ++++++
etmem/test/CMakeLists.txt | 2 ++
2 files changed, 8 insertions(+)
diff --git a/etmem/CMakeLists.txt b/etmem/CMakeLists.txt
index 505c655..9e3194a 100644
--- a/etmem/CMakeLists.txt
+++ b/etmem/CMakeLists.txt
@@ -90,6 +90,8 @@ target_link_libraries(etmemd PRIVATE pthread dl rt boundscheck numa ${GLIB2_LIBR
if( ${ARCHITECTURE} STREQUAL "aarch64" )
target_compile_options(etmemd PRIVATE -march=armv8-a)
+elseif( ${ARCHITECTURE} STREQUAL "loongarch64" )
+ target_compile_options(etmemd PRIVATE -march=loongarch64)
else()
target_compile_options(etmemd PRIVATE -march=core-avx-i -m64)
endif()
@@ -105,6 +107,8 @@ target_link_libraries(etmem PRIVATE pthread dl rt boundscheck)
if( ${ARCHITECTURE} STREQUAL "aarch64" )
target_compile_options(etmem PRIVATE -march=armv8-a)
+elseif( ${ARCHITECTURE} STREQUAL "loongarch64" )
+ target_compile_options(etmemd PRIVATE -march=loongarch64)
else()
target_compile_options(etmem PRIVATE -march=core-avx-i -m64)
endif()
@@ -121,6 +125,8 @@ target_link_libraries(etmemd_scan PRIVATE pthread dl rt boundscheck numa ${GLIB2
if( ${ARCHITECTURE} STREQUAL "aarch64" )
target_compile_options(etmemd_scan PRIVATE -march=armv8-a)
+elseif( ${ARCHITECTURE} STREQUAL "loongarch64" )
+ target_compile_options(etmemd_scan PRIVATE -march=loongarch64)
else()
target_compile_options(etmemd_scan PRIVATE -march=core-avx-i -m64)
endif()
diff --git a/etmem/test/CMakeLists.txt b/etmem/test/CMakeLists.txt
index a380e98..928e358 100644
--- a/etmem/test/CMakeLists.txt
+++ b/etmem/test/CMakeLists.txt
@@ -154,6 +154,8 @@ endif()
if( ${ARCHITECTURE} STREQUAL "aarch64")
SET(COMMON_COMPILE_OPT ${COMMON_COMPILE_OPT} -march=armv8-a)
+elseif( ${ARCHITECTURE} STREQUAL "loongarch64" )
+ SET(COMMON_COMPILE_OPT ${COMMON_COMPILE_OPT} -march=loongarch64)
else()
SET(COMMON_COMPILE_OPT ${COMMON_COMPILE_OPT} -march=core-avx-i -m64)
endif()
--
2.33.0

View File

@ -0,0 +1,34 @@
From 3ac65b4eb27e0e5d940e898af98de87e49e1fe99 Mon Sep 17 00:00:00 2001
From: liubo <liubo254@huawei.com>
Date: Mon, 10 Apr 2023 21:12:25 +0800
Subject: [PATCH 2/4] etmem: remove unnecessary log code
etmem supports only 400/600 configuration file
permissions.
During the permission check, the system check whether
the permisson requirements of 400 or 600 are met.
Error logs do not need to be printed during each permission
check.
Signed-off-by: liubo <liubo254@huawei.com>
---
etmem/src/etmemd_src/etmemd_common.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/etmem/src/etmemd_src/etmemd_common.c b/etmem/src/etmemd_src/etmemd_common.c
index 649f472..7a6125e 100644
--- a/etmem/src/etmemd_src/etmemd_common.c
+++ b/etmem/src/etmemd_src/etmemd_common.c
@@ -563,7 +563,6 @@ int file_permission_check(const char *file_path, mode_t mode)
file_p = buf.st_mode & S_IRWX_VALID;
if (file_p != mode) {
- etmemd_log(ETMEMD_LOG_WARN, "file : %s mode is wrong.\n", file_path);
return -1;
}
--
2.33.0

View File

@ -0,0 +1,199 @@
From 5892dac2f7de185c2b0f2c9c00fdd2c5e985a9dc Mon Sep 17 00:00:00 2001
From: liubo <liubo254@huawei.com>
Date: Wed, 31 May 2023 17:12:57 +0800
Subject: [PATCH 3/4] etmem: fix memory leak and fd leak
fix memory leak and fp leak.
When user stop the task while task is running, the routine
will run pthread_cancel to stop the task.
memory of vmas struct may leak when this happens.
Set thread cannot be canceled when main routine is running.
Signed-off-by: liubo <liubo254@huawei.com>
---
etmem/src/etmemd_src/etmemd_migrate.c | 3 +++
etmem/src/etmemd_src/etmemd_rpc.c | 7 +++++-
etmem/src/etmemd_src/etmemd_scan.c | 8 ++-----
etmem/src/etmemd_src/etmemd_slide.c | 29 +++++++++++------------
etmem/src/etmemd_src/etmemd_threadpool.c | 1 +
etmem/src/etmemd_src/etmemd_threadtimer.c | 13 +++++++---
6 files changed, 36 insertions(+), 25 deletions(-)
diff --git a/etmem/src/etmemd_src/etmemd_migrate.c b/etmem/src/etmemd_src/etmemd_migrate.c
index a143c5e..5f41876 100644
--- a/etmem/src/etmemd_src/etmemd_migrate.c
+++ b/etmem/src/etmemd_src/etmemd_migrate.c
@@ -98,6 +98,7 @@ static int etmemd_migrate_mem(const char *pid, const char *grade_path, struct pa
etmemd_log(ETMEMD_LOG_DEBUG, "migrate failed for pid %s, check if etmem_swap.ko installed\n", pid);
free(swap_str);
fclose(fp);
+ fp = NULL;
return -1;
}
free(swap_str);
@@ -105,6 +106,8 @@ static int etmemd_migrate_mem(const char *pid, const char *grade_path, struct pa
}
fclose(fp);
+ fp = NULL;
+
return 0;
}
diff --git a/etmem/src/etmemd_src/etmemd_rpc.c b/etmem/src/etmemd_src/etmemd_rpc.c
index 780ddce..100a7bd 100644
--- a/etmem/src/etmemd_src/etmemd_rpc.c
+++ b/etmem/src/etmemd_src/etmemd_rpc.c
@@ -22,6 +22,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <malloc.h>
#include "securec.h"
#include "etmemd_rpc.h"
#include "etmemd_project.h"
@@ -162,7 +163,11 @@ static struct obj_cmd_item obj_remove_items[] = {
static enum opt_result do_obj_remove(GKeyFile *config)
{
- return do_obj_cmd(config, obj_remove_items, ARRAY_SIZE(obj_remove_items), false);
+ enum opt_result ret;
+
+ ret = do_obj_cmd(config, obj_remove_items, ARRAY_SIZE(obj_remove_items), false);
+ (void)malloc_trim(0);
+ return ret;
}
static enum opt_result handle_obj_cmd(char *file_name, enum cmd_type type)
diff --git a/etmem/src/etmemd_src/etmemd_scan.c b/etmem/src/etmemd_src/etmemd_scan.c
index e06ba92..699b1cd 100644
--- a/etmem/src/etmemd_src/etmemd_scan.c
+++ b/etmem/src/etmemd_src/etmemd_scan.c
@@ -347,12 +347,7 @@ struct vmas *get_vmas_with_flags(const char *pid, char *vmflags_array[], int vmf
size_t len;
char *maps_file = NULL;
- if (vmflags_num == 0) {
- maps_file = MAPS_FILE;
- } else {
- maps_file = SMAPS_FILE;
- }
-
+ maps_file = (vmflags_num == 0) ? MAPS_FILE : SMAPS_FILE;
ret_vmas = (struct vmas *)calloc(1, sizeof(struct vmas));
if (ret_vmas == NULL) {
etmemd_log(ETMEMD_LOG_ERR, "malloc for vmas fail\n");
@@ -397,6 +392,7 @@ struct vmas *get_vmas_with_flags(const char *pid, char *vmflags_array[], int vmf
}
fclose(fp);
+ fp = NULL;
return ret_vmas;
}
diff --git a/etmem/src/etmemd_src/etmemd_slide.c b/etmem/src/etmemd_src/etmemd_slide.c
index a3c474b..1a11f45 100644
--- a/etmem/src/etmemd_src/etmemd_slide.c
+++ b/etmem/src/etmemd_src/etmemd_slide.c
@@ -216,11 +216,10 @@ static void *slide_executor(void *arg)
return NULL;
}
- /* register cleanup function in case of unexpected cancellation detected,
- * and register for memory_grade first, because it needs to clean after page_refs is cleaned */
- pthread_cleanup_push(clean_memory_grade_unexpected, &memory_grade);
- pthread_cleanup_push(clean_page_refs_unexpected, &page_refs);
- pthread_cleanup_push(clean_page_sort_unexpected, &page_sort);
+ if (pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL) != 0) {
+ etmemd_log(ETMEMD_LOG_ERR, "failed to set pthread cancel state.\n");
+ return NULL;
+ }
page_refs = etmemd_do_scan(tk_pid, tk_pid->tk);
if (page_refs == NULL) {
@@ -237,15 +236,10 @@ static void *slide_executor(void *arg)
memory_grade = slide_policy_interface(&page_sort, tk_pid);
scan_out:
- /* clean up page_sort linked array */
- pthread_cleanup_pop(1);
+ clean_page_sort_unexpected(&page_sort);
- /* no need to use page_refs any longer.
- * pop the cleanup function with parameter 1, because the items in page_refs list will be moved
- * into the at least on list of memory_grade after polidy function called if no problems happened,
- * but mig_policy_func() may fails to move page_refs in rare cases.
- * It will do nothing if page_refs is NULL */
- pthread_cleanup_pop(1);
+ /* no need to use page_refs any longer. */
+ clean_page_refs_unexpected(&page_refs);
if (memory_grade == NULL) {
etmemd_log(ETMEMD_LOG_DEBUG, "pid %u memory grade is empty\n", tk_pid->pid);
@@ -261,12 +255,17 @@ scan_out:
}
exit:
- /* clean memory_grade here */
- pthread_cleanup_pop(1);
+ clean_memory_grade_unexpected(&memory_grade);
+
if (malloc_trim(0) == 0) {
etmemd_log(ETMEMD_LOG_INFO, "malloc_trim to release memory for pid %u fail\n", tk_pid->pid);
}
+ if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) {
+ etmemd_log(ETMEMD_LOG_DEBUG, "pthread_setcancelstate PTHREAD_CANCEL_ENABLE failed.\n");
+ }
+ pthread_testcancel();
+
return NULL;
}
diff --git a/etmem/src/etmemd_src/etmemd_threadpool.c b/etmem/src/etmemd_src/etmemd_threadpool.c
index dac42d1..4375ca1 100644
--- a/etmem/src/etmemd_src/etmemd_threadpool.c
+++ b/etmem/src/etmemd_src/etmemd_threadpool.c
@@ -48,6 +48,7 @@ static void threadpool_cancel_unlock(void *arg)
}
etmemd_log(ETMEMD_LOG_DEBUG, "unlock for threadpool once\n");
pthread_mutex_unlock(g_pool_lock);
+ g_pool_lock = NULL;
}
static void *threadpool_routine(void *arg)
diff --git a/etmem/src/etmemd_src/etmemd_threadtimer.c b/etmem/src/etmemd_src/etmemd_threadtimer.c
index d18b3e0..4014c72 100644
--- a/etmem/src/etmemd_src/etmemd_threadtimer.c
+++ b/etmem/src/etmemd_src/etmemd_threadtimer.c
@@ -37,7 +37,11 @@ static void *thread_timer_routine(void *arg)
expired_time = timer->expired_time;
- pthread_cleanup_push(threadtimer_cancel_unlock, &timer->cond_mutex);
+ if (pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL) != 0) {
+ etmemd_log(ETMEMD_LOG_ERR, "failed to set pthread cancel state.\n");
+ return NULL;
+ }
+
pthread_mutex_lock(&timer->cond_mutex);
while (!timer->down) {
if (clock_gettime(CLOCK_MONOTONIC, &timespec) != 0) {
@@ -60,9 +64,12 @@ static void *thread_timer_routine(void *arg)
break;
}
}
- /* unlock th timer->cond_mutex */
- pthread_cleanup_pop(1);
+ threadtimer_cancel_unlock(&timer->cond_mutex);
+ if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) {
+ etmemd_log(ETMEMD_LOG_DEBUG, "pthread_setcancelstate PTHREAD_CANCEL_ENABLE failed.\n");
+ }
+ pthread_testcancel();
pthread_exit(NULL);
}
--
2.33.0

View File

@ -0,0 +1,74 @@
From 5ca2bdd61980b8cf501bc9397611260f4745a7e6 Mon Sep 17 00:00:00 2001
From: liubo <liubo254@huawei.com>
Date: Tue, 6 Jun 2023 21:14:35 +0800
Subject: [PATCH 4/4] etmem: fix multiple etmemd and too many err log problem
1. the etmem uses the fork and exec mode to run the
feature command to botain the corresponding process information.
If the cmd does not exist, the fork subprocess may not
exit, but the parent process is suspended.
As a result, new etmemd processes are continuously started.
Signed-off-by: liubo <liubo254@huawei.com>
---
etmem/src/etmemd_src/etmemd_task.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/etmem/src/etmemd_src/etmemd_task.c b/etmem/src/etmemd_src/etmemd_task.c
index dfe911f..a50c78d 100644
--- a/etmem/src/etmemd_src/etmemd_task.c
+++ b/etmem/src/etmemd_src/etmemd_task.c
@@ -48,26 +48,33 @@ static int get_pid_through_pipe(char *arg_pid[], const int *pipefd)
if (stdout_copy_fd < 0) {
etmemd_log(ETMEMD_LOG_ERR, "dup(STDOUT_FILENO) fail.\n");
close(pipefd[1]);
- return -1;
+ exit(SIGPIPE);
}
ret = dup2(pipefd[1], fileno(stdout));
if (ret == -1) {
etmemd_log(ETMEMD_LOG_ERR, "dup2 pipefd fail.\n");
close(pipefd[1]);
- return -1;
+ exit(SIGPIPE);
+ }
+
+ ret = dup2(pipefd[1], fileno(stderr));
+ if (ret == -1) {
+ etmemd_log(ETMEMD_LOG_ERR, "dup2 piped fail.\n");
+ close(pipefd[1]);
+ exit(SIGPIPE);
}
if (execve(arg_pid[0], arg_pid, NULL) == -1) {
etmemd_log(ETMEMD_LOG_ERR, "execve %s fail with %s.\n", arg_pid[0], strerror(errno));
close(pipefd[1]);
- return -1;
+ exit(SIGPIPE);
}
- if (fflush(stdout) != 0) {
+ if (fflush(stdout) != 0 || fflush(stderr) != 0) {
etmemd_log(ETMEMD_LOG_ERR, "fflush execve stdout fail.\n");
close(pipefd[1]);
- return -1;
+ exit(SIGPIPE);
}
close(pipefd[1]);
dup2(stdout_copy_fd, fileno(stdout));
@@ -75,6 +82,10 @@ static int get_pid_through_pipe(char *arg_pid[], const int *pipefd)
/* wait for execve done */
wait(&status);
+ if ((WIFEXITED(status) && WEXITSTATUS(status) == SIGPIPE) ||
+ !WIFEXITED(status)) {
+ return -1;
+ }
return 0;
}
--
2.33.0

View File

@ -0,0 +1,241 @@
From 433c75be35d8e9aeabafa9c35cbd9d38855e0497 Mon Sep 17 00:00:00 2001
From: liubo <liubo254@huawei.com>
Date: Mon, 14 Aug 2023 16:03:38 +0800
Subject: [PATCH] etmem: fix project stop cmd timeout problem
In patch "fix fd leak when user stop task timer", set the
thread to PTHREAD_CANCEL_DISABLE to solve the FD leakage
problem during task obtaining.
However, when the project stop command is executed,
the rpc cmd exits only after all task threads are executed.
But the RPC cmd timeout period is only 10 seconds.
When the task execution time exceeds the timeout period, the RPC
command times out and an error message is returned.
According to code analysis, the most time-consuming part of all
tasks is in the sleep phase of the scanning logic.
The preceding problem is solved by skipping the corresponding
sleep environment and allowing the thread to exit directly.
Signed-off-by: liubo <liubo254@huawei.com>
Signed-off-by: volcanodragon <linfeilong@huawei.com>
---
etmem/inc/etmemd_inc/etmemd_threadpool.h | 2 +-
etmem/src/etmemd_src/etmemd_pool_adapter.c | 5 ++++-
etmem/src/etmemd_src/etmemd_scan.c | 17 ++++++++++++++++-
etmem/src/etmemd_src/etmemd_slide.c | 22 +++++++++++-----------
etmem/src/etmemd_src/etmemd_threadpool.c | 4 ++--
etmem/src/etmemd_src/etmemd_threadtimer.c | 18 ++++++------------
6 files changed, 40 insertions(+), 28 deletions(-)
diff --git a/etmem/inc/etmemd_inc/etmemd_threadpool.h b/etmem/inc/etmemd_inc/etmemd_threadpool.h
index 57af8be..4e62c81 100644
--- a/etmem/inc/etmemd_inc/etmemd_threadpool.h
+++ b/etmem/inc/etmemd_inc/etmemd_threadpool.h
@@ -74,6 +74,6 @@ void threadpool_reset_status(thread_pool** inst);
/*
* Stop and destroy the thread pool instance
* */
-void threadpool_stop_and_destroy(thread_pool** inst);
+void threadpool_stop_and_destroy(thread_pool **inst);
#endif //ETMEMD_THREADPOOL_H
diff --git a/etmem/src/etmemd_src/etmemd_pool_adapter.c b/etmem/src/etmemd_src/etmemd_pool_adapter.c
index dfda3f4..39f9451 100644
--- a/etmem/src/etmemd_src/etmemd_pool_adapter.c
+++ b/etmem/src/etmemd_src/etmemd_pool_adapter.c
@@ -50,6 +50,8 @@ static void *launch_threadtimer_executor(void *arg)
int scheduing_count;
if (tk->eng->proj->start) {
+ (void)pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
+
if (etmemd_get_task_pids(tk, true) != 0) {
return NULL;
}
@@ -57,6 +59,7 @@ static void *launch_threadtimer_executor(void *arg)
push_ctrl_workflow(&tk->pids, executor->func);
threadpool_notify(tk->threadpool_inst);
+ (void)pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pool_inst = tk->threadpool_inst;
scheduing_count = __atomic_load_n(&pool_inst->scheduing_size, __ATOMIC_SEQ_CST);
@@ -120,12 +123,12 @@ void stop_and_delete_threadpool_work(struct task *tk)
tk->value, tk->eng->proj->name);
return;
}
-
/* stop the threadtimer first */
thread_timer_stop(tk->timer_inst);
/* destroy them then */
thread_timer_destroy(&tk->timer_inst);
+
threadpool_stop_and_destroy(&tk->threadpool_inst);
}
diff --git a/etmem/src/etmemd_src/etmemd_scan.c b/etmem/src/etmemd_src/etmemd_scan.c
index 699b1cd..5620951 100644
--- a/etmem/src/etmemd_src/etmemd_scan.c
+++ b/etmem/src/etmemd_src/etmemd_scan.c
@@ -120,6 +120,18 @@ void free_vmas(struct vmas *vmas)
free(vmas);
}
+static void clean_vmas_resource_unexpected(void *arg)
+{
+ struct vmas **vmas = (struct vmas **)arg;
+
+ if (*vmas == NULL) {
+ return;
+ }
+
+ free_vmas(*vmas);
+ *vmas = NULL;
+}
+
static bool parse_vma_seg0(struct vma *vma, const char *seg0)
{
int ret;
@@ -777,6 +789,7 @@ struct page_refs *etmemd_do_scan(const struct task_pid *tpid, const struct task
return NULL;
}
+ pthread_cleanup_push(clean_vmas_resource_unexpected, &vmas);
/* get vmas of target pid first. */
vmas = get_vmas(pid);
if (vmas == NULL) {
@@ -799,10 +812,12 @@ struct page_refs *etmemd_do_scan(const struct task_pid *tpid, const struct task
page_refs = NULL;
break;
}
+ (void)pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sleep((unsigned)page_scan->sleep);
+ (void)pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
}
- free_vmas(vmas);
+ pthread_cleanup_pop(1);
return page_refs;
}
diff --git a/etmem/src/etmemd_src/etmemd_slide.c b/etmem/src/etmemd_src/etmemd_slide.c
index 1a11f45..25fa45d 100644
--- a/etmem/src/etmemd_src/etmemd_slide.c
+++ b/etmem/src/etmemd_src/etmemd_slide.c
@@ -212,13 +212,16 @@ static void *slide_executor(void *arg)
struct memory_grade *memory_grade = NULL;
struct page_sort *page_sort = NULL;
- if (check_should_swap(tk_pid) == DONT_SWAP) {
- return NULL;
- }
+ /* The pthread_setcancelstate interface returns an error only when the
+ * input parameter state is invalid, no need to check return value.
+ */
+ (void)pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
- if (pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL) != 0) {
- etmemd_log(ETMEMD_LOG_ERR, "failed to set pthread cancel state.\n");
- return NULL;
+ /* register cleanup function in case of unexpected cancellation detected */
+ pthread_cleanup_push(clean_page_refs_unexpected, &page_refs);
+
+ if (check_should_swap(tk_pid) == DONT_SWAP) {
+ goto scan_out;
}
page_refs = etmemd_do_scan(tk_pid, tk_pid->tk);
@@ -238,8 +241,7 @@ static void *slide_executor(void *arg)
scan_out:
clean_page_sort_unexpected(&page_sort);
- /* no need to use page_refs any longer. */
- clean_page_refs_unexpected(&page_refs);
+ pthread_cleanup_pop(1);
if (memory_grade == NULL) {
etmemd_log(ETMEMD_LOG_DEBUG, "pid %u memory grade is empty\n", tk_pid->pid);
@@ -261,9 +263,7 @@ exit:
etmemd_log(ETMEMD_LOG_INFO, "malloc_trim to release memory for pid %u fail\n", tk_pid->pid);
}
- if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) {
- etmemd_log(ETMEMD_LOG_DEBUG, "pthread_setcancelstate PTHREAD_CANCEL_ENABLE failed.\n");
- }
+ (void)pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_testcancel();
return NULL;
diff --git a/etmem/src/etmemd_src/etmemd_threadpool.c b/etmem/src/etmemd_src/etmemd_threadpool.c
index 4375ca1..6d35fe1 100644
--- a/etmem/src/etmemd_src/etmemd_threadpool.c
+++ b/etmem/src/etmemd_src/etmemd_threadpool.c
@@ -203,7 +203,7 @@ static void threadpool_cancel_tasks_working(const thread_pool *inst)
int i;
for (i = 0; i < inst->max_thread_cap; i++) {
- pthread_cancel(inst->tid[i]);
+ (void)pthread_cancel(inst->tid[i]);
}
}
@@ -236,7 +236,7 @@ void threadpool_stop_and_destroy(thread_pool **inst)
threadpool_cancel_tasks_working(thread_instance);
for (i = 0; i < thread_instance->max_thread_cap; i++) {
- pthread_join(thread_instance->tid[i], NULL);
+ (void)pthread_join(thread_instance->tid[i], NULL);
}
free(thread_instance->tid);
diff --git a/etmem/src/etmemd_src/etmemd_threadtimer.c b/etmem/src/etmemd_src/etmemd_threadtimer.c
index 4014c72..582a84d 100644
--- a/etmem/src/etmemd_src/etmemd_threadtimer.c
+++ b/etmem/src/etmemd_src/etmemd_threadtimer.c
@@ -37,11 +37,7 @@ static void *thread_timer_routine(void *arg)
expired_time = timer->expired_time;
- if (pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL) != 0) {
- etmemd_log(ETMEMD_LOG_ERR, "failed to set pthread cancel state.\n");
- return NULL;
- }
-
+ pthread_cleanup_push(threadtimer_cancel_unlock, &timer->cond_mutex);
pthread_mutex_lock(&timer->cond_mutex);
while (!timer->down) {
if (clock_gettime(CLOCK_MONOTONIC, &timespec) != 0) {
@@ -64,12 +60,9 @@ static void *thread_timer_routine(void *arg)
break;
}
}
- threadtimer_cancel_unlock(&timer->cond_mutex);
+ /* unlock th timer->cond_mutex */
+ pthread_cleanup_pop(1);
- if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) {
- etmemd_log(ETMEMD_LOG_DEBUG, "pthread_setcancelstate PTHREAD_CANCEL_ENABLE failed.\n");
- }
- pthread_testcancel();
pthread_exit(NULL);
}
@@ -149,9 +142,10 @@ void thread_timer_stop(timer_thread* inst)
return;
}
inst->down = true;
+ pthread_cond_broadcast(&(inst->cond));
- pthread_cancel(inst->pthread);
- pthread_join(inst->pthread, NULL);
+ (void)pthread_cancel(inst->pthread);
+ (void)pthread_join(inst->pthread, NULL);
etmemd_log(ETMEMD_LOG_DEBUG, "Timer instance stops ! \n");
}
--
2.33.0

View File

@ -0,0 +1,59 @@
From ae1a854beda0b9318e080acff64de3375eff75d3 Mon Sep 17 00:00:00 2001
From: Liu Chao <liuchao173@huawei.com>
Date: Tue, 2 Apr 2024 16:01:50 +0800
Subject: [PATCH] etmem: construct etmem debug info package
Currently, there is no debug info package for etmem, and this
can be a problem when trying to analyze a coredump
Signed-off-by: tangyuchen <tangyuchen5@huawei.com>
---
etmem/CMakeLists.txt | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/etmem/CMakeLists.txt b/etmem/CMakeLists.txt
index 0b38f07..6018ce0 100644
--- a/etmem/CMakeLists.txt
+++ b/etmem/CMakeLists.txt
@@ -83,9 +83,11 @@ target_compile_options(etmemd PRIVATE -fsigned-char -fno-omit-frame-pointer -Wal
if(CONFIG_DEBUG STREQUAL "y")
target_compile_options(etmemd PRIVATE -g)
+else()
+ target_link_options(etmemd PRIVATE -s)
endif()
-set_target_properties(etmemd PROPERTIES LINK_FLAGS "-s -fPIE -pie -fPIC -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines")
+target_link_options(etmemd PRIVATE -fPIE -pie -fPIC -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines)
target_link_libraries(etmemd PRIVATE pthread dl rt boundscheck numa ${GLIB2_LIBRARIES})
if( ${ARCHITECTURE} STREQUAL "aarch64" )
@@ -102,9 +104,11 @@ target_compile_options(etmem PRIVATE -fsigned-char -fno-omit-frame-pointer -Wall
if(CONFIG_DEBUG STREQUAL "y")
target_compile_options(etmem PRIVATE -g)
+else()
+ target_link_options(etmem PRIVATE -s)
endif()
-set_target_properties(etmem PROPERTIES LINK_FLAGS "-s -fPIE -pie -fPIC -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines")
+target_link_options(etmem PRIVATE -fPIE -pie -fPIC -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines)
target_link_libraries(etmem PRIVATE pthread dl rt boundscheck)
if( ${ARCHITECTURE} STREQUAL "aarch64" )
@@ -122,9 +126,11 @@ target_compile_options(etmemd_scan PRIVATE -fsigned-char -fno-omit-frame-pointer
if(CONFIG_DEBUG STREQUAL "y")
target_compile_options(etmemd_scan PRIVATE -g)
+else()
+ target_link_options(etmemd_scan PRIVATE -s)
endif()
-set_target_properties(etmemd_scan PROPERTIES LINK_FLAGS "-s -fPIE -pie -fPIC -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -Wl,--version-script=${ETMEMD_SRC_DIR}/etmemd_scan.version")
+target_link_options(etmemd_scan PRIVATE -fPIE -pie -fPIC -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -Wl,--version-script=${ETMEMD_SRC_DIR}/etmemd_scan.version)
target_link_libraries(etmemd_scan PRIVATE pthread dl rt boundscheck numa ${GLIB2_LIBRARIES})
if( ${ARCHITECTURE} STREQUAL "aarch64" )
--
2.33.0

View File

@ -1,10 +1,8 @@
%global debug_package %{nil}
Name: etmem
Version: 1.0
Release: 11
Summary: etmem
License: Mulan PSL v2
Release: 16
Summary: etmem
License: MulanPSL-2.0
URL: https://gitee.com/openeuler/etmem
Source0: https://gitee.com/openeuler/etmem/repository/archive/%{version}.tar.gz
@ -92,6 +90,12 @@ Patch80: 0081-etmem-Fix-help-command.patch
Patch81: 0082-etmem-add-etmem-project-License-and-notice-file.patch
Patch82: 0083-etmem-fix-memory-leak.patch
Patch83: 0084-etmem-add-dt-test-code-for-permission-check.patch
Patch84: 0085-add-loongarch64-support.patch
Patch85: 0086-etmem-remove-unnecessary-log-code.patch
Patch86: 0087-etmem-fix-memory-leak-and-fd-leak.patch
Patch87: 0088-etmem-fix-multiple-etmemd-and-too-many-err-log-probl.patch
Patch88: 0089-etmem-fix-project-stop-cmd-timeout-problem.patch
Patch89: 0090-etmem-construct-etmem-debug-info-package.patch
#Dependency
BuildRequires: cmake gcc gcc-c++ glib2-devel
@ -109,7 +113,7 @@ etmem module
%build
mkdir -p build
cd build
cmake ..
cmake .. -DCONFIG_DEBUG=y
make
%install
@ -145,6 +149,24 @@ install -m 0644 userswap/include/uswap_api.h $RPM_BUILD_ROOT%{_includedir}
%postun -p /sbin/ldconfig
%changelog
* Wed Apr 3 2024 tangyuchen <tangyuchen5@huawei.com> 1.0-16
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:add debug info support for etmem
* Thu Aug 24 2023 volcanodragon <linfeilong@huawei.com> 1.0-15
- fix project stop cmd timeout problem
* Thu Jun 8 2023 liubo <liubo254@huawei.com> 1.0-14
- backport bugfix patch from upstream
* Tue Jan 10 2023 huajingyun <huajingyun@loongson.cn> 1.0-13
- add loongarch64 support
* Thu Dec 1 2022 liubo <liubo254@huawei.com> 1.0-12
- Modify License to MulanPSL-2.0 in the spec
* Mon Aug 1 2022 liubo <liubo254@huawei.com> 1.0-11
- Sync the features and bug fixes in the etmem source repo.