@@ -45,11 +45,14 @@ typedef struct umf_os_memory_provider_config_t {
45
45
int traces ; // log level of debug traces
46
46
} umf_os_memory_provider_config_t ;
47
47
48
+ #define NODESET_STR_BUF_LEN 1024
49
+
48
50
typedef struct os_memory_provider_t {
49
51
unsigned protection ; // combination of OS-specific protection flags
50
52
51
53
// NUMA config
52
54
hwloc_bitmap_t nodeset ;
55
+ char * nodeset_str_buf ; // allocated only if traces==1
53
56
hwloc_membind_policy_t numa_policy ;
54
57
int numa_flags ; // combination of hwloc flags
55
58
@@ -274,14 +277,18 @@ static umf_result_t os_initialize(void *params, void **provider) {
274
277
}
275
278
276
279
if (os_provider -> traces ) {
277
- char * strp = NULL ;
278
- hwloc_bitmap_list_asprintf (& strp , os_provider -> nodeset );
279
-
280
- if (strp ) {
281
- printf ("OS provider initialized with NUMA nodes: %s\n" , strp );
280
+ os_provider -> nodeset_str_buf = umf_ba_global_alloc (NODESET_STR_BUF_LEN );
281
+ if (!os_provider -> nodeset_str_buf ) {
282
+ fprintf (stderr ,
283
+ "Allocating memory for printing NUMA nodes failed\n" );
284
+ } else {
285
+ if (hwloc_bitmap_list_snprintf (os_provider -> nodeset_str_buf ,
286
+ NODESET_STR_BUF_LEN ,
287
+ os_provider -> nodeset )) {
288
+ printf ("OS provider initialized with NUMA nodes: %s\n" ,
289
+ os_provider -> nodeset_str_buf );
290
+ }
282
291
}
283
-
284
- free (strp );
285
292
}
286
293
287
294
* provider = os_provider ;
@@ -302,6 +309,10 @@ static void os_finalize(void *provider) {
302
309
}
303
310
304
311
os_memory_provider_t * os_provider = provider ;
312
+ if (os_provider -> traces && os_provider -> nodeset_str_buf ) {
313
+ umf_ba_global_free (os_provider -> nodeset_str_buf );
314
+ }
315
+
305
316
hwloc_bitmap_free (os_provider -> nodeset );
306
317
hwloc_topology_destroy (os_provider -> topo );
307
318
umf_ba_global_free (os_provider );
@@ -312,29 +323,32 @@ static umf_result_t os_get_min_page_size(void *provider, void *ptr,
312
323
313
324
static void print_numa_nodes (os_memory_provider_t * os_provider , void * addr ,
314
325
size_t size ) {
326
+
327
+ if (os_provider -> nodeset_str_buf == NULL ) {
328
+ // cannot print assigned NUMA node due to allocation failure in os_initialize()
329
+ return ;
330
+ }
331
+
315
332
hwloc_bitmap_t nodeset = hwloc_bitmap_alloc ();
316
333
if (!nodeset ) {
317
334
fprintf (stderr ,
318
335
"cannot print assigned NUMA node due to allocation failure\n" );
336
+ return ;
337
+ }
338
+
339
+ int ret = hwloc_get_area_memlocation (os_provider -> topo , addr , 1 , nodeset ,
340
+ HWLOC_MEMBIND_BYNODESET );
341
+ if (ret ) {
342
+ fprintf (stderr , "cannot print assigned NUMA node (errno = %i)\n" ,
343
+ errno );
344
+ perror ("get_mempolicy()" );
319
345
} else {
320
- int ret = hwloc_get_area_memlocation (os_provider -> topo , addr , 1 ,
321
- nodeset , HWLOC_MEMBIND_BYNODESET );
322
- if (ret ) {
323
- fprintf (stderr , "cannot print assigned NUMA node (errno = %i)\n" ,
324
- errno );
325
- perror ("get_mempolicy()" );
346
+ if (hwloc_bitmap_list_snprintf (os_provider -> nodeset_str_buf ,
347
+ NODESET_STR_BUF_LEN , nodeset )) {
348
+ printf ("alloc(%zu) = 0x%llx, allocate on NUMA nodes = %s\n" , size ,
349
+ (unsigned long long )addr , os_provider -> nodeset_str_buf );
326
350
} else {
327
- char * strp = NULL ;
328
- hwloc_bitmap_list_asprintf (& strp , nodeset );
329
-
330
- if (!strp ) {
331
- fprintf (stderr , "cannot print assigned NUMA node due to "
332
- "allocation failure\n" );
333
- } else {
334
- printf ("alloc(%zu) = 0x%llx, allocate on NUMA nodes = %s\n" ,
335
- size , (unsigned long long )addr , strp );
336
- }
337
- free (strp );
351
+ fprintf (stderr , "cannot print assigned NUMA node\n" );
338
352
}
339
353
}
340
354
0 commit comments