patch-2.1.15 linux/fs/namei.c

Next file: linux/fs/ncpfs/sock.c
Previous file: linux/fs/ext2/file.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.14/linux/fs/namei.c linux/fs/namei.c
@@ -48,25 +48,42 @@
 	return retval;
 }
 
+/*
+ * This is a single page for faster getname.
+ *   If the page is available when entering getname, use it.
+ *   If the page is not available, call __get_free_page instead.
+ * This works even though do_getname can block (think about it).
+ * -- Michael Chastain, based on idea of Linus Torvalds, 1 Dec 1996.
+ */
+static unsigned long name_page_cache = 0;
+
 int getname(const char * filename, char **result)
 {
 	unsigned long page;
 	int retval;
 
-	page  = __get_free_page(GFP_KERNEL);
-	retval = -ENOMEM;
-	if (page) {
-		*result = (char *)page;
-		retval = do_getname(filename, (char *) page);
-		if (retval < 0)
-			free_page(page);
+	page = name_page_cache;
+	name_page_cache = 0;
+	if (!page) {
+		page = __get_free_page(GFP_KERNEL);
+		if (!page)
+			return -ENOMEM;
 	}
+
+	retval = do_getname(filename, (char *) page);
+	if (retval < 0)
+		putname( (char *) page );
+	else
+		*result = (char *) page;
 	return retval;
 }
 
 void putname(char * name)
 {
-	free_page((unsigned long) name);
+	if (name_page_cache == 0)
+		name_page_cache = (unsigned long) name;
+	else
+		free_page((unsigned long) name);
 }
 
 /*

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov