Skip to content

Commit

Permalink
#1513: use mallinfo2 when available
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4rs committed May 12, 2022
1 parent a7beeaa commit f0fd4f8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmake/check_system_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ check_function_exists(sysconf vt_has_sysconf)

set(CMAKE_REQUIRED_INCLUDES "malloc.h")
check_function_exists(mallinfo vt_has_mallinfo)
check_function_exists(mallinfo2 vt_has_mallinfo2)

set(CMAKE_REQUIRED_INCLUDES "sys/resource.h")
check_function_exists(getrusage vt_has_getrusage)
Expand Down
1 change: 1 addition & 0 deletions cmake_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#cmakedefine vt_has_pclose
#cmakedefine vt_has_sbrk
#cmakedefine vt_has_mallinfo
#cmakedefine vt_has_mallinfo2
#cmakedefine vt_has_getrusage
#cmakedefine vt_has_sysinfo
#cmakedefine vt_has_mach_task_self
Expand Down
16 changes: 10 additions & 6 deletions src/vt/utils/memory/memory_usage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,17 @@ std::string PS::getName() {
}

std::size_t Mallinfo::getUsage() {
# if defined(vt_has_mallinfo) && defined(vt_has_malloc_h) && !vt_check_enabled(mimalloc)
struct mallinfo mi = mallinfo();
unsigned int blocks = mi.uordblks;
return static_cast<std::size_t>(blocks);
# else
return 0;
#if vt_check_enabled(mimalloc) || \
!defined(vt_has_mallinfo) && !defined(vt_has_mallinfo2)
return 0;
# endif

#if defined(vt_has_mallinfo2)
auto mi = mallinfo2();
#elif defined(vt_has_mallinfo)
auto mi = mallinfo();
#endif
return static_cast<std::size_t>(mi.uordblks);
}

std::string Mallinfo::getName() {
Expand Down

0 comments on commit f0fd4f8

Please sign in to comment.