From 932d03dd7ceabdf98145a8daaf54742a26b5ec63 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Thu, 10 Apr 2025 16:35:32 +0200 Subject: [PATCH 1/7] Hotfixes --- src/posix/utils/clone.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/posix/utils/clone.hpp b/src/posix/utils/clone.hpp index 306401f98..adf38f081 100644 --- a/src/posix/utils/clone.hpp +++ b/src/posix/utils/clone.hpp @@ -18,13 +18,17 @@ inline bool is_capio_tid(const pid_t tid) { } inline void register_capio_tid(const pid_t tid) { + START_LOG(syscall_no_intercept(SYS_gettid), "call(tid=%ld)", tid); const std::lock_guard lg(clone_mutex); tids->insert(tid); } inline void remove_capio_tid(const pid_t tid) { + START_LOG(syscall_no_intercept(SYS_gettid), "call(tid=%ld)", tid); const std::lock_guard lg(clone_mutex); - tids->erase(tid); + if (tids->find(tid) != tids->end()) { + tids->erase(tid); + } } inline void init_threading_support() { tids = new std::unordered_set{}; } From 50b13cc1214b238ef70505a94fb257f2e59d5a0c Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Thu, 10 Apr 2025 17:10:29 +0200 Subject: [PATCH 2/7] Hotfixes --- src/common/capio/shm.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/common/capio/shm.hpp b/src/common/capio/shm.hpp index 3c86741be..5d8d15614 100644 --- a/src/common/capio/shm.hpp +++ b/src/common/capio/shm.hpp @@ -133,7 +133,7 @@ void *get_shm(const std::string &shm_name) { } void *p = mmap(nullptr, sb.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (p == MAP_FAILED) { - ERR_EXIT("mmap get_shm %s", shm_name.c_str()); + ERR_EXIT("ERROR: mmap failed at get_shm(%s): %s", shm_name.c_str(), strerror(errno)); } if (close(fd) == -1) { ERR_EXIT("close"); @@ -161,7 +161,8 @@ void *get_shm_if_exist(const std::string &shm_name) { } void *p = mmap(nullptr, sb.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (p == MAP_FAILED) { - ERR_EXIT("mmap get_shm %s", shm_name.c_str()); + ERR_EXIT("ERROR: mmap failed at get_shm_if_exist(%s): %s", shm_name.c_str(), + strerror(errno)); } if (close(fd) == -1) { ERR_EXIT("close"); From 829bdd7e26560fa342e29ced4a0d357e6ac57b61 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Thu, 10 Apr 2025 17:21:52 +0200 Subject: [PATCH 3/7] hotfix --- src/common/capio/shm.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/common/capio/shm.hpp b/src/common/capio/shm.hpp index 5d8d15614..5fc3386d5 100644 --- a/src/common/capio/shm.hpp +++ b/src/common/capio/shm.hpp @@ -133,6 +133,11 @@ void *get_shm(const std::string &shm_name) { } void *p = mmap(nullptr, sb.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (p == MAP_FAILED) { + LOG("ERROR MMAP arg dump:"); + LOG("mmap-size: %ld", sb.st_size); + LOG("mmap-prot: %ld", PROT_READ | PROT_WRITE); + LOG("mmap-flags: %ld", MAP_SHARED); + LOG("mmap-fd: %ld", fd); ERR_EXIT("ERROR: mmap failed at get_shm(%s): %s", shm_name.c_str(), strerror(errno)); } if (close(fd) == -1) { From 5da2174cf30aedbc313dcb7c2564799e2187d295 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Thu, 10 Apr 2025 17:41:01 +0200 Subject: [PATCH 4/7] hotfix --- src/common/capio/shm.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/capio/shm.hpp b/src/common/capio/shm.hpp index 5fc3386d5..fa4bd9403 100644 --- a/src/common/capio/shm.hpp +++ b/src/common/capio/shm.hpp @@ -156,7 +156,7 @@ void *get_shm_if_exist(const std::string &shm_name) { if (errno == ENOENT) { return nullptr; } - ERR_EXIT("get_shm shm_open %s", shm_name.c_str()); + ERR_EXIT("ERROR: unable to open shared memory %s: %s", shm_name.c_str(), strerror(errno)); } /* Open existing object */ /* Use shared memory object size as length argument for mmap() @@ -166,6 +166,11 @@ void *get_shm_if_exist(const std::string &shm_name) { } void *p = mmap(nullptr, sb.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (p == MAP_FAILED) { + LOG("ERROR MMAP arg dump:"); + LOG("mmap-size: %ld", sb.st_size); + LOG("mmap-prot: %ld", PROT_READ | PROT_WRITE); + LOG("mmap-flags: %ld", MAP_SHARED); + LOG("mmap-fd: %ld", fd); ERR_EXIT("ERROR: mmap failed at get_shm_if_exist(%s): %s", shm_name.c_str(), strerror(errno)); } From 10dd19f4de5ce0823cd7bb6965895ae986193f35 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Thu, 10 Apr 2025 17:49:17 +0200 Subject: [PATCH 5/7] hotfix --- src/common/capio/shm.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/capio/shm.hpp b/src/common/capio/shm.hpp index fa4bd9403..b62a9be77 100644 --- a/src/common/capio/shm.hpp +++ b/src/common/capio/shm.hpp @@ -25,7 +25,7 @@ #define SHM_CREATE_CHECK(condition, source) \ if (condition) { \ - ERR_EXIT("Unable to open shm: %s", source); \ + ERR_EXIT("Unable to open shm: %s: %s", source, strerror(errno)); \ }; #else From 8e110517acfd86ad0e76d1a60a3ac0fbc3ca6175 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Fri, 11 Apr 2025 09:17:40 +0200 Subject: [PATCH 6/7] hotfix --- src/common/capio/shm.hpp | 2 +- src/posix/utils/clone.hpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/common/capio/shm.hpp b/src/common/capio/shm.hpp index b62a9be77..6a3fcbe37 100644 --- a/src/common/capio/shm.hpp +++ b/src/common/capio/shm.hpp @@ -42,7 +42,7 @@ LOG("error while creating %s", source); \ std::cout << CAPIO_SERVER_CLI_LOG_SERVER_ERROR << " [ " << node_name << " ] " \ << "Unable to create shm: " << source << std::endl; \ - ERR_EXIT("Unable to open shm: %s", source); \ + ERR_EXIT("Unable to open shm %s: %s", source, strerror(errno)); \ }; #endif diff --git a/src/posix/utils/clone.hpp b/src/posix/utils/clone.hpp index adf38f081..34d13f536 100644 --- a/src/posix/utils/clone.hpp +++ b/src/posix/utils/clone.hpp @@ -63,6 +63,18 @@ inline void hook_clone_child() { #ifdef __CAPIO_POSIX syscall_no_intercept_flag = true; + + /* + * This piece of code is aimed at addressing issues with applications that spawn several + * thousand threads that only do computations. When this occurs, under some circumstances CAPIO + * might fail to allocate shared memory objects. As such, if child threads ONLY do computation, + * we can safely ignore them with CAPIO. + */ + if (thread_local char *skip_child = std::getenv("CAPIO_IGNORE_CHILD_THREADS"); + std::string(skip_child) == "ON") { + return; + } + #endif std::unique_lock lock(clone_mutex); clone_cv.wait(lock, [&tid] { return tids->find(tid) != tids->end(); }); From 7e684bf166ac077baac35741f474f2ed547a3379 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Fri, 11 Apr 2025 09:25:08 +0200 Subject: [PATCH 7/7] hotfix --- src/posix/utils/clone.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/posix/utils/clone.hpp b/src/posix/utils/clone.hpp index 34d13f536..81398be32 100644 --- a/src/posix/utils/clone.hpp +++ b/src/posix/utils/clone.hpp @@ -70,9 +70,12 @@ inline void hook_clone_child() { * might fail to allocate shared memory objects. As such, if child threads ONLY do computation, * we can safely ignore them with CAPIO. */ - if (thread_local char *skip_child = std::getenv("CAPIO_IGNORE_CHILD_THREADS"); - std::string(skip_child) == "ON") { - return; + thread_local char *skip_child = std::getenv("CAPIO_IGNORE_CHILD_THREADS"); + if (skip_child != nullptr) { + auto skip_child_str = std::string(skip_child); + if (skip_child_str == "ON" || skip_child_str == "TRUE" || skip_child_str == "YES") { + return; + } } #endif