patch-2.1.52 linux/fs/dcache.c

Next file: linux/fs/exec.c
Previous file: linux/fs/buffer.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.51/linux/fs/dcache.c linux/fs/dcache.c
@@ -19,6 +19,9 @@
 #include <linux/malloc.h>
 #include <linux/init.h>
 
+/* For managing the dcache */
+extern int nr_free_pages, free_pages_low;
+
 /*
  * This is the single most critical data structure when it comes
  * to the dcache: the hashtable for lookups. Somebody should try
@@ -72,13 +75,13 @@
 		dentry->d_count = count;
 		if (!count) {
 			list_del(&dentry->d_lru);
+			if (dentry->d_op && dentry->d_op->d_delete)
+				dentry->d_op->d_delete(dentry);
 			if (list_empty(&dentry->d_hash)) {
 				struct inode *inode = dentry->d_inode;
 				struct dentry * parent;
-				if (inode) {
-					list_del(&dentry->d_alias);
+				if (inode)
 					iput(inode);
-				}
 				parent = dentry->d_parent;
 				d_free(dentry);
 				if (dentry == parent)
@@ -134,7 +137,6 @@
 			if (dentry->d_inode) {
 				struct inode * inode = dentry->d_inode;
 
-				list_del(&dentry->d_alias);
 				dentry->d_inode = NULL;
 				iput(inode);
 			}
@@ -152,6 +154,13 @@
 	char * str;
 	struct dentry *dentry;
 
+	/*
+	 * Check whether to shrink the dcache ... this greatly reduces
+	 * the likelyhood that kmalloc() will need additional memory.
+	 */
+	if (nr_free_pages < free_pages_low)
+		shrink_dcache();
+
 	dentry = kmalloc(sizeof(struct dentry), GFP_KERNEL);
 	if (!dentry)
 		return NULL;
@@ -172,7 +181,6 @@
 	dentry->d_mounts = dentry;
 	dentry->d_covers = dentry;
 	INIT_LIST_HEAD(&dentry->d_hash);
-	INIT_LIST_HEAD(&dentry->d_alias);
 	INIT_LIST_HEAD(&dentry->d_lru);
 
 	dentry->d_name.name = str;
@@ -194,9 +202,6 @@
  */
 void d_instantiate(struct dentry *entry, struct inode * inode)
 {
-	if (inode)
-		list_add(&entry->d_alias, &inode->i_dentry);
-
 	entry->d_inode = inode;
 }
 
@@ -312,10 +317,10 @@
 	 */
 	if (dentry->d_count == 1) {
 		struct inode * inode = dentry->d_inode;
-
-		dentry->d_inode = NULL;
-		list_del(&dentry->d_alias);
-		iput(inode);
+		if (inode) {
+			dentry->d_inode = NULL;
+			iput(inode);
+		}
 		return;
 	}
 

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