linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Szabolcs Szakacsits <szaka@f-secure.com>
To: <linux-kernel@vger.kernel.org>
Subject: [PATCH] Broken NR_RESERVED_FILES
Date: Thu, 7 Dec 2000 14:27:20 +0200 (MET DST)	[thread overview]
Message-ID: <Pine.LNX.4.30.0012071354070.5455-100000@fs129-190.f-secure.com> (raw)


Reserved fd's for superuser doesn't work. Patch for 2.2 is below,
kernel 2.4.x also has this problem, fix is similar. The default
NR_RESERVED_FILES value also had to be increased (e.g. ssh, login
needs 36, ls 16, man 45 fd's, etc).

BTW, I have an updated version of my reserved VM for superuser +
improved/fixed version of Rik's out of memory killer patch for 2.2
here,

http://mlf.linux.rulez.org/mlf/ezaz/reserved_root_vm+oom_killer-5.diff

It fixes the potential deadlock when kernel threads were blocked to
try to free pages - more details about the patch are in a former
email, http://boudicca.tux.org/hypermail/linux-kernel/2000week48/0624.html

	Szaka

diff -ur linux-2.2.18pre21/fs/file_table.c linux/fs/file_table.c
--- linux-2.2.18pre21/fs/file_table.c	Tue Jan  4 13:12:23 2000
+++ linux/fs/file_table.c	Thu Dec  7 13:26:06 2000
@@ -71,30 +71,27 @@
 {
 	static int old_max = 0;
 	struct file * f;
+	int total_free;

-	if (nr_free_files > NR_RESERVED_FILES) {
-	used_one:
-		f = free_filps;
-		remove_filp(f);
-		nr_free_files--;
-	new_one:
-		memset(f, 0, sizeof(*f));
-		f->f_count = 1;
-		f->f_version = ++global_event;
-		f->f_uid = current->fsuid;
-		f->f_gid = current->fsgid;
-		put_inuse(f);
-		return f;
-	}
-	/*
-	 * Use a reserved one if we're the superuser
-	 */
-	if (nr_free_files && !current->euid)
-		goto used_one;
-	/*
-	 * Allocate a new one if we're below the limit.
-	 */
-	if (nr_files < max_files) {
+	total_free = max_files - nr_files + nr_free_files;
+	if (total_free > NR_RESERVED_FILES || (total_free && !current->euid)) {
+		if (nr_free_files) {
+		used_one:
+			f = free_filps;
+			remove_filp(f);
+			nr_free_files--;
+		new_one:
+			memset(f, 0, sizeof(*f));
+			f->f_count = 1;
+			f->f_version = ++global_event;
+			f->f_uid = current->fsuid;
+			f->f_gid = current->fsgid;
+			put_inuse(f);
+			return f;
+		}
+		/*
+		 * Allocate a new one if we're below the limit.
+	 	*/
 		f = kmem_cache_alloc(filp_cache, SLAB_KERNEL);
 		if (f) {
 			nr_files++;
diff -ur linux-2.2.18pre21/include/linux/fs.h linux/include/linux/fs.h
--- linux-2.2.18pre21/include/linux/fs.h	Thu Nov  9 08:20:18 2000
+++ linux/include/linux/fs.h	Thu Dec  7 11:10:50 2000
@@ -51,7 +51,7 @@
 extern int max_super_blocks, nr_super_blocks;

 #define NR_FILE  4096	/* this can well be larger on a larger system */
-#define NR_RESERVED_FILES 10 /* reserved for root */
+#define NR_RESERVED_FILES 96 /* reserved for root */
 #define NR_SUPER 256

 #define MAY_EXEC 1

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

             reply	other threads:[~2000-12-07 12:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-07 12:27 Szabolcs Szakacsits [this message]
2000-12-07 12:53 ` [PATCH] Broken NR_RESERVED_FILES Tigran Aivazian
2000-12-07 13:44   ` Szabolcs Szakacsits
2000-12-07 14:03     ` Tigran Aivazian
2000-12-07 15:09       ` Szabolcs Szakacsits
2000-12-07 15:43         ` Tigran Aivazian
2000-12-07 16:15           ` Szabolcs Szakacsits
2000-12-07 16:11             ` Tigran Aivazian
2000-12-07 16:45               ` Szabolcs Szakacsits
2000-12-07 13:06 ` Tigran Aivazian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.30.0012071354070.5455-100000@fs129-190.f-secure.com \
    --to=szaka@f-secure.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).