Skip to content

Commit

Permalink
Use mallinfo2 instead of mallinfo if available
Browse files Browse the repository at this point in the history
mallinfo has been deprecated with GNU C library version 2.33 in favor of
mallinfo2 which works exactly the same as mallinfo but with larger field
widths. Use mallinfo2 if available.

Signed-off-by: Lukas Czerner <[email protected]>
Reviewed-by: Andreas Dilger <[email protected]>
Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
Lukas Czerner authored and tytso committed Apr 28, 2022
1 parent a282671 commit 97079a7
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -11254,7 +11254,7 @@ fi
if test -n "$DLOPEN_LIB" ; then
ac_cv_func_dlopen=yes
fi
for ac_func in __secure_getenv add_key backtrace chflags dlopen fadvise64 fallocate fallocate64 fchown fcntl fdatasync fstat64 fsync ftruncate64 futimes getcwd getdtablesize getentropy gethostname getmntinfo getpwuid_r getrandom getrlimit getrusage jrand48 keyctl llistxattr llseek lseek64 mallinfo mbstowcs memalign mempcpy mmap msync nanosleep open64 pathconf posix_fadvise posix_fadvise64 posix_memalign prctl pread pwrite pread64 pwrite64 secure_getenv setmntent setresgid setresuid snprintf srandom stpcpy strcasecmp strdup strnlen strptime strtoull sync_file_range sysconf usleep utime utimes valloc
for ac_func in __secure_getenv add_key backtrace chflags dlopen fadvise64 fallocate fallocate64 fchown fcntl fdatasync fstat64 fsync ftruncate64 futimes getcwd getdtablesize getentropy gethostname getmntinfo getpwuid_r getrandom getrlimit getrusage jrand48 keyctl llistxattr llseek lseek64 mallinfo mallinfo2 mbstowcs memalign mempcpy mmap msync nanosleep open64 pathconf posix_fadvise posix_fadvise64 posix_memalign prctl pread pwrite pread64 pwrite64 secure_getenv setmntent setresgid setresuid snprintf srandom stpcpy strcasecmp strdup strnlen strptime strtoull sync_file_range sysconf usleep utime utimes valloc
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,7 @@ AC_CHECK_FUNCS(m4_flatten([
llseek
lseek64
mallinfo
mallinfo2
mbstowcs
memalign
mempcpy
Expand Down
11 changes: 10 additions & 1 deletion e2fsck/iscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@ void print_resource_track(const char *desc,
printf("%s: ", desc);

#define kbytes(x) (((unsigned long long)(x) + 1023) / 1024)
#ifdef HAVE_MALLINFO
#ifdef HAVE_MALLINFO2
if (1) {
struct mallinfo2 malloc_info = mallinfo2();

printf("Memory used: %lluk/%lluk (%lluk/%lluk), ",
kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
kbytes(malloc_info.uordblks),
kbytes(malloc_info.fordblks));
} else
#elif defined HAVE_MALLINFO
/* don't use mallinfo() if over 2GB used, since it returns "int" */
if ((char *)sbrk(0) - (char *)track->brk_start < 2LL << 30) {
struct mallinfo malloc_info = mallinfo();
Expand Down
11 changes: 10 additions & 1 deletion e2fsck/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,16 @@ void print_resource_track(e2fsck_t ctx, const char *desc,
log_out(ctx, "%s: ", desc);

#define kbytes(x) (((unsigned long long)(x) + 1023) / 1024)
#ifdef HAVE_MALLINFO
#ifdef HAVE_MALLINFO2
if (1) {
struct mallinfo2 malloc_info = mallinfo2();

log_out(ctx, _("Memory used: %lluk/%lluk (%lluk/%lluk), "),
kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
kbytes(malloc_info.uordblks),
kbytes(malloc_info.fordblks));
} else
#elif defined HAVE_MALLINFO
/* don't use mallinfo() if over 2GB used, since it returns "int" */
if ((char *)sbrk(0) - (char *)track->brk_start < 2LL << 30) {
struct mallinfo malloc_info = mallinfo();
Expand Down
3 changes: 3 additions & 0 deletions lib/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@
/* Define to 1 if you have the `mallinfo' function. */
#undef HAVE_MALLINFO

/* Define to 1 if you have the `mallinfo2' function. */
#undef HAVE_MALLINFO2

/* Define to 1 if you have the <malloc.h> header file. */
#undef HAVE_MALLOC_H

Expand Down
13 changes: 10 additions & 3 deletions resize/resource_track.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ void print_resource_track(ext2_resize_t rfs, struct resource_track *track,
#ifdef HAVE_GETRUSAGE
struct rusage r;
#endif
#ifdef HAVE_MALLINFO
struct mallinfo malloc_info;
#ifdef HAVE_MALLINFO2
struct mallinfo2 malloc_info;
#elif defined HAVE_MALLINFO
struct mallinfo malloc_info;
#endif
struct timeval time_end;

Expand All @@ -76,8 +78,13 @@ void print_resource_track(ext2_resize_t rfs, struct resource_track *track,
if (track->desc)
printf("%s: ", track->desc);

#ifdef HAVE_MALLINFO
#define kbytes(x) (((unsigned long)(x) + 1023) / 1024)
#ifdef HAVE_MALLINFO2
malloc_info = mallinfo2();
printf("Memory used: %luk/%luk (%luk/%luk), ",
kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
kbytes(malloc_info.uordblks), kbytes(malloc_info.fordblks));
#elif defined HAVE_MALLINFO

malloc_info = mallinfo();
printf("Memory used: %luk/%luk (%luk/%luk), ",
Expand Down

0 comments on commit 97079a7

Please sign in to comment.