lkml.org 
[lkml]   [2002]   [Jan]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] adjustable loadavg decay rates
I've made changes to the kernel to allow the decay constants for load
average computation to be modified via /proc/sys/kernel/load-exp.

What this allows you to do is make the three loadavgs more or less
responsive to changes in system load.

There is an accompanying utility, loadavgcalc, that will help calculate
the values to feed into /proc/sys/kernel/load-exp.

This patch is against 2.5.2-pre9.

It probably isn't of interest to most people, but some might like to have
a play.

The loadavgcalc program is at:
http://barbarella.hawaga.org.uk/~benc/loadavgcalc-0.1.tar.gz

The patch is attached to this message.

Ben


--
Ben Clifford benc@hawaga.org.uk
http://www.hawaga.org.uk/ben/ GPG: 30F06950 - signed/encrypted mail encouraged

=WARNING= Do not ever send e-mail to philip@hawaga.org.uk =WARNING=



Index: linux/Documentation/sysctl/kernel.txt
===================================================================
RCS file: /mnt/white/cvsroot/linux/Documentation/sysctl/kernel.txt,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.1
diff -u -r1.1.1.1 -r1.1.1.1.2.1
--- linux/Documentation/sysctl/kernel.txt 2002/01/07 08:03:50 1.1.1.1
+++ linux/Documentation/sysctl/kernel.txt 2002/01/10 09:12:51 1.1.1.1.2.1
@@ -240,3 +240,38 @@
the idle loop, possibly speeding up get_free_pages. Since
this only affects what the idle loop is doing, you should
enable this and see if anything changes.
+
+==============================================================
+
+load-exp:
+
+1min 5min 15min
+
+Changing these values allows adjustment of the speed at which
+the system loadavg changes.
+
+Traditionally, the first value has a decay constant of
+1 minute, the second has a decay constant of 5 minutes and
+the third has a decay constant of 15 minutes, and the
+default values in this sysctl reflect this.
+
+Use the loadavgcalc utility to compute new values to feed
+into here.
+
+==============================================================
+
+load-parm
+
+fshift freq hz
+
+Information required for the loadavgcalc utility to
+calculate values to feed into load-exp.
+
+fshift is the number of bits in the fractional part of
+numbers fed into load-exp.
+
+freq is the number of ticks between successive loadavg
+computations.
+
+hz is the number of ticks in one second.
+
Index: linux/include/linux/sysctl.h
===================================================================
RCS file: /mnt/white/cvsroot/linux/include/linux/sysctl.h,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.2
diff -u -r1.1.1.1 -r1.1.1.1.2.2
--- linux/include/linux/sysctl.h 2002/01/07 08:02:49 1.1.1.1
+++ linux/include/linux/sysctl.h 2002/01/10 09:19:45 1.1.1.1.2.2
@@ -124,6 +124,8 @@
KERN_CORE_USES_PID=52, /* int: use core or core.%pid */
KERN_TAINTED=53, /* int: various kernel tainted flags */
KERN_CADPID=54, /* int: PID of the process to notify on CAD */
+ KERN_LOAD_EXP=55, /* int: exponents for loadavg */
+ KERN_LOAD_PARM=56, /* int: other parameters for loadavg */
};


Index: linux/kernel/sysctl.c
===================================================================
RCS file: /mnt/white/cvsroot/linux/kernel/sysctl.c,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.2
diff -u -r1.1.1.1 -r1.1.1.1.2.2
--- linux/kernel/sysctl.c 2002/01/07 08:02:48 1.1.1.1
+++ linux/kernel/sysctl.c 2002/01/10 09:19:46 1.1.1.1.2.2
@@ -51,6 +51,8 @@
extern int sysrq_enabled;
extern int core_uses_pid;
extern int cad_pid;
+extern int load_exps[];
+extern int load_parms[];

/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
static int maxolduid = 65535;
@@ -257,6 +259,10 @@
{KERN_S390_USER_DEBUG_LOGGING,"userprocess_debug",
&sysctl_userprocess_debug,sizeof(int),0644,NULL,&proc_dointvec},
#endif
+ {KERN_LOAD_EXP, "load-exp", &load_exps, 3*sizeof(int),
+ 0644, NULL, &proc_dointvec},
+ {KERN_LOAD_PARM, "load-parameters", &load_parms, 3*sizeof(int),
+ 0444, NULL, &proc_dointvec},
{0}
};

Index: linux/kernel/timer.c
===================================================================
RCS file: /mnt/white/cvsroot/linux/kernel/timer.c,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.3
diff -u -r1.1.1.1 -r1.1.1.1.2.3
--- linux/kernel/timer.c 2002/01/07 08:02:48 1.1.1.1
+++ linux/kernel/timer.c 2002/01/10 09:19:46 1.1.1.1.2.3
@@ -13,6 +13,7 @@
* serialize accesses to xtime/lost_ticks).
* Copyright (C) 1998 Andrea Arcangeli
* 1999-03-10 Improved NTP compatibility by Ulrich Windl
+ * 2002-01-09 Userland adjustable loadavg. Copyright (C) 2001 Ben Clifford.
*/

#include <linux/config.h>
@@ -619,6 +620,28 @@
*/
unsigned long avenrun[3];

+/*
+ * Stores the decay constants for the exponential averages.
+ *
+ * todo: put in sysctl adjustment of the other values.
+ * todo: adjustable significant figures and frequency
+ * todo: fs/proc/proc_misc.c: avenrun[] references
+ * todo: LOAD_INT and LOAD_FRAC macros (in at least fs/proc/proc_misc)
+ * todo: find/grep of all the constant reveals various places that should
+ * be checked / changed.
+ * todo?:user can set loadavg value, for example, initial value after reboot
+ * if we are running a many-week decay and expect to reboot several
+ * times?
+ */
+unsigned int load_exps[3] = { EXP_1, EXP_5, EXP_15};
+
+/*
+ * Read only variables (at least for the moment).
+ * They are here in order to expose the kernel constants via /proc/sys
+ * for the userland exponent calculator.
+ */
+unsigned int load_parms[3] = {FSHIFT, LOAD_FREQ, HZ};
+
static inline void calc_load(unsigned long ticks)
{
unsigned long active_tasks; /* fixed-point */
@@ -628,9 +651,9 @@
if (count < 0) {
count += LOAD_FREQ;
active_tasks = count_active_tasks();
- CALC_LOAD(avenrun[0], EXP_1, active_tasks);
- CALC_LOAD(avenrun[1], EXP_5, active_tasks);
- CALC_LOAD(avenrun[2], EXP_15, active_tasks);
+ CALC_LOAD(avenrun[0], load_exps[0], active_tasks);
+ CALC_LOAD(avenrun[1], load_exps[1], active_tasks);
+ CALC_LOAD(avenrun[2], load_exps[2], active_tasks);
}
}
\
 
 \ /
  Last update: 2005-03-22 13:15    [W:0.895 / U:0.132 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site