Skip to content

Commit d7775a9

Browse files
committed
Implement size limit for the cache of opened IPC handles
1 parent bf8d0d8 commit d7775a9

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/ipc_cache.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ typedef struct ipc_mapped_handle_cache_t {
5454

5555
ipc_mapped_handle_cache_global_t *IPC_MAPPED_CACHE_GLOBAL = NULL;
5656

57+
// Returns value of the UMF_MAX_OPENED_IPC_HANDLES environment variable
58+
// or 0 if it is not set.
59+
static size_t umfIpcCacheGlobalInitMaxOpenedHandles(void) {
60+
const char *max_size_str = getenv("UMF_MAX_OPENED_IPC_HANDLES");
61+
if (max_size_str) {
62+
char *endptr;
63+
size_t max_size = strtoul(max_size_str, &endptr, 10);
64+
if (*endptr == '\0') {
65+
return max_size;
66+
}
67+
LOG_ERR("Invalid value of UMF_MAX_OPENED_IPC_HANDLES: %s",
68+
max_size_str);
69+
}
70+
return 0;
71+
}
72+
5773
umf_result_t umfIpcCacheGlobalInit(void) {
5874
umf_result_t ret = UMF_RESULT_SUCCESS;
5975
ipc_mapped_handle_cache_global_t *cache_global =
@@ -78,8 +94,7 @@ umf_result_t umfIpcCacheGlobalInit(void) {
7894
goto err_mutex_destroy;
7995
}
8096

81-
// TODO: make max_size configurable via environment variable
82-
cache_global->max_size = 0;
97+
cache_global->max_size = umfIpcCacheGlobalInitMaxOpenedHandles();
8398
cache_global->cur_size = 0;
8499
cache_global->lru_list = NULL;
85100

0 commit comments

Comments
 (0)