patch to enforce inode limit

Bill Hawes (whawes@star.net)
Fri, 24 Jul 1998 09:31:00 -0400


This is a multi-part message in MIME format.
--------------837AD0A4DB2021DFEBED775A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I've found that under certain conditions the inode-max limit wasn't
being enforced properly in grow_inodes(), and the number of inodes can
grow substantially beyond the limit. The limit was being enforced by
preshrinking dcache before trying to allocate more inodes, but
apparently there are cases where this doesn't work. (Possibly the inodes
were dirty and couldn't be reused immediately.)

The attached patch moves the test for nr_inodes >= max_inodes to enforce
it as a hard limit, and uses a ">=" instead of ">" to avoid inching
above the limit.

I've also added a KERN_WARNING to the failure limit message, and a limit
counter to avoid getting more than one warning (per limit) if the limit
is reached. (No failure messages have been observed so far.)

Testing under the same conditions shows the limit is strictly enforced.

Regards,
Bill
--------------837AD0A4DB2021DFEBED775A
Content-Type: text/plain; charset=us-ascii; name="inode_grow110-patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="inode_grow110-patch"

--- linux-2.1.110/fs/inode.c.old Fri Jul 3 10:32:32 1998
+++ linux-2.1.110/fs/inode.c Thu Jul 23 22:49:21 1998
@@ -409,9 +437,13 @@
*/
static struct inode * grow_inodes(void)
{
+ static int warn_limit = 0;
struct inode * inode;

spin_unlock(&inode_lock);
+ if (inodes_stat.nr_inodes >= max_inodes)
+ goto shrink;
+
inode = (struct inode *)__get_free_page(GFP_KERNEL);
if (inode) {
int size;
@@ -433,15 +465,15 @@
inodes_stat.nr_inodes += INODES_PER_PAGE;
inodes_stat.nr_free_inodes += INODES_PER_PAGE - 1;
inodes_stat.preshrink = 0;
- if (inodes_stat.nr_inodes > max_inodes)
- inodes_stat.preshrink = 1;
return inode;
}

/*
- * If the allocation failed, do an extensive pruning of
- * the dcache and then try again to free some inodes.
+ * If the allocation failed or the limit has been reached,
+ * do an extensive pruning of the dcache and then try again
+ * to free some inodes.
*/
+shrink:
prune_dcache(inodes_stat.nr_inodes >> 2);
inodes_stat.preshrink = 1;

@@ -458,7 +490,10 @@
}
spin_unlock(&inode_lock);

- printk("grow_inodes: allocation failed\n");
+ if (warn_limit < max_inodes) {
+ warn_limit = max_inodes;
+ printk(KERN_WARNING "VFS: inode allocation failed\n");
+ }
return NULL;
}

--------------837AD0A4DB2021DFEBED775A--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html