minor patch for get_empty_filp

Bill Hawes (whawes@star.net)
Fri, 22 Aug 1997 10:18:42 -0400


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

I've attached a patch for get_empty_filp that simplifies the allocation
of new file structures. The old grow_filp() code isn't necessary now
that the SLAB allocator is being used for file structures.

The patch will also print a message if the file-max limit is reached,
rather than just silently fail the allocation. It saves the old max
value so that only one message is printed; if the limit is increased and
then exceeded again, another message is printed.

I ran some tests with file-max set to 90 to induce failures, but haven't
found any kernel problems yet.

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

--- fs/file_table.c.old Thu Jul 24 13:34:38 1997
+++ fs/file_table.c Fri Aug 22 09:35:36 1997
@@ -43,26 +43,6 @@
file->f_pprev = &inuse_filps;
}

-/* Get more free filp's. */
-static int grow_files(void)
-{
- int i = 16;
-
- while(i--) {
- struct file * file = kmem_cache_alloc(filp_cache, SLAB_KERNEL);
- if(!file) {
- if(i == 15)
- return 0;
- goto got_some;
- }
-
- insert_file_free(file);
- nr_files++;
- }
-got_some:
- return 1;
-}
-
void file_table_init(void)
{
filp_cache = kmem_cache_create("filp", sizeof(struct file),
@@ -78,28 +58,36 @@
*/
struct file * get_empty_filp(void)
{
+ static int old_max = 0;
struct file * f;

-again:
- if((f = free_filps) != NULL) {
- remove_filp(f);
- memset(f, 0, sizeof(*f));
- f->f_count = 1;
- f->f_version = ++event;
- put_inuse(f);
- } else {
- int max = max_files;
-
- /* Reserve a few files for the super-user.. */
- if (current->euid)
- max -= 10;
-
- if (nr_files < max && grow_files())
- goto again;
+ f = free_filps;
+ if (!f)
+ goto get_more;
+ remove_filp(f);
+got_one:
+ memset(f, 0, sizeof(*f));
+ f->f_count = 1;
+ f->f_version = ++event;
+ put_inuse(f);
+ return f;

+get_more:
+ /* Reserve a few files for the super-user.. */
+ if (nr_files < (current->euid ? max_files - 10 : max_files)) {
+ f = kmem_cache_alloc(filp_cache, SLAB_KERNEL);
+ if (f) {
+ nr_files++;
+ goto got_one;
+ }
/* Big problems... */
+ printk("VFS: filp allocation failed\n");
+
+ } else if (max_files > old_max) {
+ printk("VFS: file-max limit %d reached\n", max_files);
+ old_max = max_files;
}
- return f;
+ return NULL;
}

/*

--------------DF61404D148BA02325FA90F4--