semaphore => spinlock in {get|put}name

Jakub Jelinek (jj@sunsite.ms.mff.cuni.cz)
Mon, 9 Mar 1998 09:14:05 +0100 (MET)


Hi!

Is there any reason why do we use an expensive semaphore instead of a cheap
spinlock?

--- fs/namei.c.xx Mon Feb 9 17:44:02 1998
+++ fs/namei.c Mon Mar 9 08:53:56 1998
@@ -24,6 +24,7 @@
#include <linux/smp_lock.h>
#include <linux/quotaops.h>

+#include <asm/spinlock.h>
#include <asm/uaccess.h>
#include <asm/unaligned.h>
#include <asm/semaphore.h>
@@ -81,7 +82,7 @@

char * getname_quicklist = NULL;
int getname_quickcount = 0;
-struct semaphore getname_quicklock = MUTEX;
+spinlock_t getname_quicklock = SPIN_LOCK_UNLOCKED;

/* Tuning: increase locality by reusing same pages again...
* if getname_quicklist becomes too long on low memory machines, either a limit
@@ -91,7 +92,7 @@
static inline char * get_page(void)
{
char * res;
- down(&getname_quicklock);
+ spin_lock(&getname_quicklock);
res = getname_quicklist;
if (res) {
#ifdef DEBUG
@@ -105,20 +106,20 @@
getname_quicklist = *(char**)res;
getname_quickcount--;
}
- else
+ spin_unlock(&getname_quicklock);
+ if (!res)
res = (char*)__get_free_page(GFP_KERNEL);
- up(&getname_quicklock);
return res;
}

inline void putname(char * name)
{
if (name) {
- down(&getname_quicklock);
+ spin_lock(&getname_quicklock);
*(char**)name = getname_quicklist;
getname_quicklist = name;
getname_quickcount++;
- up(&getname_quicklock);
+ spin_unlock(&getname_quicklock);
}
/* if a getname_quicklist limit is necessary to introduce, call
* free_page((unsigned long) name);
--- arch/sparc64/kernel/sys_sparc32.c.xx Mon Feb 9 01:08:57 1998
+++ arch/sparc64/kernel/sys_sparc32.c Mon Mar 9 09:02:42 1998
@@ -59,7 +59,7 @@

extern char * getname_quicklist;
extern int getname_quickcount;
-extern struct semaphore getname_quicklock;
+extern spinlock_t getname_quicklock;
extern int kerneld_msqid;

/* Tuning: increase locality by reusing same pages again...
@@ -70,15 +70,15 @@
static inline char * get_page(void)
{
char * res;
- down(&getname_quicklock);
+ spin_lock(&getname_quicklock);
res = getname_quicklist;
if (res) {
getname_quicklist = *(char**)res;
getname_quickcount--;
}
- else
+ spin_unlock(&getname_quicklock);
+ if (!res)
res = (char*)__get_free_page(GFP_KERNEL);
- up(&getname_quicklock);
return res;
}

Cheers,
Jakub
___________________________________________________________________
Jakub Jelinek | jj@sunsite.mff.cuni.cz | http://sunsite.mff.cuni.cz
Administrator of SunSITE Czech Republic, MFF, Charles University
___________________________________________________________________
Ultralinux - first 64bit OS to take full power of the UltraSparc
Linux version 2.1.89 on a sparc64 machine (498.80 BogoMips).
___________________________________________________________________

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu