@@ -33,6 +33,7 @@ static char *DEFAULT_NAME = "disjoint";
33
33
struct ctl disjoint_ctl_root ;
34
34
static UTIL_ONCE_FLAG ctl_initialized = UTIL_ONCE_FLAG_INIT ;
35
35
36
+ // CTL: name attribute
36
37
static int CTL_READ_HANDLER (name )(void * ctx , umf_ctl_query_source_t source ,
37
38
void * arg , size_t size ,
38
39
umf_ctl_index_utlist_t * indexes ,
@@ -66,8 +67,30 @@ static int CTL_WRITE_HANDLER(name)(void *ctx, umf_ctl_query_source_t source,
66
67
return 0 ;
67
68
}
68
69
69
- static const umf_ctl_node_t CTL_NODE (disjoint )[] = {CTL_LEAF_RW (name ),
70
- CTL_NODE_END };
70
+ // CTL: allocation counters
71
+ uint64_t allocation_balance = 0 ;
72
+
73
+ static int CTL_READ_HANDLER (allocation_balance )(
74
+ void * ctx , umf_ctl_query_source_t source , void * arg , size_t size ,
75
+ umf_ctl_index_utlist_t * indexes , const char * extra_name ,
76
+ umf_ctl_query_type_t queryType ) {
77
+ (void )ctx , (void )source , (void )size , (void )indexes , (void )extra_name ,
78
+ (void )queryType ;
79
+ // Calculate from pool buckets
80
+ disjoint_pool_t * pool = (disjoint_pool_t * )ctx ;
81
+ printf ("Calculating allocation balance for pool: %p\n" , (void * )pool );
82
+ if (arg == NULL ) {
83
+ return -1 ;
84
+ }
85
+ uint64_t * balance = (uint64_t * )arg ;
86
+ * balance = 0 ;
87
+ utils_atomic_load_acquire_u64 (& allocation_balance , balance );
88
+
89
+ return 0 ;
90
+ }
91
+
92
+ static const umf_ctl_node_t CTL_NODE (disjoint )[] = {
93
+ CTL_LEAF_RW (name ), CTL_LEAF_RO (allocation_balance ), CTL_NODE_END };
71
94
72
95
static void initialize_disjoint_ctl (void ) {
73
96
CTL_REGISTER_MODULE (& disjoint_ctl_root , disjoint );
@@ -579,7 +602,6 @@ static void *disjoint_pool_allocate(disjoint_pool_t *pool, size_t size) {
579
602
}
580
603
581
604
void * ptr = NULL ;
582
-
583
605
if (size > pool -> params .max_poolable_size ) {
584
606
umf_result_t ret =
585
607
umfMemoryProviderAlloc (pool -> provider , size , 0 , & ptr );
@@ -755,7 +777,7 @@ umf_result_t disjoint_pool_initialize(umf_memory_provider_handle_t provider,
755
777
void * disjoint_pool_malloc (void * pool , size_t size ) {
756
778
disjoint_pool_t * hPool = (disjoint_pool_t * )pool ;
757
779
void * ptr = disjoint_pool_allocate (hPool , size );
758
-
780
+ utils_atomic_increment_u64 ( & allocation_balance );
759
781
return ptr ;
760
782
}
761
783
@@ -939,8 +961,9 @@ umf_result_t disjoint_pool_free(void *pool, void *ptr) {
939
961
if (ret != UMF_RESULT_SUCCESS ) {
940
962
TLS_last_allocation_error = ret ;
941
963
LOG_ERR ("deallocation from the memory provider failed" );
964
+ } else {
965
+ utils_atomic_decrement_u64 (& allocation_balance );
942
966
}
943
-
944
967
return ret ;
945
968
}
946
969
@@ -971,6 +994,9 @@ umf_result_t disjoint_pool_free(void *pool, void *ptr) {
971
994
critnib_release (disjoint_pool -> known_slabs , ref_slab );
972
995
973
996
if (disjoint_pool -> params .pool_trace > 1 ) {
997
+ printf ("Freeing %8zu %s bytes from %s -> %p\n" , bucket -> size ,
998
+ disjoint_pool -> params .name , (to_pool ? "pool" : "provider" ),
999
+ unaligned_ptr );
974
1000
bucket -> free_count ++ ;
975
1001
}
976
1002
@@ -985,7 +1011,7 @@ umf_result_t disjoint_pool_free(void *pool, void *ptr) {
985
1011
disjoint_pool_get_limits (disjoint_pool )-> total_size , name ,
986
1012
disjoint_pool -> params .cur_pool_size );
987
1013
}
988
-
1014
+ utils_atomic_decrement_u64 ( & allocation_balance );
989
1015
return UMF_RESULT_SUCCESS ;
990
1016
}
991
1017
0 commit comments