-
Notifications
You must be signed in to change notification settings - Fork 37
[disjoint] Add CTL memory used/reserved metrics #1430
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,8 +72,84 @@ static umf_result_t CTL_WRITE_HANDLER(name)(void *ctx, | |
return UMF_RESULT_SUCCESS; | ||
} | ||
|
||
static const umf_ctl_node_t CTL_NODE(disjoint)[] = {CTL_LEAF_RW(name), | ||
CTL_NODE_END}; | ||
static umf_result_t CTL_READ_HANDLER(used_memory)( | ||
void *ctx, umf_ctl_query_source_t source, void *arg, size_t size, | ||
umf_ctl_index_utlist_t *indexes, const char *extra_name, | ||
umf_ctl_query_type_t queryType) { | ||
(void)source, (void)indexes, (void)queryType, (void)extra_name; | ||
disjoint_pool_t *pool = (disjoint_pool_t *)ctx; | ||
|
||
if (arg == NULL || size < sizeof(size_t)) { | ||
return UMF_RESULT_ERROR_INVALID_ARGUMENT; | ||
} | ||
|
||
size_t used_memory = 0; | ||
|
||
// Calculate used memory across all buckets | ||
for (size_t i = 0; i < pool->buckets_num; i++) { | ||
bucket_t *bucket = pool->buckets[i]; | ||
utils_mutex_lock(&bucket->bucket_lock); | ||
|
||
// Count allocated chunks in available slabs | ||
slab_list_item_t *it; | ||
for (it = bucket->available_slabs; it != NULL; it = it->next) { | ||
slab_t *slab = it->val; | ||
used_memory += slab->num_chunks_allocated * bucket->size; | ||
} | ||
|
||
// Count allocated chunks in unavailable slabs (all chunks allocated) | ||
for (it = bucket->unavailable_slabs; it != NULL; it = it->next) { | ||
slab_t *slab = it->val; | ||
used_memory += slab->num_chunks_allocated * bucket->size; | ||
} | ||
|
||
utils_mutex_unlock(&bucket->bucket_lock); | ||
} | ||
|
||
*(size_t *)arg = used_memory; | ||
return UMF_RESULT_SUCCESS; | ||
} | ||
|
||
static umf_result_t CTL_READ_HANDLER(reserved_memory)( | ||
void *ctx, umf_ctl_query_source_t source, void *arg, size_t size, | ||
umf_ctl_index_utlist_t *indexes, const char *extra_name, | ||
umf_ctl_query_type_t queryType) { | ||
(void)source, (void)indexes, (void)queryType, (void)extra_name; | ||
disjoint_pool_t *pool = (disjoint_pool_t *)ctx; | ||
|
||
if (arg == NULL || size < sizeof(size_t)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dito |
||
return UMF_RESULT_ERROR_INVALID_ARGUMENT; | ||
} | ||
|
||
size_t reserved_memory = 0; | ||
|
||
// Calculate reserved memory across all buckets | ||
for (size_t i = 0; i < pool->buckets_num; i++) { | ||
bucket_t *bucket = pool->buckets[i]; | ||
utils_mutex_lock(&bucket->bucket_lock); | ||
|
||
// Count all slabs (both available and unavailable) | ||
slab_list_item_t *it; | ||
for (it = bucket->available_slabs; it != NULL; it = it->next) { | ||
slab_t *slab = it->val; | ||
reserved_memory += slab->slab_size; | ||
} | ||
|
||
for (it = bucket->unavailable_slabs; it != NULL; it = it->next) { | ||
slab_t *slab = it->val; | ||
reserved_memory += slab->slab_size; | ||
} | ||
|
||
utils_mutex_unlock(&bucket->bucket_lock); | ||
} | ||
|
||
*(size_t *)arg = reserved_memory; | ||
return UMF_RESULT_SUCCESS; | ||
} | ||
|
||
static const umf_ctl_node_t CTL_NODE(disjoint)[] = { | ||
CTL_LEAF_RW(name), CTL_LEAF_RO(used_memory), CTL_LEAF_RO(reserved_memory), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used memory should be in the stats subtree |
||
CTL_NODE_END}; | ||
|
||
static void initialize_disjoint_ctl(void) { | ||
CTL_REGISTER_MODULE(&disjoint_ctl_root, disjoint); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size != sizeof....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it really have to be an exact size? Isn't
<
enough?