[OpenAFS-devel] [PATCH] crget() memory allocation oddity

chas williams - CONTRACTOR chas@cmf.nrl.navy.mil
Tue, 06 Jun 2006 09:31:22 -0400


This is a multipart MIME message.

--==_Exmh_1149600459_263330
Content-Type: text/plain; charset=us-ascii

In message <44854E98.8040700@pclella.cern.ch>,Rainer Toebbicke writes:
>We're running with a similar patch since a few days on some machines 
>without ill effects.

along these lines, try the following patch.  it does away with the
cred pool.  bonnie++ doesnt seem to show much of a performance difference
(this was tested on a 2.6 kernel):

Version 1.02c       ------Sequential Create------ --------Random Create--------
relax               -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
              files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
kmalloc/kfree    16   111  21  1740  81   113  12   122  23   544  42   182  14
                 16   116  22  1740  82   115  12   111  21   549  42   178  14

cred_pool        16   107  21  1742  82   116  12   111  22   548  43   179  14
                 16   105  19  1778  81   117  12   115  21   548  43   180  14

this could just be the result of dropping some of the redundant operations
like memset(,0,) for every crget().  also, crdup() seems to miss copying the
cr_rgid.  you could probably also get away with just copying cr_ngroups
instead of NGROUPS for the 2.4 case (i can't test this).

--==_Exmh_1149600459_263330
Content-Type: text/plain ; name="blah"; charset=us-ascii
Content-Description: blah
Content-Disposition: attachment; filename="blah"

Index: src/afs/LINUX/osi_machdep.h
===================================================================
--- src/afs/LINUX/osi_machdep.h	(revision 5)
+++ src/afs/LINUX/osi_machdep.h	(revision 7)
@@ -139,7 +139,6 @@
     gid_t cr_groups[NGROUPS];	/* 32 groups - empty set to NOGROUP */
     int cr_ngroups;
 #endif
-    struct cred *cr_next;
 } cred_t;
 #define AFS_UCRED cred
 #define AFS_PROC struct task_struct
Index: src/afs/LINUX/osi_cred.c
===================================================================
--- src/afs/LINUX/osi_cred.c	(revision 5)
+++ src/afs/LINUX/osi_cred.c	(revision 7)
@@ -20,49 +20,18 @@
 #include "afs/sysincludes.h"
 #include "afsincludes.h"
 
-/* Setup a pool for creds. Allocate several at a time. */
-#define CRED_ALLOC_STEP 29	/* at 140 bytes/cred = 4060 bytes. */
-
-
-static cred_t *cred_pool = NULL;
-int cred_allocs = 0;
-int ncreds_inuse = 0;
-
-/* Cred locking assumes current single threaded non-preemptive kernel.
- * Also assuming a fast path through both down and up if no waiters. Otherwise,
- * test if no creds in pool before grabbing lock in crfree().
- */
-#if defined(AFS_LINUX24_ENV)
-static DECLARE_MUTEX(linux_cred_pool_lock);
-#else
-static struct semaphore linux_cred_pool_lock = MUTEX;
-#endif
-#define CRED_LOCK() down(&linux_cred_pool_lock)
-#define CRED_UNLOCK() up(&linux_cred_pool_lock)
-
 cred_t *
 crget(void)
 {
     cred_t *tmp;
-    int i;
 
-    CRED_LOCK();
-    if (!cred_pool) {
-	cred_allocs++;
-	cred_pool = (cred_t *) osi_Alloc(CRED_ALLOC_STEP * sizeof(cred_t));
-	if (!cred_pool)
+#if !defined(GFP_NOFS)
+#define GFP_NOFS GFP_KERNEL
+#endif
+    tmp = kmalloc(sizeof(cred_t), GFP_NOFS);
+    if (!tmp)
 	    osi_Panic("crget: No more memory for creds!\n");
 
-	for (i = 0; i < CRED_ALLOC_STEP - 1; i++)
-	    cred_pool[i].cr_next = (cred_t *) &cred_pool[i + 1];
-	cred_pool[i].cr_next = NULL;
-    }
-    tmp = cred_pool;
-    cred_pool = (cred_t *) tmp->cr_next;
-    ncreds_inuse++;
-    CRED_UNLOCK();
-
-    memset(tmp, 0, sizeof(cred_t));
     tmp->cr_ref = 1;
     return tmp;
 }
@@ -75,14 +44,7 @@
 	return;
     }
 
-#if defined(AFS_LINUX26_ENV)
-    put_group_info(cr->cr_group_info);
-#endif
-    CRED_LOCK();
-    cr->cr_next = (cred_t *) cred_pool;
-    cred_pool = cr;
-    CRED_UNLOCK();
-    ncreds_inuse--;
+    kfree(cr);
 }
 
 
@@ -95,6 +57,7 @@
     tmp->cr_uid = cr->cr_uid;
     tmp->cr_ruid = cr->cr_ruid;
     tmp->cr_gid = cr->cr_gid;
+    tmp->cr_rgid = cr->cr_rgid;
 
 #if defined(AFS_LINUX26_ENV)
     get_group_info(cr->cr_group_info);
@@ -104,7 +67,6 @@
     tmp->cr_ngroups = cr->cr_ngroups;
 #endif
 
-    tmp->cr_ref = 1;
     return tmp;
 }
 

--==_Exmh_1149600459_263330--