Messages in this thread Patch in this message | | | Date | Fri, 22 Aug 1997 10:18:42 -0400 | From | Bill Hawes <> | Subject | minor patch for get_empty_filp |
| |
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--- 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; } /* | |