Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement size limit for the cache of opened IPC handles #998

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/ipc_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ typedef struct ipc_mapped_handle_cache_t {

ipc_mapped_handle_cache_global_t *IPC_MAPPED_CACHE_GLOBAL = NULL;

// Returns value of the UMF_MAX_OPENED_IPC_HANDLES environment variable
// or 0 if it is not set.
static size_t umfIpcCacheGlobalInitMaxOpenedHandles(void) {
const char *max_size_str = getenv("UMF_MAX_OPENED_IPC_HANDLES");
if (max_size_str) {
char *endptr;
size_t max_size = strtoul(max_size_str, &endptr, 10);
if (*endptr == '\0') {
return max_size;
}
LOG_ERR("Invalid value of UMF_MAX_OPENED_IPC_HANDLES: %s",
max_size_str);
}
return 0;
}

umf_result_t umfIpcCacheGlobalInit(void) {
umf_result_t ret = UMF_RESULT_SUCCESS;
ipc_mapped_handle_cache_global_t *cache_global =
Expand All @@ -78,8 +94,7 @@ umf_result_t umfIpcCacheGlobalInit(void) {
goto err_mutex_destroy;
}

// TODO: make max_size configurable via environment variable
cache_global->max_size = 0;
cache_global->max_size = umfIpcCacheGlobalInitMaxOpenedHandles();
cache_global->cur_size = 0;
cache_global->lru_list = NULL;

Expand Down
Loading