All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: sandeen@sandeen.net, djwong@kernel.org
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 1/2] xfs_scrub: move to mallinfo2 when available
Date: Thu, 05 May 2022 09:04:05 -0700	[thread overview]
Message-ID: <165176664529.246897.6962083531265042879.stgit@magnolia> (raw)
In-Reply-To: <165176663972.246897.5479033385952013770.stgit@magnolia>

From: Darrick J. Wong <djwong@kernel.org>

Starting with glibc 2.35, the mallinfo library call has finally been
upgraded to return 64-bit memory usage quantities.  Migrate to the new
call, since it also warns about mallinfo being deprecated.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 configure.ac          |    1 +
 include/builddefs.in  |    1 +
 m4/package_libcdev.m4 |   18 ++++++++++++++++++
 scrub/Makefile        |    4 ++++
 scrub/xfs_scrub.c     |   47 +++++++++++++++++++++++++++++------------------
 5 files changed, 53 insertions(+), 18 deletions(-)


diff --git a/configure.ac b/configure.ac
index 160f64dd..4650d56c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -192,6 +192,7 @@ AC_HAVE_STATFS_FLAGS
 AC_HAVE_MAP_SYNC
 AC_HAVE_DEVMAPPER
 AC_HAVE_MALLINFO
+AC_HAVE_MALLINFO2
 AC_PACKAGE_WANT_ATTRIBUTES_H
 AC_HAVE_LIBATTR
 if test "$enable_scrub" = "yes"; then
diff --git a/include/builddefs.in b/include/builddefs.in
index 626db210..e0a2f3cb 100644
--- a/include/builddefs.in
+++ b/include/builddefs.in
@@ -115,6 +115,7 @@ HAVE_STATFS_FLAGS = @have_statfs_flags@
 HAVE_MAP_SYNC = @have_map_sync@
 HAVE_DEVMAPPER = @have_devmapper@
 HAVE_MALLINFO = @have_mallinfo@
+HAVE_MALLINFO2 = @have_mallinfo2@
 HAVE_LIBATTR = @have_libattr@
 HAVE_LIBICU = @have_libicu@
 HAVE_OPENAT = @have_openat@
diff --git a/m4/package_libcdev.m4 b/m4/package_libcdev.m4
index adab9bb9..8d05dc40 100644
--- a/m4/package_libcdev.m4
+++ b/m4/package_libcdev.m4
@@ -367,6 +367,24 @@ AC_DEFUN([AC_HAVE_MALLINFO],
     AC_SUBST(have_mallinfo)
   ])
 
+#
+# Check if we have a mallinfo2 libc call
+#
+AC_DEFUN([AC_HAVE_MALLINFO2],
+  [ AC_MSG_CHECKING([for mallinfo2 ])
+    AC_TRY_COMPILE([
+#include <malloc.h>
+    ], [
+         struct mallinfo2 test;
+
+         test.arena = 0; test.hblkhd = 0; test.uordblks = 0; test.fordblks = 0;
+         test = mallinfo2();
+    ], have_mallinfo2=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_mallinfo2)
+  ])
+
 #
 # Check if we have a openat call
 #
diff --git a/scrub/Makefile b/scrub/Makefile
index 74492fb6..aba14ed2 100644
--- a/scrub/Makefile
+++ b/scrub/Makefile
@@ -77,6 +77,10 @@ ifeq ($(HAVE_MALLINFO),yes)
 LCFLAGS += -DHAVE_MALLINFO
 endif
 
+ifeq ($(HAVE_MALLINFO2),yes)
+LCFLAGS += -DHAVE_MALLINFO2
+endif
+
 ifeq ($(HAVE_SYNCFS),yes)
 LCFLAGS += -DHAVE_SYNCFS
 endif
diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c
index 41839c26..7a0411b0 100644
--- a/scrub/xfs_scrub.c
+++ b/scrub/xfs_scrub.c
@@ -282,6 +282,34 @@ phase_start(
 	return error;
 }
 
+static inline unsigned long long
+kbytes(unsigned long long x)
+{
+	return (x + 1023) / 1024;
+}
+
+static void
+report_mem_usage(
+	const char			*phase,
+	const struct phase_rusage	*pi)
+{
+#if defined(HAVE_MALLINFO2) || defined(HAVE_MALLINFO)
+# ifdef HAVE_MALLINFO2
+	struct mallinfo2		mall_now = mallinfo2();
+# else
+	struct mallinfo			mall_now = mallinfo();
+# endif
+	fprintf(stdout, _("%sMemory used: %lluk/%lluk (%lluk/%lluk), "),
+		phase,
+		kbytes(mall_now.arena), kbytes(mall_now.hblkhd),
+		kbytes(mall_now.uordblks), kbytes(mall_now.fordblks));
+#else
+	fprintf(stdout, _("%sMemory used: %lluk, "),
+		phase,
+		kbytes(((char *) sbrk(0)) - ((char *) pi->brk_start)));
+#endif
+}
+
 /* Report usage stats. */
 static int
 phase_end(
@@ -289,9 +317,6 @@ phase_end(
 	unsigned int		phase)
 {
 	struct rusage		ruse_now;
-#ifdef HAVE_MALLINFO
-	struct mallinfo		mall_now;
-#endif
 	struct timeval		time_now;
 	char			phasebuf[DESCR_BUFSZ];
 	double			dt;
@@ -323,21 +348,7 @@ phase_end(
 	else
 		phasebuf[0] = 0;
 
-#define kbytes(x)	(((unsigned long)(x) + 1023) / 1024)
-#ifdef HAVE_MALLINFO
-
-	mall_now = mallinfo();
-	fprintf(stdout, _("%sMemory used: %luk/%luk (%luk/%luk), "),
-		phasebuf,
-		kbytes(mall_now.arena), kbytes(mall_now.hblkhd),
-		kbytes(mall_now.uordblks), kbytes(mall_now.fordblks));
-#else
-	fprintf(stdout, _("%sMemory used: %luk, "),
-		phasebuf,
-		(unsigned long) kbytes(((char *) sbrk(0)) -
-				       ((char *) pi->brk_start)));
-#endif
-#undef kbytes
+	report_mem_usage(phasebuf, pi);
 
 	fprintf(stdout, _("time: %5.2f/%5.2f/%5.2fs\n"),
 		timeval_subtract(&time_now, &pi->time),


  reply	other threads:[~2022-05-05 16:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-05 16:03 [PATCHSET 0/2] xfsprogs: random fixes Darrick J. Wong
2022-05-05 16:04 ` Darrick J. Wong [this message]
2022-05-05 19:28   ` [PATCH 1/2] xfs_scrub: move to mallinfo2 when available Eric Sandeen
2022-05-10  9:38   ` Christoph Hellwig
2022-05-05 16:04 ` [PATCH 2/2] xfs_db: fix a complaint about a printf buffer overrun Darrick J. Wong
2022-05-05 19:34   ` Eric Sandeen
2022-05-10  9:38   ` Christoph Hellwig
2022-05-10 21:30 ` [PATCH 3/2] xfs: note the removal of XFS_IOC_FSSETDM in the documentation Darrick J. Wong
2022-05-12 18:31   ` Eric Sandeen

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=165176664529.246897.6962083531265042879.stgit@magnolia \
    --to=djwong@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    /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.