Minor sysctl fixes and updates

Christopher Horn (chorn@warwick.net)
Mon, 23 Mar 1998 02:40:58 +0000


This is a multi-part message in MIME format.

--------------A60D1BD3D8E0523E27B103
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello! The attached patch against 2.1.90 fixes the swapout_interval
sysctl so that it is now meaningful, has a minor fix to compile without
/proc support, implements a few new sysctl values, and updates the
appropriate documentation. If anyone who tries it has any problems
please let me know, otherwise I hope to submit it for 2.1.91.

Cheers,
Chris

--------------A60D1BD3D8E0523E27B103
Content-Type: text/plain; charset=us-ascii; name="sysctl-patch-2.1.90"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="sysctl-patch-2.1.90"

diff -uNr /usr/src/linux-2.1.90-virgin/Documentation/sysctl/fs.txt /usr/src/linux/Documentation/sysctl/fs.txt
--- /usr/src/linux-2.1.90-virgin/Documentation/sysctl/fs.txt Wed Dec 31 19:00:00 1969
+++ /usr/src/linux/Documentation/sysctl/fs.txt Sun Mar 22 20:17:00 1998
@@ -0,0 +1,60 @@
+Documentation for /proc/sys/fs sysctl entries
+3/8/98 Chris Horn
+
+This file contains documentation on the directories and files found in the
+/proc/sys/fs directory. The files in these directories can be used to control
+or modify the behaviour of selected filesystems or binary formats.
+
+Note that subdirectories and files may or may not be present, depending upon
+whether or not the controlled feature is compiled into the kernel or built as
+a loadable module. If built as a module, most subdirectories are registered
+dynamically when the module is loaded.
+
+Currently the following subdirectories related to binary formats may exist.
+
+binfmt_aout For aout binaries
+binfmt_elf For ELF binaries
+binfmt_misc For miscellaneous binaries
+
+==============================================================================
+
+/proc/sys/fs/binfmt_aout
+
+core-enable:
+
+This option defaults to 1, which enables aout core dumps. A value of 0 will
+globally disable aout core dumps.
+
+core-name:
+
+This option controls the name given to the file the core dump is stored in.
+The following are valid options :
+
+0 File name is core, this is the traditional default.
+1 File name is core.<name> where name is that of the process that dumped.
+2 File name is core.<pid> where pid is that of the process that dumped.
+
+============================================================
+
+/proc/sys/fs/binfmt_elf
+
+core-enable:
+
+This option defaults to 1, which enables ELF core dumps. A value of 0 will
+globally disable ELF core dumps.
+
+core-name:
+
+This option controls the name given to the file the core dump is stored in.
+The following are valid options :
+
+0 File name is core, this is the traditional default.
+1 File name is core.<name> where name is that of the process that dumped.
+2 File name is core.<pid> where pid is that of the process that dumped.
+
+============================================================
+
+/proc/sys/fs/binfmt_misc
+
+The binfmt_misc mechanism is documented separately in the binfmt_misc.txt
+file in the primary Documentation directory.
diff -uNr /usr/src/linux-2.1.90-virgin/Documentation/sysctl/kernel.txt /usr/src/linux/Documentation/sysctl/kernel.txt
--- /usr/src/linux-2.1.90-virgin/Documentation/sysctl/kernel.txt Sat Mar 7 11:06:09 1998
+++ /usr/src/linux/Documentation/sysctl/kernel.txt Sun Mar 22 20:17:00 1998
@@ -25,10 +25,13 @@
- inode-max
- inode-nr
- inode-state
+- machine
- osrelease
- ostype
- panic
- printk
+- reservedfiles
+- reservedtasks
- securelevel
- version

@@ -132,8 +135,10 @@

==============================================================

-osrelease, ostype & version:
+machine, osrelease, ostype & version:

+# cat machine
+i586
# cat osrelease
2.1.88
# cat ostype
@@ -141,9 +146,9 @@
# cat version
#5 Wed Feb 25 21:49:24 MET 1998

-The files osrelease and ostype should be clear enough. Version
-needs a little more clarification however. The '#5' means that
-this is the fifth kernel built from this source base and the
+The files machine, osrelease, and ostype should be clear enough.
+Version needs a little more clarification however. The '#5' means
+that this is the fifth kernel built from this source base and the
date behind it indicates the time the kernel was built.
The only way to tune these values is to rebuild the kernel :-)

@@ -206,3 +211,11 @@
ROM/Flash boot loader. Maybe to tell it what to do after
rebooting. ???

+==============================================================
+
+reservedfiles & reservedtasks:
+
+These are fairly self explanatory. These are the number of file
+handles or tasks reserved for root. If a machine is under heavy
+load and either limit is approached, they should make it possible
+for the root user to still login.
diff -uNr /usr/src/linux-2.1.90-virgin/Documentation/sysctl/vm.txt /usr/src/linux/Documentation/sysctl/vm.txt
--- /usr/src/linux-2.1.90-virgin/Documentation/sysctl/vm.txt Fri Mar 20 21:02:37 1998
+++ /usr/src/linux/Documentation/sysctl/vm.txt Sun Mar 22 20:37:17 1998
@@ -236,10 +236,10 @@

swapout_interval:

-The single value in this file controls the amount of time
-between successive wakeups of kswapd when nr_free_pages is
-between free_pages_low and free_pages_high. The default value
-of HZ/4 is usually right, but when kswapd can't keep up with
-the number of allocations in your system, you might want to
-decrease this number.
+The single value in this file controls the number of times
+kswapd wakes up per second when nr_free_pages is between
+free_pages_low and free_pages_high. The default value of 4
+is usually right, but when kswapd can't keep up with the number
+of allocations in your system, you might want to decrease this
+number.

diff -uNr /usr/src/linux-2.1.90-virgin/fs/binfmt_aout.c /usr/src/linux/fs/binfmt_aout.c
--- /usr/src/linux-2.1.90-virgin/fs/binfmt_aout.c Mon Dec 1 13:34:11 1997
+++ /usr/src/linux/fs/binfmt_aout.c Sun Mar 22 20:17:00 1998
@@ -28,6 +28,10 @@
#include <asm/uaccess.h>
#include <asm/pgtable.h>

+#ifdef CONFIG_SYSCTL
+#include <linux/sysctl.h>
+#endif
+
static int load_aout_binary(struct linux_binprm *, struct pt_regs * regs);
static int load_aout_library(int fd);
static int aout_core_dump(long signr, struct pt_regs * regs);
@@ -42,6 +46,35 @@
#endif
};

+struct {
+ int enable;
+ int name;
+} sysctl_aout_core = {1, 0};
+
+#ifdef CONFIG_SYSCTL
+
+static struct ctl_table_header *aout_table_header;
+
+static ctl_table aout_table[] = {
+ {FS_AOUT_CORE_ENABLE, "core-enable", &sysctl_aout_core.enable, sizeof(int),
+ 0644, NULL, &proc_dointvec},
+ {FS_AOUT_CORE_NAME, "core-name", &sysctl_aout_core.name, sizeof(int),
+ 0644, NULL, &proc_dointvec},
+ {0}
+};
+
+static ctl_table aout_dir_table[] = {
+ {FS_AOUT, "binfmt_aout", NULL, 0, 0555, aout_table},
+ {0}
+};
+
+static ctl_table aout_root_table[] = {
+ {CTL_FS, "fs", NULL, 0, 0555, aout_dir_table},
+ {0}
+};
+
+#endif /* CONFIG_SYSCTL */
+
static void set_brk(unsigned long start, unsigned long end)
{
start = PAGE_ALIGN(start);
@@ -84,7 +117,7 @@
struct file file;
mm_segment_t fs;
int has_dumped = 0;
- char corefile[6+sizeof(current->comm)];
+ char corefile[12+sizeof(current->comm)];
unsigned long dump_start, dump_size;
struct user dump;
#if defined(__alpha__)
@@ -100,7 +133,7 @@
# define START_STACK(u) (u.start_stack)
#endif

- if (!current->dumpable || current->mm->count != 1)
+ if (!current->dumpable || current->mm->count != 1 || !sysctl_aout_core.enable)
return 0;
current->dumpable = 0;

@@ -110,11 +143,19 @@
fs = get_fs();
set_fs(KERNEL_DS);
memcpy(corefile,"core.",5);
-#if 0
- memcpy(corefile+5,current->comm,sizeof(current->comm));
-#else
- corefile[4] = '\0';
-#endif
+ switch (sysctl_aout_core.name) {
+ case 0 :
+ corefile[4] = '\0';
+ break;
+ case 1 :
+ memcpy(corefile+5,current->comm,sizeof(current->comm));
+ break;
+ case 2 :
+ sprintf(corefile,"core.%d",current->pid);
+ break;
+ default :
+ corefile[4] = '\0';
+ }
dentry = open_namei(corefile,O_CREAT | 2 | O_TRUNC, 0600);
if (IS_ERR(dentry)) {
dentry = NULL;
@@ -560,6 +601,9 @@

__initfunc(int init_aout_binfmt(void))
{
+#ifdef CONFIG_SYSCTL
+ aout_table_header = register_sysctl_table(aout_root_table, 1);
+#endif
return register_binfmt(&aout_format);
}

@@ -569,6 +613,9 @@
}

void cleanup_module( void) {
+#ifdef CONFIG_SYSCTL
+ unregister_sysctl_table(aout_table_header);
+#endif
unregister_binfmt(&aout_format);
}
#endif
diff -uNr /usr/src/linux-2.1.90-virgin/fs/binfmt_elf.c /usr/src/linux/fs/binfmt_elf.c
--- /usr/src/linux-2.1.90-virgin/fs/binfmt_elf.c Sat Mar 7 11:06:20 1998
+++ /usr/src/linux/fs/binfmt_elf.c Sun Mar 22 20:17:00 1998
@@ -39,6 +39,10 @@

#include <linux/elf.h>

+#ifdef CONFIG_SYSCTL
+#include <linux/sysctl.h>
+#endif
+
static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs);
static int load_elf_library(int fd);
extern int dump_fpu (struct pt_regs *, elf_fpregset_t *);
@@ -75,6 +79,35 @@
#endif
};

+struct {
+ int enable;
+ int name;
+} sysctl_elf_core = {1, 0};
+
+#ifdef CONFIG_SYSCTL
+
+static struct ctl_table_header *elf_table_header;
+
+static ctl_table elf_table[] = {
+ {FS_ELF_CORE_ENABLE, "core-enable", &sysctl_elf_core.enable, sizeof(int),
+ 0644, NULL, &proc_dointvec},
+ {FS_ELF_CORE_NAME, "core-name", &sysctl_elf_core.name, sizeof(int),
+ 0644, NULL, &proc_dointvec},
+ {0}
+};
+
+static ctl_table elf_dir_table[] = {
+ {FS_ELF, "binfmt_elf", NULL, 0, 0555, elf_table},
+ {0}
+};
+
+static ctl_table elf_root_table[] = {
+ {CTL_FS, "fs", NULL, 0, 0555, elf_dir_table},
+ {0}
+};
+
+#endif
+
static void set_brk(unsigned long start, unsigned long end)
{
start = ELF_PAGEALIGN(start);
@@ -1045,7 +1078,7 @@
struct dentry *dentry;
struct inode *inode;
mm_segment_t fs;
- char corefile[6+sizeof(current->comm)];
+ char corefile[12+sizeof(current->comm)];
int segs;
int i;
size_t size;
@@ -1059,7 +1092,7 @@
elf_fpregset_t fpu; /* NT_PRFPREG */
struct elf_prpsinfo psinfo; /* NT_PRPSINFO */

- if (!current->dumpable || limit < ELF_EXEC_PAGESIZE || current->mm->count != 1)
+ if (!current->dumpable || limit < ELF_EXEC_PAGESIZE || current->mm->count != 1 || !sysctl_elf_core.enable)
return 0;
current->dumpable = 0;

@@ -1111,11 +1144,19 @@
fs = get_fs();
set_fs(KERNEL_DS);
memcpy(corefile,"core.",5);
-#if 0
- memcpy(corefile+5,current->comm,sizeof(current->comm));
-#else
- corefile[4] = '\0';
-#endif
+ switch (sysctl_elf_core.name) {
+ case 0 :
+ corefile[4] = '\0';
+ break;
+ case 1 :
+ memcpy(corefile+5,current->comm,sizeof(current->comm));
+ break;
+ case 2 :
+ sprintf(corefile, "core.%d",current->pid);
+ break;
+ default :
+ corefile[4] = '\0';
+ }
dentry = open_namei(corefile, O_CREAT | 2 | O_TRUNC, 0600);
if (IS_ERR(dentry)) {
dentry = NULL;
@@ -1328,6 +1369,9 @@

__initfunc(int init_elf_binfmt(void))
{
+#ifdef CONFIG_SYSCTL
+ elf_table_header = register_sysctl_table(elf_root_table, 1);
+#endif
return register_binfmt(&elf_format);
}

@@ -1345,7 +1389,12 @@

void cleanup_module( void)
{
+#ifdef CONFIG_SYSCTL
+ unregister_sysctl_table(elf_table_header);
+#endif
/* Remove the COFF and ELF loaders. */
unregister_binfmt(&elf_format);
}
#endif
+
+
diff -uNr /usr/src/linux-2.1.90-virgin/fs/file_table.c /usr/src/linux/fs/file_table.c
--- /usr/src/linux-2.1.90-virgin/fs/file_table.c Sun Oct 12 13:10:40 1997
+++ /usr/src/linux/fs/file_table.c Sun Mar 22 20:17:00 1998
@@ -21,6 +21,7 @@
int nr_files = 0; /* read only */
int nr_free_files = 0; /* read only */
int max_files = NR_FILE;/* tunable */
+int reservedfiles = NR_RESERVED_FILES;

/* Free list management, if you are here you must have f_count == 0 */
static struct file * free_filps = NULL;
@@ -69,7 +70,7 @@
static int old_max = 0;
struct file * f;

- if (nr_free_files > NR_RESERVED_FILES) {
+ if (nr_free_files > reservedfiles) {
used_one:
f = free_filps;
remove_filp(f);
diff -uNr /usr/src/linux-2.1.90-virgin/include/linux/sysctl.h /usr/src/linux/include/linux/sysctl.h
--- /usr/src/linux-2.1.90-virgin/include/linux/sysctl.h Fri Mar 20 21:02:55 1998
+++ /usr/src/linux/include/linux/sysctl.h Sun Mar 22 20:18:17 1998
@@ -72,7 +72,10 @@
KERN_STATINODE,
KERN_DENTRY, /* dentry statistics */
KERN_MODPROBE,
- KERN_KMOD_UNLOAD_DELAY
+ KERN_KMOD_UNLOAD_DELAY,
+ KERN_MACHINE,
+ KERN_RESERVEDTASKS,
+ KERN_RESERVEDFILES
};


@@ -357,6 +360,22 @@
/* CTL_PROC names: */

/* CTL_FS names: */
+enum {
+ FS_ELF = 1,
+ FS_AOUT
+};
+
+/* /proc/sys/fs/binfmt_elf */
+enum {
+ FS_ELF_CORE_ENABLE = 1,
+ FS_ELF_CORE_NAME
+};
+
+/* /proc/sys/fs/binfmt_aout */
+enum {
+ FS_AOUT_CORE_ENABLE = 1,
+ FS_AOUT_CORE_NAME
+};

/* CTL_DEBUG names: */

diff -uNr /usr/src/linux-2.1.90-virgin/kernel/fork.c /usr/src/linux/kernel/fork.c
--- /usr/src/linux-2.1.90-virgin/kernel/fork.c Fri Mar 20 21:02:55 1998
+++ /usr/src/linux/kernel/fork.c Sun Mar 22 20:17:00 1998
@@ -33,6 +33,7 @@
int nr_running=1;
unsigned long int total_forks=0; /* Handle normal Linux uptimes. */
int last_pid=0;
+int reservedtasks = MIN_TASKS_LEFT_FOR_ROOT;

/* SLAB cache for mm_struct's. */
kmem_cache_t *mm_cachep;
@@ -143,7 +144,7 @@
if(current->uid) {
int error;

- if(nr_tasks >= NR_TASKS - MIN_TASKS_LEFT_FOR_ROOT)
+ if(nr_tasks >= NR_TASKS - reservedtasks)
return -EAGAIN;
if((error = charge_uid(current, 1)) < 0)
return error;
diff -uNr /usr/src/linux-2.1.90-virgin/kernel/sysctl.c /usr/src/linux/kernel/sysctl.c
--- /usr/src/linux-2.1.90-virgin/kernel/sysctl.c Fri Mar 20 21:02:56 1998
+++ /usr/src/linux/kernel/sysctl.c Sun Mar 22 20:24:26 1998
@@ -41,6 +41,9 @@
extern int bdf_prm[], bdflush_min[], bdflush_max[];
extern char binfmt_java_interpreter[], binfmt_java_appletviewer[];
extern int sysctl_overcommit_memory;
+extern int reservedtasks, reservedfiles;
+extern int inodes_stat[];
+extern int dentry_stat[];
#ifdef CONFIG_KMOD
extern char modprobe_path[];
extern int kmod_unload_delay;
@@ -114,8 +117,6 @@

extern struct proc_dir_entry proc_sys_root;

-extern int inodes_stat[];
-extern int dentry_stat[];
static void register_proc_table(ctl_table *, struct proc_dir_entry *);
static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
#endif
@@ -184,6 +185,12 @@
{KERN_KMOD_UNLOAD_DELAY, "kmod_unload_delay", &kmod_unload_delay,
sizeof(int), 0644, NULL, &proc_dointvec},
#endif
+ {KERN_MACHINE, "machine", system_utsname.machine, 64,
+ 0444, NULL, &proc_dostring, &sysctl_string},
+ {KERN_RESERVEDTASKS, "reserved-tasks", &reservedtasks, sizeof(int),
+ 0600, NULL, &proc_dointvec},
+ {KERN_RESERVEDFILES, "reserved-files", &reservedfiles, sizeof(int),
+ 0600, NULL, &proc_dointvec},
{0}
};

@@ -191,14 +198,14 @@
{VM_SWAPCTL, "swapctl",
&swap_control, sizeof(swap_control_t), 0600, NULL, &proc_dointvec},
{VM_SWAPOUT, "swapout_interval",
- &swapout_interval, sizeof(int), 0600, NULL, &proc_dointvec_jiffies},
+ &swapout_interval, sizeof(int), 0600, NULL, &proc_dointvec},
{VM_FREEPG, "freepages",
&freepages, sizeof(freepages_t), 0600, NULL, &proc_dointvec},
{VM_BDFLUSH, "bdflush", &bdf_prm, 9*sizeof(int), 0600, NULL,
&proc_dointvec_minmax, &sysctl_intvec, NULL,
&bdflush_min, &bdflush_max},
{VM_OVERCOMMIT_MEMORY, "overcommit_memory", &sysctl_overcommit_memory,
- sizeof(sysctl_overcommit_memory), 0644, NULL, &proc_dointvec},
+ sizeof(sysctl_overcommit_memory), 0600, NULL, &proc_dointvec},
{VM_BUFFERMEM, "buffermem",
&buffer_mem, sizeof(buffer_mem_t), 0600, NULL, &proc_dointvec},
{0}
@@ -838,12 +845,6 @@
}

#else /* CONFIG_PROC_FS */
-
-int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
- void *buffer, size_t *lenp)
-{
- return -ENOSYS;
-}

int proc_dostring(ctl_table *table, int write, struct file *filp,
void *buffer, size_t *lenp)
diff -uNr /usr/src/linux-2.1.90-virgin/mm/vmscan.c /usr/src/linux/mm/vmscan.c
--- /usr/src/linux-2.1.90-virgin/mm/vmscan.c Fri Mar 20 21:02:56 1998
+++ /usr/src/linux/mm/vmscan.c Sun Mar 22 20:29:02 1998
@@ -37,7 +37,7 @@
* How often do we do a pageout scan during normal conditions?
* Default is four times a second.
*/
-int swapout_interval = HZ / 4;
+int swapout_interval = 4;

/*
* The wait queue for waking up the pageout daemon:
@@ -609,7 +609,7 @@
/* Set the next wake-up time */
next_swap_jiffies = jiffies;
if (!memory_low)
- next_swap_jiffies += swapout_interval;
+ next_swap_jiffies += HZ / swapout_interval;
}
timer_active |= (1<<SWAP_TIMER);
}

--------------A60D1BD3D8E0523E27B103--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu