public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Arkadiusz Mi??kiewicz <arekm@maven.pl>
Cc: Christoph Hellwig <hch@infradead.org>, xfs@oss.sgi.com
Subject: Re: xfs_repair fails with corrupt dinode 17491441757, extent total = 1, nblocks = 0.  This is a bug.
Date: Thu, 3 Nov 2011 07:54:29 -0400	[thread overview]
Message-ID: <20111103115429.GA15726@infradead.org> (raw)
In-Reply-To: <20111103110306.GA8382@infradead.org>

[-- Attachment #1: Type: text/plain, Size: 78 bytes --]

Can you give this patch a quick try on the image in that constrained
setup?



[-- Attachment #2: libxfs-estimate-free-memory-better --]
[-- Type: text/plain, Size: 6213 bytes --]

Index: xfsprogs-dev/libxfs/linux.c
===================================================================
--- xfsprogs-dev.orig/libxfs/linux.c	2011-11-03 12:01:14.213689743 +0100
+++ xfsprogs-dev/libxfs/linux.c	2011-11-03 12:46:56.928191650 +0100
@@ -207,8 +207,13 @@ platform_nproc(void)
 	return sysconf(_SC_NPROCESSORS_ONLN);
 }
 
+/*
+ * Return the memory that we can use freely.
+ *
+ * The return value is in kilobytes.
+ */
 unsigned long
-platform_physmem(void)
+platform_freemem(void)
 {
 	struct sysinfo  si;
 
@@ -217,5 +222,14 @@ platform_physmem(void)
 			progname);
 		exit(1);
 	}
-	return (si.totalram >> 10) * si.mem_unit;	/* kilobytes */
+
+	/*
+	 * Assume we can use memory that is marked free.  This is a very
+	 * conservative approximation given that there might be a lot of
+	 * pagecache that is easily reclaimable, but the only way to figure
+	 * out pagecache size is by parsing /proc/meminfo, and the format
+	 * of that file keeps changing.  This approach is still better than
+	 * guessing based on si.totalram which might be highly overestimated.
+	 */
+	return (si.freeram >> 10) * si.mem_unit;
 }
Index: xfsprogs-dev/include/libxfs.h
===================================================================
--- xfsprogs-dev.orig/include/libxfs.h	2011-11-03 12:29:02.001691672 +0100
+++ xfsprogs-dev/include/libxfs.h	2011-11-03 12:31:49.780691838 +0100
@@ -475,7 +475,7 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE
 
 #define LIBXFS_BBTOOFF64(bbs)	(((xfs_off_t)(bbs)) << BBSHIFT)
 extern int		libxfs_nproc(void);
-extern unsigned long	libxfs_physmem(void);	/* in kilobytes */
+extern unsigned long	libxfs_freemem(void);	/* in kilobytes */
 
 #include <xfs/xfs_ialloc.h>
 #include <xfs/xfs_rtalloc.h>
Index: xfsprogs-dev/libxfs/darwin.c
===================================================================
--- xfsprogs-dev.orig/libxfs/darwin.c	2011-11-03 12:29:02.017691106 +0100
+++ xfsprogs-dev/libxfs/darwin.c	2011-11-03 12:40:10.720691752 +0100
@@ -128,18 +128,27 @@ platform_nproc(void)
 	return ncpu;
 }
 
+/*
+ * Return the memory that we can use freely.
+ *
+ * The return value is in kilobytes.
+ */
 unsigned long
-platform_physmem(void)
+platform_freemem(void)
 {
-	unsigned long	physmem;
-	size_t		len = sizeof(physmem);
+	unsigned long	freemem;
+	size_t		len = sizeof(freemem);
 	static int	mib[2] = {CTL_HW, HW_PHYSMEM};
 
-	if (sysctl(mib, 2, &physmem, &len, NULL, 0) < 0) {
+	if (sysctl(mib, 2, &freemem, &len, NULL, 0) < 0) {
 		fprintf(stderr, _("%s: can't determine memory size\n"),
 			progname);
 		exit(1);
 	}
-	return physmem >> 10;
+
+ 	/*
+	 * Assume we can use approximately 3/4 of the physical memory.
+	 */
+	return (freemem >> (10 + 2)) * 3;
 }
 
Index: xfsprogs-dev/libxfs/freebsd.c
===================================================================
--- xfsprogs-dev.orig/libxfs/freebsd.c	2011-11-03 12:29:02.037693919 +0100
+++ xfsprogs-dev/libxfs/freebsd.c	2011-11-03 12:40:19.000190942 +0100
@@ -187,17 +187,26 @@ platform_nproc(void)
 	return ncpu;
 }
 
+/*
+ * Return the memory that we can use freely.
+ *
+ * The return value is in kilobytes.
+ */
 unsigned long
-platform_physmem(void)
+platform_freemem(void)
 {
-	unsigned long	physmem;
-	size_t		len = sizeof(physmem);
+	unsigned long	freemem;
+	size_t		len = sizeof(freemem);
 	static int	mib[2] = {CTL_HW, HW_PHYSMEM};
 
-	if (sysctl(mib, 2, &physmem, &len, NULL, 0) < 0) {
+	if (sysctl(mib, 2, &freemem, &len, NULL, 0) < 0) {
 		fprintf(stderr, _("%s: can't determine memory size\n"),
 			progname);
 		exit(1);
 	}
-	return physmem >> 10;
+
+ 	/*
+	 * Assume we can use approximately 3/4 of the physical memory.
+	 */
+	return (freemem >> (10 + 2)) * 3;
 }
Index: xfsprogs-dev/libxfs/init.c
===================================================================
--- xfsprogs-dev.orig/libxfs/init.c	2011-11-03 12:29:02.057690208 +0100
+++ xfsprogs-dev/libxfs/init.c	2011-11-03 12:29:50.044192568 +0100
@@ -862,7 +862,7 @@ libxfs_nproc(void)
 }
 
 unsigned long
-libxfs_physmem(void)
+libxfs_freemem(void)
 {
-	return platform_physmem();
+	return platform_freemem();
 }
Index: xfsprogs-dev/libxfs/init.h
===================================================================
--- xfsprogs-dev.orig/libxfs/init.h	2011-11-03 12:29:02.077690698 +0100
+++ xfsprogs-dev/libxfs/init.h	2011-11-03 12:29:52.296691230 +0100
@@ -32,7 +32,7 @@ extern char *platform_findblockpath (cha
 extern int platform_direct_blockdev (void);
 extern int platform_align_blockdev (void);
 extern int platform_nproc(void);
-extern unsigned long platform_physmem(void);	/* in kilobytes */
+extern unsigned long platform_freemem(void);	/* in kilobytes */
 extern int platform_has_uuid;
 
 #endif	/* LIBXFS_INIT_H */
Index: xfsprogs-dev/libxfs/irix.c
===================================================================
--- xfsprogs-dev.orig/libxfs/irix.c	2011-11-03 12:29:02.097691363 +0100
+++ xfsprogs-dev/libxfs/irix.c	2011-11-03 12:42:59.724691783 +0100
@@ -97,8 +97,13 @@ platform_nproc(void)
 	return sysmp(MP_NPROCS);
 }
 
+/*
+ * Return the memory that we can use freely.
+ *
+ * The return value is in kilobytes.
+ */
 unsigned long
-platform_physmem(void)
+platform_freemem(void)
 {
 	struct rminfo ri;
 
@@ -107,5 +112,9 @@ platform_physmem(void)
 			progname);
 		exit(1);
 	}
-	return (ri.physmem >> 10) * getpagesize();	/* kilobytes */
-}
\ No newline at end of file
+
+	/*
+	 * Assume we can use all free memory.
+	 */
+	return (ri.freemem >> 10) * getpagesize();	/* kilobytes */
+}
Index: xfsprogs-dev/repair/xfs_repair.c
===================================================================
--- xfsprogs-dev.orig/repair/xfs_repair.c	2011-11-03 12:29:02.117690613 +0100
+++ xfsprogs-dev/repair/xfs_repair.c	2011-11-03 12:32:42.348190446 +0100
@@ -631,8 +631,11 @@ main(int argc, char **argv)
 		mem_used = (mp->m_sb.sb_icount >> (10 - 2)) +
 					(mp->m_sb.sb_dblocks >> (10 + 1)) +
 					50000;	/* rough estimate of 50MB overhead */
-		max_mem = max_mem_specified ? max_mem_specified * 1024 :
-						libxfs_physmem() * 3 / 4;
+
+		if (max_mem_specified)
+			max_mem = max_mem_specified * 1024;
+		else
+			max_mem = libxfs_freemem();
 
 		if (getrlimit(RLIMIT_AS, &rlim) != -1 &&
 					rlim.rlim_cur != RLIM_INFINITY) {

[-- Attachment #3: Type: text/plain, Size: 121 bytes --]

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  reply	other threads:[~2011-11-03 11:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-31 10:56 xfs_repair fails with corrupt dinode 17491441757, extent total = 1, nblocks = 0. This is a bug Arkadiusz Miśkiewicz
2011-11-03 10:26 ` Christoph Hellwig
2011-11-03 10:40   ` Arkadiusz Miśkiewicz
2011-11-03 10:48     ` Christoph Hellwig
2011-11-03 10:57       ` Arkadiusz Miśkiewicz
2011-11-03 11:03         ` Christoph Hellwig
2011-11-03 11:54           ` Christoph Hellwig [this message]
2011-11-03 20:02             ` Arkadiusz Miśkiewicz
2011-11-03 20:21           ` Arkadiusz Miśkiewicz
2011-11-06 22:19 ` Arkadiusz Miśkiewicz

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=20111103115429.GA15726@infradead.org \
    --to=hch@infradead.org \
    --cc=arekm@maven.pl \
    --cc=xfs@oss.sgi.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox