Skip to content

Commit bcaba47

Browse files
authored
Merge pull request #1103 from vinser52/svinogra_refactoring
Refactoring of the memory tracker and IPC cache
2 parents 5a515c5 + fa9b0ea commit bcaba47

File tree

4 files changed

+129
-127
lines changed

4 files changed

+129
-127
lines changed

src/ipc_cache.c

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2024 Intel Corporation
3+
* Copyright (C) 2024-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -22,41 +22,41 @@
2222
#pragma warning(disable : 4702)
2323
#endif
2424

25-
struct ipc_handle_cache_entry_t;
25+
struct ipc_opened_cache_entry_t;
2626

27-
typedef struct ipc_handle_cache_entry_t *hash_map_t;
28-
typedef struct ipc_handle_cache_entry_t *lru_list_t;
27+
typedef struct ipc_opened_cache_entry_t *hash_map_t;
28+
typedef struct ipc_opened_cache_entry_t *lru_list_t;
2929

30-
typedef struct ipc_handle_cache_entry_t {
30+
typedef struct ipc_opened_cache_entry_t {
3131
UT_hash_handle hh;
32-
struct ipc_handle_cache_entry_t *next, *prev;
33-
ipc_mapped_handle_cache_key_t key;
32+
struct ipc_opened_cache_entry_t *next, *prev;
33+
ipc_opened_cache_key_t key;
3434
uint64_t ref_count;
3535
uint64_t handle_id;
3636
hash_map_t
3737
*hash_table; // pointer to the hash table to which the entry belongs
38-
ipc_mapped_handle_cache_value_t value;
39-
} ipc_handle_cache_entry_t;
38+
ipc_opened_cache_value_t value;
39+
} ipc_opened_cache_entry_t;
4040

41-
typedef struct ipc_mapped_handle_cache_global_t {
41+
typedef struct ipc_opened_cache_global_t {
4242
utils_mutex_t cache_lock;
4343
umf_ba_pool_t *cache_allocator;
4444
size_t max_size;
4545
size_t cur_size;
4646
lru_list_t lru_list;
47-
} ipc_mapped_handle_cache_global_t;
47+
} ipc_opened_cache_global_t;
4848

49-
typedef struct ipc_mapped_handle_cache_t {
50-
ipc_mapped_handle_cache_global_t *global;
49+
typedef struct ipc_opened_cache_t {
50+
ipc_opened_cache_global_t *global;
5151
hash_map_t hash_table;
52-
ipc_mapped_handle_cache_eviction_cb_t eviction_cb;
53-
} ipc_mapped_handle_cache_t;
52+
ipc_opened_cache_eviction_cb_t eviction_cb;
53+
} ipc_opened_cache_t;
5454

55-
ipc_mapped_handle_cache_global_t *IPC_MAPPED_CACHE_GLOBAL = NULL;
55+
ipc_opened_cache_global_t *IPC_OPENED_CACHE_GLOBAL = NULL;
5656

5757
umf_result_t umfIpcCacheGlobalInit(void) {
5858
umf_result_t ret = UMF_RESULT_SUCCESS;
59-
ipc_mapped_handle_cache_global_t *cache_global =
59+
ipc_opened_cache_global_t *cache_global =
6060
umf_ba_global_alloc(sizeof(*cache_global));
6161
if (!cache_global) {
6262
LOG_ERR("Failed to allocate memory for the IPC cache global data");
@@ -71,7 +71,7 @@ umf_result_t umfIpcCacheGlobalInit(void) {
7171
}
7272

7373
cache_global->cache_allocator =
74-
umf_ba_create(sizeof(ipc_handle_cache_entry_t));
74+
umf_ba_create(sizeof(ipc_opened_cache_entry_t));
7575
if (!cache_global->cache_allocator) {
7676
LOG_ERR("Failed to create IPC cache allocator");
7777
ret = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
@@ -83,7 +83,7 @@ umf_result_t umfIpcCacheGlobalInit(void) {
8383
cache_global->cur_size = 0;
8484
cache_global->lru_list = NULL;
8585

86-
IPC_MAPPED_CACHE_GLOBAL = cache_global;
86+
IPC_OPENED_CACHE_GLOBAL = cache_global;
8787
goto err_exit;
8888

8989
err_mutex_destroy:
@@ -97,15 +97,15 @@ umf_result_t umfIpcCacheGlobalInit(void) {
9797
#ifndef NDEBUG
9898
static size_t getGlobalLruListSize(lru_list_t lru_list) {
9999
size_t size = 0;
100-
ipc_handle_cache_entry_t *tmp;
100+
ipc_opened_cache_entry_t *tmp;
101101
DL_COUNT(lru_list, tmp, size);
102102
return size;
103103
}
104104
#endif /* NDEBUG */
105105

106106
void umfIpcCacheGlobalTearDown(void) {
107-
ipc_mapped_handle_cache_global_t *cache_global = IPC_MAPPED_CACHE_GLOBAL;
108-
IPC_MAPPED_CACHE_GLOBAL = NULL;
107+
ipc_opened_cache_global_t *cache_global = IPC_OPENED_CACHE_GLOBAL;
108+
IPC_OPENED_CACHE_GLOBAL = NULL;
109109

110110
if (!cache_global) {
111111
return;
@@ -119,31 +119,31 @@ void umfIpcCacheGlobalTearDown(void) {
119119
umf_ba_global_free(cache_global);
120120
}
121121

122-
ipc_mapped_handle_cache_handle_t umfIpcHandleMappedCacheCreate(
123-
ipc_mapped_handle_cache_eviction_cb_t eviction_cb) {
122+
ipc_opened_cache_handle_t
123+
umfIpcOpenedCacheCreate(ipc_opened_cache_eviction_cb_t eviction_cb) {
124124
if (eviction_cb == NULL) {
125125
LOG_ERR("Eviction callback is NULL");
126126
return NULL;
127127
}
128128

129-
ipc_mapped_handle_cache_t *cache = umf_ba_global_alloc(sizeof(*cache));
129+
ipc_opened_cache_t *cache = umf_ba_global_alloc(sizeof(*cache));
130130

131131
if (!cache) {
132132
LOG_ERR("Failed to allocate memory for the IPC cache");
133133
return NULL;
134134
}
135135

136-
assert(IPC_MAPPED_CACHE_GLOBAL != NULL);
136+
assert(IPC_OPENED_CACHE_GLOBAL != NULL);
137137

138-
cache->global = IPC_MAPPED_CACHE_GLOBAL;
138+
cache->global = IPC_OPENED_CACHE_GLOBAL;
139139
cache->hash_table = NULL;
140140
cache->eviction_cb = eviction_cb;
141141

142142
return cache;
143143
}
144144

145-
void umfIpcHandleMappedCacheDestroy(ipc_mapped_handle_cache_handle_t cache) {
146-
ipc_handle_cache_entry_t *entry, *tmp;
145+
void umfIpcOpenedCacheDestroy(ipc_opened_cache_handle_t cache) {
146+
ipc_opened_cache_entry_t *entry, *tmp;
147147
HASH_ITER(hh, cache->hash_table, entry, tmp) {
148148
DL_DELETE(cache->global->lru_list, entry);
149149
HASH_DEL(cache->hash_table, entry);
@@ -157,15 +157,14 @@ void umfIpcHandleMappedCacheDestroy(ipc_mapped_handle_cache_handle_t cache) {
157157
umf_ba_global_free(cache);
158158
}
159159

160-
umf_result_t
161-
umfIpcHandleMappedCacheGet(ipc_mapped_handle_cache_handle_t cache,
162-
const ipc_mapped_handle_cache_key_t *key,
163-
uint64_t handle_id,
164-
ipc_mapped_handle_cache_value_t **retEntry) {
165-
ipc_handle_cache_entry_t *entry = NULL;
160+
umf_result_t umfIpcOpenedCacheGet(ipc_opened_cache_handle_t cache,
161+
const ipc_opened_cache_key_t *key,
162+
uint64_t handle_id,
163+
ipc_opened_cache_value_t **retEntry) {
164+
ipc_opened_cache_entry_t *entry = NULL;
166165
umf_result_t ret = UMF_RESULT_SUCCESS;
167166
bool evicted = false;
168-
ipc_mapped_handle_cache_value_t evicted_value;
167+
ipc_opened_cache_value_t evicted_value;
169168

170169
if (!cache || !key || !retEntry) {
171170
LOG_ERR("Some arguments are NULL, cache=%p, key=%p, retEntry=%p",

src/ipc_cache.h

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2024 Intel Corporation
3+
* Copyright (C) 2024-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -14,39 +14,37 @@
1414

1515
#include "utils_concurrency.h"
1616

17-
typedef struct ipc_mapped_handle_cache_key_t {
17+
typedef struct ipc_opened_cache_key_t {
1818
void *remote_base_ptr;
1919
umf_memory_provider_handle_t local_provider;
2020
int remote_pid;
21-
} ipc_mapped_handle_cache_key_t;
21+
} ipc_opened_cache_key_t;
2222

23-
typedef struct ipc_mapped_handle_cache_value_t {
23+
typedef struct ipc_opened_cache_value_t {
2424
void *mapped_base_ptr;
2525
size_t mapped_size;
2626
utils_mutex_t mmap_lock;
27-
} ipc_mapped_handle_cache_value_t;
27+
} ipc_opened_cache_value_t;
2828

29-
struct ipc_mapped_handle_cache_t;
29+
struct ipc_opened_cache_t;
3030

31-
typedef struct ipc_mapped_handle_cache_t *ipc_mapped_handle_cache_handle_t;
31+
typedef struct ipc_opened_cache_t *ipc_opened_cache_handle_t;
3232

3333
umf_result_t umfIpcCacheGlobalInit(void);
3434
void umfIpcCacheGlobalTearDown(void);
3535

3636
// define pointer to the eviction callback function
37-
typedef void (*ipc_mapped_handle_cache_eviction_cb_t)(
38-
const ipc_mapped_handle_cache_key_t *key,
39-
const ipc_mapped_handle_cache_value_t *value);
37+
typedef void (*ipc_opened_cache_eviction_cb_t)(
38+
const ipc_opened_cache_key_t *key, const ipc_opened_cache_value_t *value);
4039

41-
ipc_mapped_handle_cache_handle_t umfIpcHandleMappedCacheCreate(
42-
ipc_mapped_handle_cache_eviction_cb_t eviction_cb);
40+
ipc_opened_cache_handle_t
41+
umfIpcOpenedCacheCreate(ipc_opened_cache_eviction_cb_t eviction_cb);
4342

44-
void umfIpcHandleMappedCacheDestroy(ipc_mapped_handle_cache_handle_t cache);
43+
void umfIpcOpenedCacheDestroy(ipc_opened_cache_handle_t cache);
4544

46-
umf_result_t
47-
umfIpcHandleMappedCacheGet(ipc_mapped_handle_cache_handle_t cache,
48-
const ipc_mapped_handle_cache_key_t *key,
49-
uint64_t handle_id,
50-
ipc_mapped_handle_cache_value_t **retEntry);
45+
umf_result_t umfIpcOpenedCacheGet(ipc_opened_cache_handle_t cache,
46+
const ipc_opened_cache_key_t *key,
47+
uint64_t handle_id,
48+
ipc_opened_cache_value_t **retEntry);
5149

5250
#endif /* UMF_IPC_CACHE_H */

0 commit comments

Comments
 (0)