[OpenAFS-devel] lots of vmalloc failures lately...

Nickolai Zeldovich kolya@MIT.EDU
Mon, 26 Apr 2004 14:57:06 -0700


On Mon, 2004-04-26 at 09:04, Neulinger, Nathan wrote:
> The biggest problem here is that the alloc failure generates a log
> message that gives no information about where it was called from, and it
> usually doesn't oops till later in the code... 

If you want, you can try the untested patch below, applied to the
current checkout from CVS (which has an autoconf check to see if the
compiler supports __FUNCTION__).  This should tell you what allocations
are failing where.

Apologies if the patch appears to be broken -- I'm still not quite sure
of how my new mail agent (Evolution) behaves.  You can also grab it as 
http://mit.edu/kolya/tmp/afs-alloc-debug.

-- kolya

--- afs/afs_osi.c	21 Apr 2004 02:20:21 -0000	1.44
+++ afs/afs_osi.c	26 Apr 2004 21:50:30 -0000
@@ -422,10 +422,10 @@
 
 
 void *
-afs_osi_Alloc(size_t x)
+afs_osi_Alloc_debug(size_t x, char *func, int line)
 {
-    register struct osimem *tm = NULL;
-    register int size;
+    void *ptr = NULL;
+    int size = x;
 
     AFS_STATCNT(osi_Alloc);
     /* 0-length allocs may return NULL ptr from AFS_KALLOC, so we
special-case
@@ -435,20 +435,24 @@
 
     AFS_STATS(afs_stats_cmperf.OutStandingAllocs++);
     AFS_STATS(afs_stats_cmperf.OutStandingMemUsage += x);
+
 #ifdef AFS_LINUX20_ENV
-    return osi_linux_alloc(x, 1);
+    ptr = osi_linux_alloc(x, 1);
 #elif defined(AFS_FBSD_ENV)
-    return osi_fbsd_alloc(x, 1);
+    ptr = osi_fbsd_alloc(x, 1);
 #else
-    size = x;
-    tm = (struct osimem *)AFS_KALLOC(size);
+    ptr = AFS_KALLOC(size);
+#endif
+
+    if (!ptr) {
+	printf("Unable to allocate %d bytes at %s:%d\n", size, func, line);
 #ifdef	AFS_SUN_ENV
-    if (!tm)
 	osi_Panic("osi_Alloc: Couldn't allocate %d bytes; out of memory!\n",
 		  size);
 #endif
-    return (void *)tm;
-#endif
+    }
+
+    return ptr;
 }
 
 #if	defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV)

--- afs/afs_osi.h	11 Mar 2004 19:14:46 -0000	1.21
+++ afs/afs_osi.h	26 Apr 2004 21:50:30 -0000
@@ -114,6 +114,12 @@
 /*
  * Alloc declarations.
  */
+#ifdef HAVE_FUNCTION_MACRO
+#define afs_osi_Alloc(size) afs_osi_Alloc_debug((size), __FUNCTION__,
__LINE__)
+#else
+#define afs_osi_Alloc(size) afs_osi_Alloc_debug((size), "unknown", 0)
+#endif
+
 #define afs_osi_Alloc_NoSleep afs_osi_Alloc
 
 /*

--- afs/afs_prototypes.h	17 Mar 2004 06:43:34 -0000	1.47
+++ afs/afs_prototypes.h	26 Apr 2004 21:50:30 -0000
@@ -464,7 +464,7 @@
 extern void afs_osi_RxkRegister(void);
 extern void afs_osi_MaskSignals(void);
 extern void afs_osi_UnmaskRxkSignals(void);
-extern void *afs_osi_Alloc(size_t x);
+extern void *afs_osi_Alloc_debug(size_t x, char *func, int line);
 #ifndef afs_osi_Alloc_NoSleep
 extern void *afs_osi_Alloc_NoSleep(size_t x);
 #endif

--- afs/UKERNEL/afs_usrops.c	16 Apr 2004 00:34:38 -0000	1.25
+++ afs/UKERNEL/afs_usrops.c	26 Apr 2004 21:50:30 -0000
@@ -926,7 +926,7 @@
 static char *afs_check_string2 = "AFS_OSI_";
 
 void *
-afs_osi_Alloc(size_t size)
+afs_osi_Alloc_debug(size_t size, char *func, int line)
 {
     return malloc(size);
 }

--- rx/xdr.h	10 Mar 2004 23:01:54 -0000	1.11
+++ rx/xdr.h	26 Apr 2004 21:50:30 -0000
@@ -95,7 +95,12 @@
 #define	osi_free		afs_osi_Free
 
 /* keep here for now, 64 bit issues */
-extern void *afs_osi_Alloc(size_t x);
+extern void *afs_osi_Alloc_debug(size_t x, char *func, int line);
+#ifdef HAVE_FUNCTION_MACRO
+#define afs_osi_Alloc(size) afs_osi_Alloc_debug((size), __FUNCTION__,
__LINE__)
+#else
+#define afs_osi_Alloc(size) afs_osi_Alloc_debug((size), "unknown", 0)
+#endif
 #ifndef afs_osi_Alloc_NoSleep
 extern void *afs_osi_Alloc_NoSleep(size_t x);
 #endif