From: Lukas Czerner <lczerner@redhat.com>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH 3/3] e2fsprogs: use mallinfo2 instead of mallinfo if available
Date: Thu, 17 Feb 2022 10:25:00 +0100 [thread overview]
Message-ID: <20220217092500.40525-3-lczerner@redhat.com> (raw)
In-Reply-To: <20220217092500.40525-1-lczerner@redhat.com>
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 <lczerner@redhat.com>
---
configure | 2 +-
configure.ac | 1 +
e2fsck/iscan.c | 11 ++++++++++-
e2fsck/util.c | 11 ++++++++++-
lib/config.h.in | 3 +++
resize/resource_track.c | 13 ++++++++++---
6 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/configure b/configure
index effd929d..530bc77c 100755
--- a/configure
+++ b/configure
@@ -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"
diff --git a/configure.ac b/configure.ac
index dff3d1ca..8acc4e1c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1214,6 +1214,7 @@ AC_CHECK_FUNCS(m4_flatten([
llseek
lseek64
mallinfo
+ mallinfo2
mbstowcs
memalign
mempcpy
diff --git a/e2fsck/iscan.c b/e2fsck/iscan.c
index 607e4752..33c6a4cd 100644
--- a/e2fsck/iscan.c
+++ b/e2fsck/iscan.c
@@ -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();
diff --git a/e2fsck/util.c b/e2fsck/util.c
index 3fe3c988..42740d9e 100644
--- a/e2fsck/util.c
+++ b/e2fsck/util.c
@@ -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();
diff --git a/lib/config.h.in b/lib/config.h.in
index 9c9de65d..b5856bb5 100644
--- a/lib/config.h.in
+++ b/lib/config.h.in
@@ -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
diff --git a/resize/resource_track.c b/resize/resource_track.c
index f0efe114..f4667060 100644
--- a/resize/resource_track.c
+++ b/resize/resource_track.c
@@ -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;
@@ -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), ",
--
2.34.1
next prev parent reply other threads:[~2022-02-17 9:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-17 9:24 [PATCH 1/3] resize2fs: remove unused variable 'c' Lukas Czerner
2022-02-17 9:24 ` [PATCH 2/3] libss: fix possible NULL pointer dereferece on allocation failure Lukas Czerner
2022-02-17 9:25 ` Lukas Czerner [this message]
2022-02-28 23:49 ` [PATCH 3/3] e2fsprogs: use mallinfo2 instead of mallinfo if available Andreas Dilger
2022-02-28 23:50 ` Andreas Dilger
2022-02-28 23:51 ` [PATCH 1/3] resize2fs: remove unused variable 'c' Andreas Dilger
2022-04-28 17:16 ` Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220217092500.40525-3-lczerner@redhat.com \
--to=lczerner@redhat.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.