Skip to contentSkip to conversation

Automatice kernel tunables (AKT)

RFC PATCH In review [email protected] 4 participants 24 messages Jan 16, 2007 – Feb 15, 2007

Subsystems (5)
Documentation VFS MM core Scheduler +1 more subsystems
lore
Share & tools
lore
#0 lore raw

cover Automatice kernel tunables (AKT)

This is a series of patches that introduces a feature that makes the kernel automatically change the tunables values as it sees resources running out.

The AKT framework is made of 2 parts:

1) Kernel part:
Interfaces are provided to the kernel subsystems, to (un)register the tunables that might be automatically tuned in the future.

Registering a tunable consists in the following steps:
- a structure is declared and filled by the kernel subsystem for the registered tunable
- that tunable structure is registered into sysfs

Registration should be done during the kernel subsystem initialization step.

Another interface is provided to the kernel subsystems, to activate the automatic tuning for a registered tunable. It can be called during resource allocation to tune up, and during resource freeing to tune down the registered tunable. The automatic tuning routine is called only if the tunable has been enabled to be automatically tuning in sysfs.

2) User part:

AKT uses sysfs to enable the tunables management from the user world (mainly making them automatic or manual).

akt uses sysfs in the following way:
- a tunables subsystem (tunables_subsys) is declared and registered during akt initialization.
- registering a tunable is equivalent to registering the corresponding kobject within that subsystem.
- each tunable kobject has 3 associated attributes, all with a RW mode (i.e. the show() and store() methods are provided for them):
. autotune: enables to (de)activate automatic tuning for the tunable . max: enables to set a new maximum value for the tunable . min: enables to set a new minimum value for the tunable

The only way to activate automatic tuning is from user side:
- the directory /sys/tunables is created during the init phase.
- each time a tunable is registered by a kernel subsystem, a directory is created for it under /sys/tunables.
- This directory contains 1 file for each tunable kobject attribute

These patches should be applied to 2.6.20-rc4, in the following order:

[PATCH 1/6]: tunables_registration.patch
[PATCH 2/6]: auto_tuning_activation.patch
[PATCH 3/6]: auto_tuning_kobjects.patch
[PATCH 4/6]: tunable_min_max_kobjects.patch
[PATCH 5/6]: per_namespace_tunables.patch
[PATCH 6/6]: auto_tune_applied.patch

--

#1 lore raw

RFC PATCH 1/6 Tunable structure and registration routines

[PATCH 01/06]

Defines the auto_tune structure: this is the structure that contains the information needed by the adjustment routine for a given tunable. Also defines the registration routines.

The fork kernel component defines a tunable structure for the threads-max tunable and registers it.

---
 Documentation/00-INDEX      |    2 
 Documentation/auto_tune.txt |  333 ++++++++++++++++++++++++++++++++++++++++++++
 fs/Kconfig                  |    2 
 include/linux/akt.h         |  186 ++++++++++++++++++++++++
 include/linux/akt_ops.h     |  186 ++++++++++++++++++++++++
 init/main.c                 |    2 
 kernel/Makefile             |    1 
 kernel/autotune/Kconfig     |   30 +++
 kernel/autotune/Makefile    |    7 
 kernel/autotune/akt.c       |  123 ++++++++++++++++
 kernel/fork.c               |   18 ++
 11 files changed, 890 insertions(+)
Documentation/00-INDEX +2 -0
Index: linux-2.6.20-rc4/Documentation/00-INDEX
===================================================================
@@ -52,6 +52,8 @@ applying-patches.txt
 	- description of various trees and how to apply their patches.
 arm/
 	- directory with info about Linux on the ARM architecture.
+auto_tune.txt
+	- info on the Automatic Kernel Tunables (AKT) feature.
 basic_profiling.txt
 	- basic instructions for those who wants to profile Linux kernel.
 binfmt_misc.txt
Documentation/auto_tune.txt new file +333 -0

333 lines not on this page · raw message

fs/Kconfig +2 -0
Index: linux-2.6.20-rc4/fs/Kconfig
===================================================================
@@ -925,6 +925,8 @@ config PROC_KCORE
 	bool "/proc/kcore support" if !ARM
 	depends on PROC_FS && MMU
 
+source "kernel/autotune/Kconfig"
+
 config PROC_VMCORE
         bool "/proc/vmcore support (EXPERIMENTAL)"
         depends on PROC_FS && EXPERIMENTAL && CRASH_DUMP
include/linux/akt.h new file +186 -0

186 lines not on this page · raw message

include/linux/akt_ops.h new file +186 -0

186 lines not on this page · raw message

init/main.c +2 -0
Index: linux-2.6.20-rc4/init/main.c
===================================================================
@@ -54,6 +54,7 @@
 #include <linux/pid_namespace.h>
 #include <linux/compile.h>
 #include <linux/device.h>
+#include <linux/akt.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -613,6 +614,7 @@ asmlinkage void __init start_kernel(void
 	signals_init();
 	/* rootfs populating might need page-writeback */
 	page_writeback_init();
+	fork_late_init();
 #ifdef CONFIG_PROC_FS
 	proc_root_init();
 #endif
kernel/Makefile +1 -0
Index: linux-2.6.20-rc4/kernel/Makefile
===================================================================
@@ -50,6 +50,7 @@ obj-$(CONFIG_RELAY) += relay.o
 obj-$(CONFIG_UTS_NS) += utsname.o
 obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
 obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
+obj-$(CONFIG_AKT) += autotune/
 
 ifneq ($(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/autotune/Kconfig new file +30 -0
Index: linux-2.6.20-rc4/kernel/autotune/Kconfig
===================================================================
@@ -0,0 +1,30 @@
+#
+# Automatic Kernel Tunables
+#
+
+menu "Automatic Kernel Tunables"
+
+config AKT
+	bool "Automatic kernel tunable (kernel support)"
+	depends on PROC_FS && SYSFS
+	help
+	  This is a functionality that enables automatic adjustment of kernel
+	  tunables: when this feature is enabled the kernel can automatically
+	  change the tunables values as it sees resources running out.
+
+	  The list of kernel tunables that can potentially be automatically
+	  adjusted can found under /sys/tunables.
+
+	  In order to make a tunable actually automatic, issue the following
+	  command:
+	  echo 1 > /sys/tunables/<tunable_name>/autotune
+
+	  In order to make it manual, issue the following command:
+	  echo 0 > /sys/tunables/<tunable_name>/autotune
+
+	  See Documentation/auto_tune.txt for more details.
+
+	  If unsure, say N.
+
+endmenu
+
kernel/autotune/Makefile new file +7 -0
Index: linux-2.6.20-rc4/kernel/autotune/Makefile
===================================================================
@@ -0,0 +1,7 @@
+#
+# Makefile for akt
+#
+
+obj-y := akt.o
+
+
kernel/autotune/akt.c new file +123 -0

123 lines not on this page · raw message

kernel/fork.c +18 -0
Index: linux-2.6.20-rc4/kernel/fork.c
===================================================================
@@ -49,6 +49,8 @@
 #include <linux/delayacct.h>
 #include <linux/taskstats_kern.h>
 #include <linux/random.h>
+#include <linux/akt.h>
+#include <linux/akt_ops.h>
 
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
@@ -65,6 +67,13 @@ int nr_threads; 		/* The idle threads do
 
 int max_threads;		/* tunable limit on nr_threads */
 
+#define THREADTHRESH 80
+/*
+ * The actual values for min and max will be known during fork_init
+ */
+DEFINE_TUNABLE(max_threads_akt, THREADTHRESH, 0, 0, &max_threads,
+		&nr_threads, int);
+
 DEFINE_PER_CPU(unsigned long, process_counts) = 0;
 
 __cacheline_aligned DEFINE_RWLOCK(tasklist_lock);  /* outer */
@@ -152,12 +161,21 @@ void __init fork_init(unsigned long memp
 	if(max_threads < 20)
 		max_threads = 20;
 
+	set_tunable_min_max(max_threads_akt, max_threads, mempages / 2, int);
+
 	init_task.signal->rlim[RLIMIT_NPROC].rlim_cur = max_threads/2;
 	init_task.signal->rlim[RLIMIT_NPROC].rlim_max = max_threads/2;
 	init_task.signal->rlim[RLIMIT_SIGPENDING] =
 		init_task.signal->rlim[RLIMIT_NPROC];
 }
 
+void __init fork_late_init(void)
+{
+	if (register_tunable(&max_threads_akt))
+		printk(KERN_WARNING
+			"Failed registering tunable max_threads\n");
+}
+
 static struct task_struct *dup_task_struct(struct task_struct *orig)
 {
 	struct task_struct *tsk;

--

#2 lore raw

Re: [RFC][PATCH 1/6] Tunable structure and registration routines

Quoted 36 lines · On Tue, 16 Jan 2007 07:15:17 +0100 [email protected] wrote:

[PATCH 01/06]

Defines the auto_tune structure: this is the structure that contains the information needed by the adjustment routine for a given tunable. Also defines the registration routines.

The fork kernel component defines a tunable structure for the threads-max tunable and registers it.

---
 Documentation/00-INDEX      |    2 
 Documentation/auto_tune.txt |  333 ++++++++++++++++++++++++++++++++++++++++++++
 fs/Kconfig                  |    2 
 include/linux/akt.h         |  186 ++++++++++++++++++++++++
 include/linux/akt_ops.h     |  186 ++++++++++++++++++++++++
 init/main.c                 |    2 
 kernel/Makefile             |    1 
 kernel/autotune/Kconfig     |   30 +++
 kernel/autotune/Makefile    |    7 
 kernel/autotune/akt.c       |  123 ++++++++++++++++
 kernel/fork.c               |   18 ++
 11 files changed, 890 insertions(+)

Index: linux-2.6.20-rc4/Documentation/auto_tune.txt
===================================================================

Documentation/auto_tune.txt new file +7 -0
@@ -0,0 +1,333 @@
+			Automatic Kernel Tunables
+                        =========================
+
+		   Nadia Derbey ([email protected])
+
+
+

Documentation/auto_tune.txt line 17

Quoted 10 lines
Documentation/auto_tune.txt new file +10 -0
+This feature aims at making the kernel automatically change the tunables
+values as it sees resources running out.
+
+The AKT framework is made of 2 parts:
+
+1) Kernel part:
+Interfaces are provided to the kernel subsystems, to (un)register the
+tunables that might be automatically tuned in the future.
+
+Registering a tunable consists in the following steps:
                                 s/in/of/
Quoted 5 lines
Documentation/auto_tune.txt new file +5 -0
+- a structure is declared and filled by the kernel subsystem for the
+registered tunable
+- that tunable structure is registered into sysfs
+
+Registration should be done during the kernel subsystem initialization step.

...

Quoted 7 lines
Documentation/auto_tune.txt new file +7 -0
+Any kernel subsystem that has registered a tunable should call
+auto_tune_func() as follows:
+
++-------------------------+--------------------------------------------+
+| Step                    | Routine to call                            |
++-------------------------+--------------------------------------------+
+| Declaration phase       | DEFINE_TUNABLE(name, values...);           |

Documentation/auto_tune.txt line 194

Quoted 10 lines
Documentation/auto_tune.txt new file +10 -0
++-------------------------+--------------------------------------------+
+| Initialization routine  | set_tunable_min_max(name, min, max);       |
+|                         | set_autotuning_routine(name, routine);     |
+|                         | register_tunable(&name);                   |
+| Note: the 1st 2 calls   |                                            |
+|       are optional      |                                            |
++-------------------------+--------------------------------------------+
+| Alloc                   | activate_auto_tuning(AKT_UP, &name);       |
++-------------------------+--------------------------------------------+
+| Free                    | activate_auto_tuning(AKT_DOWN, &name);     |

So does Free always use AKT_DOWN? why does it matter? Seems unneeded and inconsistent.
How does one activate a tunable for downward adjustment?

Documentation/auto_tune.txt line 201

Quoted 7 lines

++-------------------------+--------------------------------------------+
+| module_exit() routine | unregister_tunable(&name); |
++-------------------------+--------------------------------------------+

Documentation/auto_tune.txt new file +4 -0
+
+activate_auto_tuning is a static inline defined in akt.h, that does the
+following:
+. if <tunable is registered> and <auto tuning is allowd for tunable>

allowed

Quoted 25 lines

+. call the routine stored in tunable->auto_tune

Documentation/auto_tune.txt new file +24 -0
+
+
+The effect of the default automatic tuning routine is the following:
+
+           +----------------------------------------------------------------+
+           |                 Tunable automatically adjustable               |
+           +---------------+------------------------------------------------+
+           |      NO       |                      YES                       |
++----------+---------------+------------------------------------------------+
+| AKT_UP   | No effect     | If the tunable value exceeds the specified     |
+|          |               | threshold, that value is increased up to a     |
+|          |               | maximum value.                                 |
+|          |               | The maximum value is specified during the      |
+|          |               | tunable declaration and can be changed at any  |
+|          |               | time through sysfs                             |
++----------+---------------+------------------------------------------------+
+| AKT_DOWN | No effect     | If the tunable value falls under the specified |
+|          |               | threshold, that value is decreased down to a   |
+|          |               | minimum value.                                 |
+|          |               | The minimum value is specified during the      |
+|          |               | tunable declaration and can be changed at any  |
+|          |               | time through sysfs                             |
++----------+---------------+------------------------------------------------+
+

Documentation/auto_tune.txt line 236

Quoted 10 lines
Documentation/auto_tune.txt new file +10 -0
+
+1.6. Default automatic adjustment routine
+
+The last service provided by AKT at the kernel level is the default automatic
+adjustment routine. As seen, above, this routine supports various tunables
+types. It works as follows (only the AKT_UP direction is described here -
+AKT_DOWN does the reverse operation):
+
+The 2nd parameter passed in to this routine is a pointer to a previously
+registerd tunable structure. That structure contains the following fields (see

registered

Quoted 17 lines

+1.1 for the detailed description):

+- threshold
+- key
+- min
+- max
+- tunable
+- checked
Documentation/auto_tune.txt new file +10 -0
+
+When this routine is entered, it does the following:
+1. <*checked> is compared to <*tunable> * threshold
+2. if <*checked> is greater, <*tunable> is set to:
+	<*tunable> + (<*tunable> * (100 - threshold) / 100)
+
+
+
+1.6) akt and sysfs:
+

...

Quoted 3 lines
Documentation/auto_tune.txt new file +3 -0
+
+1.7) tunables that are namespace dependent
+

...

Quoted 4 lines
Documentation/auto_tune.txt new file +4 -0
+
+1.7.2) Initializing the tunable structure
+
+Then the tunable structure should be initialized by calling the following

Documentation/auto_tune.txt line 299

Quoted 10 lines
Documentation/auto_tune.txt new file +10 -0
+routine:
+
+init_tunable_ipcns(namespace_ptr, structure_name, threshold, min, max,
+		tunable_variable_ptr, checked_variable_ptr,
+		tunable_variable_type);
+
+Parameters:
+- namespace_ptr: pointer to the namespace the tunable belongs to.
+
+See DEFINE_TUNABLE for the other parameters

end with a period/full-stop '.'.

Quoted 3 lines
Documentation/auto_tune.txt new file +3 -0
+
+1.7.3) Registering the tunable structure
+

...

Documentation/auto_tune.txt line 318

Quoted 8 lines
Documentation/auto_tune.txt new file +8 -0
+
+2) User part:
+
+As seen above, the only way to activate automatic tuning is from user side:
+- the directory /sys/tunables is created during the init phase.
+- each time a tunable is registered by a kernel subsystem, a directory is
+created for it under /sys/tunables.
+- This directory contains 1 file for each tunable kobject attribute:

Please try to limit text documentation to 80 columns or less.

Quoted 20 lines

++-----------+---------------+-------------------+----------------------------+
+| attribute | default value | how to set it | effect |
++-----------+---------------+-------------------+----------------------------+

+| autotune  | 0             | echo 1 > autotune | makes the tunable automatic|
+|           |               | echo 0 > autotune | makes the tunable manual   |
++-----------+---------------+-------------------+----------------------------+
+| max       | max value set | echo <M> > max    | sets the tunable max value |
+|           | during tunable|                   | to <M>                     |
+|           | definition    |                   |                            |
++-----------+---------------+-------------------+----------------------------+
+| min       | min value set | echo <m> > min    | sets the tunable min value |
+|           | during tunable|                   | to <m>                     |
+|           | definition    |                   |                            |

++-----------+---------------+-------------------+----------------------------+
+
Index: linux-2.6.20-rc4/fs/Kconfig
===================================================================

fs/Kconfig config PROC_KCORE · line 928

Quoted 4 lines
fs/Kconfig +1 -0
@@ -925,6 +925,8 @@ config PROC_KCORE
 	bool "/proc/kcore support" if !ARM
 	depends on PROC_FS && MMU
 
+source "kernel/autotune/Kconfig"

Why is that is the File systems menu? Seems odd to me for it to be there. If it's just because it depends on PROC_FS and SYSFS, then it should just go completely after the File systems menu.

Quoted 25 lines
fs/Kconfig +0 -0
 config PROC_VMCORE
         bool "/proc/vmcore support (EXPERIMENTAL)"
         depends on PROC_FS && EXPERIMENTAL && CRASH_DUMP

Index: linux-2.6.20-rc4/include/linux/akt.h
===================================================================

include/linux/akt.h new file +17 -0
@@ -0,0 +1,186 @@
+
+#ifndef AKT_H
+#define AKT_H
+
+#include <linux/types.h>
+#include <linux/kobject.h>
+
+/*
+ * First parameter passed to the adjustment routine
+ */
+#define AKT_UP   0   /* adjustment "up" */
+#define AKT_DOWN 1   /* adjustment "down" */
+
+
+struct auto_tune {
+	spinlock_t tunable_lck; /* serializes access to the stucture fields */
+	auto_tune_fn auto_tune; /* auto tuning routine registered by the */

include/linux/akt.h line 27

Quoted 10 lines
include/linux/akt.h new file +10 -0
+				/* calling kernel susbsystem. If NULL, the */
+				/* auto tuning routine that will be called */
+				/* is the default one that processes uints */
+	int (*check_parms)(struct auto_tune *);	/* min / max checking */
+						/* routine ptr: points to */
+						/* the appropriate routine */
+						/* depending on the */
+						/* tunable type */
+	const char *name;
+	char flags;	/* Only 2 bits are meaningful: */

Make flags unsigned char so that no sign bit is needed.

include/linux/akt.h line 104

Quoted 5 lines
include/linux/akt.h new file +5 -0
+			/* bit 0: set to 1 if the associated tunable can */
+			/*        be automatically adjusted */
+			/* bits 1: set to 1 if the tunable has been */
+			/*         registered */
+			/* bits 2-7: useless */

unused ??

Quoted 12 lines
include/linux/akt.h new file +12 -0
+	char threshold;	/* threshold to enable the adjustment expressed as */
+			/* a %age */
+	struct typed_value min;	/* min value the tunable can ever reach */
+				/* and associated show / store routines) */
+	struct typed_value max;	/* max value the tunable can ever reach */
+				/* and associated show / store routines) */
+	void *tunable;	/* address of the tunable to adjust */
+	void *checked;	/* address of the variable that is controlled by */
+			/* the tunable. This is the calling subsystem's */
+			/* object counter */
+};
+

...

include/linux/akt.h line 184

Quoted 2 lines
include/linux/akt.h new file +2 -0
+
+extern void fork_late_init(void);

Looks like the wrong header file for that extern.

Quoted 21 lines

+#endif /* AKT_H */

Index: linux-2.6.20-rc4/kernel/autotune/akt.c
===================================================================

kernel/autotune/akt.c new file +14 -0
@@ -0,0 +1,123 @@
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/akt.h>
+
+
+
+	Too Much Whitespace.  :)
+
+
+
+/*
+ * FUNCTION:    Inserts a tunable structure into sysfs
+ *              This routine serves also as a checker for the tunable

kernel/autotune/akt.c line 24

Quoted 10 lines
kernel/autotune/akt.c new file +10 -0
+ *              structure fields.
+ *              This routine is called by any kernel subsystem that wants to
+ *              use akt services (automatic tunables adjustment) in the future
+ *
+ * NOTE: when calling this routine, the tunable structure should have already
+ *       been filled by defining it with DEFINE_TUNABLE()
+ *
+ * RETURN VALUE: 0: successful
+ *               <0 if failure
+ */

Please use kernel-doc format for function comment blocks.

kernel/autotune/akt.c line 58

Quoted 4 lines
kernel/autotune/akt.c new file +4 -0
+int register_tunable(struct auto_tune *tun)
+{
+	if (tun == NULL) {
+		printk(KERN_ERR "\tBad tunable structure pointer (NULL)\n");

Each printk() needs something that tells that module or part of the kernel that it's coming from (sometimes called a prefix). And drop the \t (tab). IOW, replace the tab with a prefix, e.g.:

printk(KERN_ERR "autotune: Bad tunable structure NULL pointer\n");

kernel/autotune/akt.c line 65

Quoted 7 lines
kernel/autotune/akt.c new file +7 -0
+		return -EINVAL;
+	}
+
+	if (tun->threshold <= 0 || tun->threshold >= 100) {
+		printk(KERN_ERR "\tBad threshold (%d) value "
+			"- should be in the [1-99] interval\n",
+			tun->threshold);

Replace \t with a prefix (and more below).

Quoted 48 lines
kernel/autotune/akt.c new file +48 -0
+		return -EINVAL;
+	}
+
+	if (tun->tunable == NULL) {
+		printk(KERN_ERR "\tBad tunable pointer (NULL)\n");
+		return -EINVAL;
+	}
+
+	if (tun->checked == NULL) {
+		printk(KERN_ERR "\tBad checked value pointer (NULL)\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Check the min / max value
+	 */
+	if (tun->check_parms(tun)) {
+		printk(KERN_ERR "\tBad min / max values\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+
+/*
+ * FUNCTION:    Removes a tunable structure from sysfs.
+ *              This routine is called by any kernel subsystem that doesn't
+ *              need the akt services anymore
+ *
+ * NOTE:  reg_tun should point to a previously registered tunable
+ *
+ * RETURN VALUE: 0: successful
+ *               <0 if failure
+ */
+int unregister_tunable(struct auto_tune *reg_tun)
+{
+	if (reg_tun == NULL) {
+		printk(KERN_ERR "\tBad tunable address (NULL)\n");
+		return -EINVAL;
+	}
+
+	spin_lock(&reg_tun->tunable_lck);
+
+	BUG_ON(!is_tunable_registered(reg_tun));
+
+	reg_tun->flags = 0;
+

kernel/autotune/akt.c line 123

Quoted 10 lines
kernel/autotune/akt.c new file +10 -0
+	spin_unlock(&reg_tun->tunable_lck);
+
+	return 0;
+}
+
+	Too Much Whitespace....
+
+
+EXPORT_SYMBOL_GPL(register_tunable);
+EXPORT_SYMBOL_GPL(unregister_tunable);

---
~Randy

#3 lore raw

Re: [RFC][PATCH 1/6] Tunable structure and registration routines

Randy,

Thanks for reviewing the code!
My comments embedded.
I'll re-send the patches as soon as possible.

Regards,
Nadia

Quoted 5 lines · Randy Dunlap
Quoted 2 lines · On Tue, 16 Jan 2007 07:15:17 +0100 [email protected] wrote:

[PATCH 01/06]

<snip>

Quoted 15 lines
Quoted 15 lines
Documentation/auto_tune.txt new file +13 -0
+Any kernel subsystem that has registered a tunable should call
+auto_tune_func() as follows:
+
++-------------------------+--------------------------------------------+
+| Step                    | Routine to call                            |
++-------------------------+--------------------------------------------+
+| Declaration phase       | DEFINE_TUNABLE(name, values...);           |
++-------------------------+--------------------------------------------+
+| Initialization routine  | set_tunable_min_max(name, min, max);       |
+|                         | set_autotuning_routine(name, routine);     |
+|                         | register_tunable(&name);                   |
+| Note: the 1st 2 calls   |                                            |
+|       are optional      |                                            |
Quoted 8 lines
Quoted 4 lines

++-------------------------+--------------------------------------------+
+| Alloc | activate_auto_tuning(AKT_UP, &name); |
++-------------------------+--------------------------------------------+
+| Free | activate_auto_tuning(AKT_DOWN, &name); |

So does Free always use AKT_DOWN? why does it matter? Seems unneeded and inconsistent.

Tuning down is recommended in order to come back to the default tunable value.
I agree with you: today it has quite no effect, except on the tunable value. If we take the ipc's example, grow_ary() just returns if the new tunable value happens to be lower than the previous one. But we can imagine, in the future, that grow_ary could deallocate the unused memory.
+ in that particular case, lowering the tunable value makes the 1st loop in ipc_addid() shorter.

Quoted 1 line

How does one activate a tunable for downward adjustment?

Actually a tunable is activated to be dynamically adjusted (whatever the direction).
But you are giving me an idea for a future enhancement: we can imagine a tunable that could be allowed to increase only (or decrease only). In that case, we should move the autotune sysfs attribute into an 'up' and a 'down' attribute?

<snip>

Quoted 11 lines

Documentation/auto_tune.txt line 318

Quoted 8 lines
Documentation/auto_tune.txt new file +8 -0
+
+2) User part:
+
+As seen above, the only way to activate automatic tuning is from user side:
+- the directory /sys/tunables is created during the init phase.
+- each time a tunable is registered by a kernel subsystem, a directory is
+created for it under /sys/tunables.
+- This directory contains 1 file for each tunable kobject attribute:

Please try to limit text documentation to 80 columns or less.

That's exactly what I did?

<snip>

Quoted 8 lines
Quoted 8 lines

Index: linux-2.6.20-rc4/fs/Kconfig
===================================================================

fs/Kconfig +0 -0
@@ -925,6 +925,8 @@ config PROC_KCORE
 	bool "/proc/kcore support" if !ARM
 	depends on PROC_FS && MMU
 
Quoted 8 lines

fs/Kconfig config PROC_KCORE · line 928

Quoted 1 line
fs/Kconfig +1 -0
+source "kernel/autotune/Kconfig"

Why is that is the File systems menu? Seems odd to me for it to be there. If it's just because it depends on PROC_FS and SYSFS, then it should just go completely after the File systems menu.

Since the tunables that are handled in AKT, I wanted the feature to be close to CONFIG_PROC_FS.
Now, I do not agree with your proposal: putting it after the FS menu means that it would appear in the main menu, right? I'll try to find a better place for it.

Quoted 6 lines
Quoted 6 lines

Index: linux-2.6.20-rc4/include/linux/akt.h
===================================================================

include/linux/akt.h new file +1 -0
@@ -0,0 +1,186 @@
+

<snip>

Quoted 6 lines

include/linux/akt.h line 99

Quoted 1 line
include/linux/akt.h new file +1 -0
+	char flags;	/* Only 2 bits are meaningful: */

Make flags unsigned char so that no sign bit is needed.

Quoted 8 lines

include/linux/akt.h line 104

Quoted 5 lines
include/linux/akt.h new file +5 -0
+			/* bit 0: set to 1 if the associated tunable can */
+			/*        be automatically adjusted */
+			/* bits 1: set to 1 if the tunable has been */
+			/*         registered */
+			/* bits 2-7: useless */

unused ??

yep

<snip>

Quoted 9 lines

include/linux/akt.h line 184

Quoted 4 lines
include/linux/akt.h new file +2 -0
+
+extern void fork_late_init(void);

Looks like the wrong header file for that extern.

Actually, I wanted the changes to the existing kernel files to be as small as possible. That's why everything is concentrated, whenever possible, in the added files.

Regards,
Nadia

#4 lore raw

Re: [RFC][PATCH 1/6] Tunable structure and registration routines

Quoted 5 lines · On Thu, 25 Jan 2007 17:26:31 +0100 Nadia Derbey wrote:

Randy,

Thanks for reviewing the code!
My comments embedded.
I'll re-send the patches as soon as possible.

OK, thanks.

Quoted 31 lines
Quoted 5 lines · Randy Dunlap
Quoted 2 lines · On Tue, 16 Jan 2007 07:15:17 +0100 [email protected] wrote:

[PATCH 01/06]

<snip>

Quoted 15 lines
Quoted 15 lines
Documentation/auto_tune.txt new file +13 -0
+Any kernel subsystem that has registered a tunable should call
+auto_tune_func() as follows:
+
++-------------------------+--------------------------------------------+
+| Step                    | Routine to call                            |
++-------------------------+--------------------------------------------+
+| Declaration phase       | DEFINE_TUNABLE(name, values...);           |
++-------------------------+--------------------------------------------+
+| Initialization routine  | set_tunable_min_max(name, min, max);       |
+|                         | set_autotuning_routine(name, routine);     |
+|                         | register_tunable(&name);                   |
+| Note: the 1st 2 calls   |                                            |
+|       are optional      |                                            |
Quoted 8 lines
Quoted 4 lines

++-------------------------+--------------------------------------------+
+| Alloc | activate_auto_tuning(AKT_UP, &name); |
++-------------------------+--------------------------------------------+
+| Free | activate_auto_tuning(AKT_DOWN, &name); |

So does Free always use AKT_DOWN? why does it matter? Seems unneeded and inconsistent.

Quoted 2 lines

Tuning down is recommended in order to come back to the default tunable value.

Let me try to be clearer. What is Alloc? and why is AKT_UP associated with Alloc and AFK_DOWN associated with Free (whatever that means)?

Quoted 8 lines

I agree with you: today it has quite no effect, except on the tunable value. If we take the ipc's example, grow_ary() just returns if the new tunable value happens to be lower than the previous one.
But we can imagine, in the future, that grow_ary could deallocate the unused memory.
+ in that particular case, lowering the tunable value makes the 1st loop in ipc_addid() shorter.

Quoted 8 lines
Quoted 1 line

How does one activate a tunable for downward adjustment?

Actually a tunable is activated to be dynamically adjusted (whatever the direction).
But you are giving me an idea for a future enhancement: we can imagine a tunable that could be allowed to increase only (or decrease only). In that case, we should move the autotune sysfs attribute into an 'up' and a 'down' attribute?

Couldn't the tunable owner just adjust the min value to a new (larger) min value, e.g.?

Quoted 10 lines
Quoted 6 lines
Quoted 1 line

+extern void fork_late_init(void);

Looks like the wrong header file for that extern.

Actually, I wanted the changes to the existing kernel files to be as small as possible. That's why everything is concentrated, whenever possible, in the added files.

I suppose that's OK for review, but it shouldn't be merged that way.

---
~Randy

#5 lore raw

Re: [RFC][PATCH 1/6] Tunable structure and registration routines

Quoted 23 lines · Randy Dunlap
Quoted 22 lines · On Thu, 25 Jan 2007 17:26:31 +0100 Nadia Derbey wrote:
Quoted 21 lines
Quoted 7 lines
Documentation/auto_tune.txt new file +7 -0
+Any kernel subsystem that has registered a tunable should call
+auto_tune_func() as follows:
+
++-------------------------+--------------------------------------------+
+| Step                    | Routine to call                            |
++-------------------------+--------------------------------------------+
+| Declaration phase       | DEFINE_TUNABLE(name, values...);           |

Documentation/auto_tune.txt line 194

Quoted 10 lines
Documentation/auto_tune.txt new file +10 -0
++-------------------------+--------------------------------------------+
+| Initialization routine  | set_tunable_min_max(name, min, max);       |
+|                         | set_autotuning_routine(name, routine);     |
+|                         | register_tunable(&name);                   |
+| Note: the 1st 2 calls   |                                            |
+|       are optional      |                                            |
++-------------------------+--------------------------------------------+
+| Alloc                   | activate_auto_tuning(AKT_UP, &name);       |
++-------------------------+--------------------------------------------+
+| Free                    | activate_auto_tuning(AKT_DOWN, &name);     |

So does Free always use AKT_DOWN? why does it matter? Seems unneeded and inconsistent.

Quoted 6 lines
Quoted 1 line

Tuning down is recommended in order to come back to the default tunable value.

Let me try to be clearer. What is Alloc? and why is AKT_UP associated with Alloc and AFK_DOWN associated with Free (whatever that means)?

Alloc stands for resource allocation: in a subsystem where resource allocation depends on a tunable value, we should tune up that value prior to the alllocation itself. Let's come back to the ipc subsystem example: ipc_addid() is the routine that adds an entry to an ipc array. The 1st thing it does (via grow_ary()) is to allocate some more space for the ipc array if needed, i.e. if the ipc tunable value has increased. That's why the tunable should be tuned up before calling ipc_addid().

AKT_DOWN is the reverse operation: we are freeing resources, so the tunble has no reason to remain with a big value.

Quoted 9 lines
Quoted 9 lines

I agree with you: today it has quite no effect, except on the tunable value. If we take the ipc's example, grow_ary() just returns if the new tunable value happens to be lower than the previous one. But we can imagine, in the future, that grow_ary could deallocate the unused memory.
+ in that particular case, lowering the tunable value makes the 1st loop
in ipc_addid() shorter.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

How does one activate a tunable for downward adjustment?

Actually a tunable is activated to be dynamically adjusted (whatever the direction).
But you are giving me an idea for a future enhancement: we can imagine a tunable that could be allowed to increase only (or decrease only). In that case, we should move the autotune sysfs attribute into an 'up' and a 'down' attribute?

Couldn't the tunable owner just adjust the min value to a new (larger) min value, e.g.?

You're completely right: setting the min value to the default one should be enough!

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines

+extern void fork_late_init(void);

Looks like the wrong header file for that extern.

Quoted 8 lines
Quoted 1 line

Actually, I wanted the changes to the existing kernel files to be as small as possible. That's why everything is concentrated, whenever possible, in the added files.

I suppose that's OK for review, but it shouldn't be merged that way.

---
~Randy

Regards,
Nadia

#6 lore raw

RFC PATCH 2/6 auto_tuning activation

In reply to [email protected]

[PATCH 02/06]

Introduces the auto-tuning activation routine

The auto-tuning routine is called by the fork kernel component

---
 include/linux/akt.h |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/exit.c       |   11 +++++++++++
 kernel/fork.c       |    2 ++
 3 files changed, 63 insertions(+)
include/linux/akt.h +50 -0
Index: linux-2.6.20-rc4/include/linux/akt.h
===================================================================
@@ -118,12 +118,22 @@ struct auto_tune {
 /*
  * Flags for a registered tunable
  */
+#define AUTO_TUNE_ENABLE  0x01
 #define TUNABLE_REGISTERED  0x02
 
 
 /*
  * When calling this routine the tunable lock should be held
  */
+static inline int is_auto_tune_enabled(struct auto_tune *tunable)
+{
+	return (tunable->flags & AUTO_TUNE_ENABLE) == AUTO_TUNE_ENABLE;
+}
+
+
+/*
+ * When calling this routine the tunable lock should be held
+ */
 static inline int is_tunable_registered(struct auto_tune *tunable)
 {
 	return (tunable->flags & TUNABLE_REGISTERED) == TUNABLE_REGISTERED;
@@ -163,6 +173,44 @@ static inline int is_tunable_registered(
 	} while (0)
 
 
+static inline void set_autotuning_routine(struct auto_tune *tunable,
+					auto_tune_fn fn)
+{
+	if (fn != NULL)
+		tunable->auto_tune = fn;
+}
+
+
+/*
+ * direction may be one of:
+ *    AKT_UP: adjust up (i.e. increase tunable value when needed)
+ *    AKT_DOWN: adjust down (i.e. decrease tunable value when needed)
+ */
+static inline int activate_auto_tuning(int direction,
+					struct auto_tune *tunable)
+{
+	int ret = 0;
+
+	BUG_ON(direction != AKT_UP && direction != AKT_DOWN);
+
+	if (tunable == NULL)
+		return 0;
+
+	spin_lock(&tunable->tunable_lck);
+
+	if (!is_auto_tune_enabled(tunable) ||
+					!is_tunable_registered(tunable)) {
+		spin_unlock(&tunable->tunable_lck);
+		return 0;
+	}
+
+	ret = tunable->auto_tune(direction, tunable);
+
+	spin_unlock(&tunable->tunable_lck);
+	return ret;
+}
+
+
 
 extern int register_tunable(struct auto_tune *);
 extern int unregister_tunable(struct auto_tune *);
@@ -173,7 +221,9 @@ extern int unregister_tunable(struct aut
 
 #define DEFINE_TUNABLE(s, thresh, min, max, tun, chk, type)
 #define set_tunable_min_max(s, min, max, type)   do { } while (0)
+#define set_autotuning_routine(s, fn)            do { } while (0)
 
+#define activate_auto_tuning(direction, tunable) ( { 0; } )
 
 #define register_tunable(a)                 0
 #define unregister_tunable(a)               0
kernel/fork.c +2 -0
Index: linux-2.6.20-rc4/kernel/fork.c
===================================================================
@@ -995,6 +995,8 @@ static struct task_struct *copy_process(
 	if ((clone_flags & CLONE_SIGHAND) && !(clone_flags & CLONE_VM))
 		return ERR_PTR(-EINVAL);
 
+	activate_auto_tuning(AKT_UP, &max_threads_akt);
+
 	retval = security_task_create(clone_flags);
 	if (retval)
 		goto fork_out;
kernel/exit.c +11 -0
Index: linux-2.6.20-rc4/kernel/exit.c
===================================================================
@@ -42,12 +42,15 @@
 #include <linux/audit.h> /* for audit_free() */
 #include <linux/resource.h>
 #include <linux/blkdev.h>
+#include <linux/akt.h>
 
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
 #include <asm/pgtable.h>
 #include <asm/mmu_context.h>
 
+extern struct auto_tune max_threads_akt;
+
 extern void sem_exit (void);
 
 static void exit_mm(struct task_struct * tsk);
@@ -172,6 +175,14 @@ repeat:
 
 	sched_exit(p);
 	write_unlock_irq(&tasklist_lock);
+
+	/*
+	 * nr_threads has been decremented in __unhash_process: adjust
+	 * max_threads down if needed
+	 * We do it here to avoid calling activate_auto_tuning under lock
+	 */
+	activate_auto_tuning(AKT_DOWN, &max_threads_akt);
+
 	proc_flush_task(p);
 	release_thread(p);
 	call_rcu(&p->rcu, delayed_put_task_struct);

--

#7 lore raw

RFC PATCH 3/6 tunables associated kobjects

In reply to [email protected]

[PATCH 03/06]

Introduces the kobjects associated to each tunable and the sysfs registration

---
 include/linux/akt.h         |   25 ++++-
 init/main.c                 |    1 
 kernel/autotune/Makefile    |    2 
 kernel/autotune/akt.c       |   86 +++++++++++++++++
 kernel/autotune/akt_sysfs.c |  214 ++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 324 insertions(+), 4 deletions(-)
include/linux/akt.h +23 -2
Index: linux-2.6.20-rc4/include/linux/akt.h
===================================================================
@@ -48,6 +48,16 @@ typedef int (*auto_tune_fn)(int, struct 
 
 
 /*
+ * for sysfs support
+ */
+struct tunable_kobject {
+	struct kobject kobj;
+	struct auto_tune *tun;
+};
+
+
+
+/*
  * Structure used to describe the min / max values for a tunable inside the
  * auto_tune structure.
  * These values are type dependent and are used as high / low boundaries when
@@ -73,7 +83,12 @@ struct typed_value {
  * allocated for each registered tunable, and the associated kobject exported
  * via sysfs.
  *
- * The structure lock (tunable_lck) protects
+ * This structure may be accessed in 2 ways:
+ *   . directly from inside the kernel susbsystem that uses it (during tunable
+ *     automatic adjustment)
+ *   . from sysfs, while updating the kobject attributes
+ *
+ * In both cases, the structure lock (tunable_lck) is taken: it protects
  * against concurrent accesses to tunable and checked pointers
  *
  * A pointer to this structure is passed in to  the automatic adjustment
@@ -108,6 +123,7 @@ struct auto_tune {
 				/* and associated show / store routines) */
 	struct typed_value max;	/* max value the tunable can ever reach */
 				/* and associated show / store routines) */
+	struct tunable_kobject    tun_kobj;	/* used for sysfs support */
 	void *tunable;	/* address of the tunable to adjust */
 	void *checked;	/* address of the variable that is controlled by */
 			/* the tunable. This is the calling subsystem's */
@@ -158,6 +174,7 @@ static inline int is_tunable_registered(
 		.max	= {						\
 			.value		= { .val_##type = (_max), },	\
 		},							\
+		.tun_kobj	= { .tun = NULL, },			\
 		.tunable	= (_tun),				\
 		.checked	= (_chk),				\
 	}
@@ -211,9 +228,12 @@ static inline int activate_auto_tuning(i
 }
 
 
-
+extern void init_auto_tuning(void);
 extern int register_tunable(struct auto_tune *);
 extern int unregister_tunable(struct auto_tune *);
+extern int tunable_sysfs_setup(struct auto_tune *);
+extern ssize_t show_tuning_mode(struct auto_tune *, char *);
+extern ssize_t store_tuning_mode(struct auto_tune *, const char *, size_t);
 
 
 #else	/* CONFIG_AKT */
@@ -228,6 +248,7 @@ extern int unregister_tunable(struct aut
 #define register_tunable(a)                 0
 #define unregister_tunable(a)               0
 
+static inline void init_auto_tuning(void)   { }
 
 #endif	/* CONFIG_AKT */
 
init/main.c +1 -0
Index: linux-2.6.20-rc4/init/main.c
===================================================================
@@ -614,6 +614,7 @@ asmlinkage void __init start_kernel(void
 	signals_init();
 	/* rootfs populating might need page-writeback */
 	page_writeback_init();
+	init_auto_tuning();
 	fork_late_init();
 #ifdef CONFIG_PROC_FS
 	proc_root_init();
kernel/autotune/Makefile +1 -1
Index: linux-2.6.20-rc4/kernel/autotune/Makefile
===================================================================
@@ -2,6 +2,6 @@
 # Makefile for akt
 #
 
-obj-y := akt.o
+obj-y := akt.o akt_sysfs.o
 
 
kernel/autotune/akt.c +85 -1

116 lines not on this page · raw message

kernel/autotune/akt_sysfs.c new file +214 -0

214 lines not on this page · raw message

--

#8 lore raw

RFC PATCH 4/6 min and max kobjects

In reply to [email protected]

[PATCH 04/06]

Introduces the kobjects associated to each tunable min and max value

---
 include/linux/akt.h         |   30 ++++
 include/linux/akt_ops.h     |  311 ++++++++++++++++++++++++++++++++++++++++++++
 kernel/autotune/akt.c       |  120 ++++++++++++++++
 kernel/autotune/akt_sysfs.c |    8 +
 4 files changed, 469 insertions(+)
include/linux/akt.h +30 -0
Index: linux-2.6.20-rc4/include/linux/akt.h
===================================================================
@@ -62,6 +62,13 @@ struct tunable_kobject {
  * auto_tune structure.
  * These values are type dependent and are used as high / low boundaries when
  * tuning up or down.
+ * The show and store routines (thare are type dependent too) are here for
+ * sysfs support (since the min and max can be updated through sysfs).
+ * The abs_value field is used to check that we are not:
+ *   . falling under the very 1st min value when updating the min value
+ *     through sysfs
+ *   . going over the very 1st max value when updating the max value
+ *     through sysfs
  * The type is known when the tunable is defined (see DEFINE_TUNABLE macro).
  */
 struct typed_value {
@@ -74,6 +81,17 @@ struct typed_value {
 		long   val_long;
 		ulong  val_ulong;
 	} value;
+	union {
+		short  val_short;
+		ushort val_ushort;
+		int    val_int;
+		uint   val_uint;
+		size_t val_size_t;
+		long   val_long;
+		ulong  val_ulong;
+	} abs_value;
+	ssize_t (*show)(struct auto_tune *, char *);
+	ssize_t (*store)(struct auto_tune *, const char *, size_t);
 };
 
 
@@ -170,9 +188,15 @@ static inline int is_tunable_registered(
 		.threshold	= (_thresh),				\
 		.min	= {						\
 			.value		= { .val_##type = (_min), },	\
+			.abs_value	= { .val_##type = (_min), },	\
+			.show		= show_tunable_min_##type,	\
+			.store		= store_tunable_min_##type,	\
 		},							\
 		.max	= {						\
 			.value		= { .val_##type = (_max), },	\
+			.abs_value	= { .val_##type = (_max), },	\
+			.show		= show_tunable_max_##type,	\
+			.store		= store_tunable_max_##type,	\
 		},							\
 		.tun_kobj	= { .tun = NULL, },			\
 		.tunable	= (_tun),				\
@@ -186,7 +210,9 @@ static inline int is_tunable_registered(
 #define set_tunable_min_max(s, _min, _max, type)	\
 	do {						\
 		(s).min.value.val_##type = _min;	\
+		(s).min.abs_value.val_##type = _min;	\
 		(s).max.value.val_##type = _max;	\
+		(s).max.abs_value.val_##type = _max;	\
 	} while (0)
 
 
@@ -234,6 +260,10 @@ extern int unregister_tunable(struct aut
 extern int tunable_sysfs_setup(struct auto_tune *);
 extern ssize_t show_tuning_mode(struct auto_tune *, char *);
 extern ssize_t store_tuning_mode(struct auto_tune *, const char *, size_t);
+extern ssize_t show_tunable_min(struct auto_tune *, char *);
+extern ssize_t store_tunable_min(struct auto_tune *, const char *, size_t);
+extern ssize_t show_tunable_max(struct auto_tune *, char *);
+extern ssize_t store_tunable_max(struct auto_tune *, const char *, size_t);
 
 
 #else	/* CONFIG_AKT */
include/linux/akt_ops.h +311 -0

316 lines not on this page · raw message

kernel/autotune/akt.c +120 -0

131 lines not on this page · raw message

kernel/autotune/akt_sysfs.c +8 -0
Index: linux-2.6.20-rc4/kernel/autotune/akt_sysfs.c
===================================================================
@@ -54,8 +54,16 @@ struct tunable_attribute tun_attr_##_nam
 static TUNABLE_ATTR(autotune, S_IWUSR | S_IRUGO, show_tuning_mode,
 		store_tuning_mode);
 
+static TUNABLE_ATTR(min, S_IWUSR | S_IRUGO, show_tunable_min,
+		store_tunable_min);
+
+static TUNABLE_ATTR(max, S_IWUSR | S_IRUGO, show_tunable_max,
+		store_tunable_max);
+
 static struct tunable_attribute *tunable_sysfs_attrs[] = {
 	&tun_attr_autotune,	/* to (de)activate auto tuning */
+	&tun_attr_min,		/* to play with the tunable min value */
+	&tun_attr_max,		/* to play with the tunable max value */
 	NULL,
 };
 

--

#9 lore raw

Re: [RFC][PATCH 4/6] min and max kobjects

Quoted 17 lines · On Tue, 16 Jan 2007 07:15:20 +0100 [email protected] wrote:

[PATCH 04/06]

Introduces the kobjects associated to each tunable min and max value

---
 include/linux/akt.h         |   30 ++++
 include/linux/akt_ops.h     |  311 ++++++++++++++++++++++++++++++++++++++++++++
 kernel/autotune/akt.c       |  120 ++++++++++++++++
 kernel/autotune/akt_sysfs.c |    8 +
 4 files changed, 469 insertions(+)

Index: linux-2.6.20-rc4/include/linux/akt.h
===================================================================

include/linux/akt.h struct tunable_kobject { · line 65

Quoted 4 lines
include/linux/akt.h +1 -0
@@ -62,6 +62,13 @@ struct tunable_kobject {
  * auto_tune structure.
  * These values are type dependent and are used as high / low boundaries when
  * tuning up or down.
+ * The show and store routines (thare are type dependent too) are here for

they (or these ?)

Quoted 16 lines
include/linux/akt.h +6 -0
+ * sysfs support (since the min and max can be updated through sysfs).
+ * The abs_value field is used to check that we are not:
+ *   . falling under the very 1st min value when updating the min value
+ *     through sysfs
+ *   . going over the very 1st max value when updating the max value
+ *     through sysfs
  * The type is known when the tunable is defined (see DEFINE_TUNABLE macro).
  */
 struct typed_value {

Index: linux-2.6.20-rc4/kernel/autotune/akt.c
===================================================================

kernel/autotune/akt.c +0 -0
@@ -203,5 +207,121 @@ ssize_t store_tuning_mode(struct auto_tu
 }

kernel/autotune/akt.c ssize_t store_tuning_mode(struct auto_tu · line 217

Quoted 10 lines
kernel/autotune/akt.c +8 -0
 
 
+/*
+ * FUNCTION:    Get operation called by tunable_attr_show (i.e. when the file
+ *              /sys/tunables/<tunable>/min is displayed).
+ *              Outputs the current tunable minimum value
+ *
+ * RETURN VALUE: >0 : output string length (including the '\0')
+ *               <0 : failure
+ */

Since you are providing function comment header blocks, please use the accepted kernel-doc format for (all of) these.

Quoted 18 lines
kernel/autotune/akt.c +18 -0
+ssize_t show_tunable_min(struct auto_tune *tun_addr, char *buf)
+{
+	ssize_t rc;
+
+	if (tun_addr == NULL) {
+		printk(KERN_ERR
+			" show_tunable_min(): tunable address is invalid\n");
+		return -EINVAL;
+	}
+
+	spin_lock(&tun_addr->tunable_lck);
+
+	rc = tun_addr->min.show(tun_addr, buf);
+
+	spin_unlock(&tun_addr->tunable_lck);
+
+	return rc;
+}

kernel/autotune/akt.c ssize_t store_tuning_mode(struct auto_tu · line 245

Quoted 10 lines
kernel/autotune/akt.c +10 -0
+
+
+/*
+ * FUNCTION:    Set operation called by tunable_attr_store (i.e. when a
+ *              string is stored into /sys/tunables/<tunable>/min).
+ *
+ * PARAMETERS:  count: input buffer size (including the '\0')
+ *
+ * RETURN VALUE: >0: number of characters used from the input buffer
+ *               <= 0: failure

I would expect a return value of 0 not to indicate failure; only <0 should do that. So is this a typo or a real case where a return of 0 indicates failure?

Quoted 22 lines
kernel/autotune/akt.c +22 -0
+ */
+ssize_t store_tunable_min(struct auto_tune *tun_addr, const char *buf,
+			size_t count)
+{
+	ssize_t rc;
+
+	if (tun_addr == NULL) {
+		printk(KERN_ERR
+			" store_tunable_min(): tunable address is invalid\n");
+		return -EINVAL;
+	}
+
+	spin_lock(&tun_addr->tunable_lck);
+
+	rc = tun_addr->min.store(tun_addr, buf, count);
+
+	spin_unlock(&tun_addr->tunable_lck);
+
+	return rc;
+}
+
+

kernel/autotune/akt.c ssize_t store_tuning_mode(struct auto_tu · line 303

Quoted 10 lines
kernel/autotune/akt.c +10 -0
+
+
+/*
+ * FUNCTION:    Set operation called by tunable_attr_store (i.e. when a
+ *              string is stored into /sys/tunables/<tunable>/max).
+ *
+ * PARAMETERS:  count: input buffer size (including the '\0')
+ *
+ * RETURN VALUE: >0: number of characters used from the input buffer
+ *               <= 0: failure

same question.

Quoted 14 lines
kernel/autotune/akt.c +14 -0
+ */
+ssize_t store_tunable_max(struct auto_tune *tun_addr, const char *buf,
+			size_t count)
+{
+	ssize_t rc;
+
+	if (tun_addr == NULL) {
+		printk(KERN_ERR
+			" store_tunable_max(): tunable address is invalid\n");
+		return -EINVAL;
+	}
+
+	spin_lock(&tun_addr->tunable_lck);
+

kernel/autotune/akt.c ssize_t store_tuning_mode(struct auto_tu · line 327

Quoted 10 lines
kernel/autotune/akt.c +8 -0
+	rc = tun_addr->max.store(tun_addr, buf, count);
+
+	spin_unlock(&tun_addr->tunable_lck);
+
+	return rc;
+}
+
+
 EXPORT_SYMBOL_GPL(register_tunable);
 EXPORT_SYMBOL_GPL(unregister_tunable);

Thanks.

---
~Randy

#10 lore raw

Re: [RFC][PATCH 4/6] min and max kobjects

Quoted 7 lines · Randy Dunlap
Quoted 4 lines · On Tue, 16 Jan 2007 07:15:20 +0100 [email protected] wrote:

[PATCH 04/06]

Introduces the kobjects associated to each tunable min and max value

<snip>

Quoted 8 lines
Quoted 8 lines

Index: linux-2.6.20-rc4/kernel/autotune/akt.c
===================================================================

kernel/autotune/akt.c +0 -0
@@ -203,5 +207,121 @@ ssize_t store_tuning_mode(struct auto_tu
 }
 
 

<snip>

Quoted 6 lines
Quoted 6 lines
kernel/autotune/akt.c +6 -0
+
+/*
+ * FUNCTION:    Set operation called by tunable_attr_store (i.e. when a
+ *              string is stored into /sys/tunables/<tunable>/min).
+ *
+ * PARAMETERS:  count: input buffer size (including the '\0')
Quoted 8 lines
Quoted 3 lines

+ *
+ * RETURN VALUE: >0: number of characters used from the input buffer
+ * <= 0: failure

I would expect a return value of 0 not to indicate failure; only <0 should do that. So is this a typo or a real case where a return of 0 indicates failure?

This is a typo

Quoted 6 lines
Quoted 6 lines

+ */

kernel/autotune/akt.c +3 -0
+ssize_t store_tunable_min(struct auto_tune *tun_addr, const char *buf,
+			size_t count)
+{

<snip>

Quoted 11 lines
Quoted 8 lines

+/*
+ * FUNCTION: Set operation called by tunable_attr_store (i.e. when a
+ * string is stored into /sys/tunables/<tunable>/max).
+ *
+ * PARAMETERS: count: input buffer size (including the '\0')
+ *
+ * RETURN VALUE: >0: number of characters used from the input buffer
+ * <= 0: failure

same question.

Same answer ;-)

Quoted 2 lines

Regards,
Nadia

#11 lore raw

RFC PATCH 5/6 per namespace tunables

In reply to [email protected]

[PATCH 05/06]

This patch introduces all that is needed to process per namespace tunables.

---
 include/linux/akt.h   |   12 +++++++
 kernel/autotune/akt.c |   80 ++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 73 insertions(+), 19 deletions(-)
include/linux/akt.h +12 -0
Index: linux-2.6.20-rc4/include/linux/akt.h
===================================================================
@@ -154,6 +154,7 @@ struct auto_tune {
  */
 #define AUTO_TUNE_ENABLE  0x01
 #define TUNABLE_REGISTERED  0x02
+#define TUNABLE_IPC_NS      0x04
 
 
 /*
@@ -204,6 +205,8 @@ static inline int is_tunable_registered(
 	}
 
 
+#define DECLARE_TUNABLE(s)	struct auto_tune s;
+
 #define DEFINE_TUNABLE(s, thr, min, max, tun, chk, type)		\
 	struct auto_tune s = TUNABLE_INIT(#s, thr, min, max, tun, chk, type)
 
@@ -215,6 +218,13 @@ static inline int is_tunable_registered(
 		(s).max.abs_value.val_##type = _max;	\
 	} while (0)
 
+#define init_tunable_ipcns(ns, s, thr, min, max, tun, chk, type)	\
+	do {								\
+		DEFINE_TUNABLE(s, thr, min, max, tun, chk, type);	\
+		s.flags |= TUNABLE_IPC_NS;				\
+		ns->s = s;						\
+	} while (0)
+
 
 static inline void set_autotuning_routine(struct auto_tune *tunable,
 					auto_tune_fn fn)
@@ -269,7 +279,9 @@ extern ssize_t store_tunable_max(struct 
 #else	/* CONFIG_AKT */
 
 
+#define DECLARE_TUNABLE(s)
 #define DEFINE_TUNABLE(s, thresh, min, max, tun, chk, type)
+#define init_tunable_ipcns(ns, s, th, m, M, tun, chk, type)  do { } while (0)
 #define set_tunable_min_max(s, min, max, type)   do { } while (0)
 #define set_autotuning_routine(s, fn)            do { } while (0)
 
kernel/autotune/akt.c +61 -19

186 lines not on this page · raw message

--

#12 lore raw

Re: [RFC][PATCH 5/6] per namespace tunables

Quoted 9 lines · On Tue, 16 Jan 2007 07:15:21 +0100 [email protected] wrote:

[PATCH 05/06]

This patch introduces all that is needed to process per namespace tunables.

---
 include/linux/akt.h   |   12 +++++++
 kernel/autotune/akt.c |   80 ++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 73 insertions(+), 19 deletions(-)
Quoted 6 lines

+/*
+ * FUNCTION: This routine gets the actual auto_tune structure for the
+ * tunables that are per namespace (presently only ipc ones).
+ *
+ * RETURN VALUE: pointer to the tunable structure for the current namespace
+ */

Please use kernel-doc format for function comment blocks. (see Documentation/kernel-doc-nano-HOWTO.txt)

Quoted 7 lines
kernel/autotune/akt.c +7 -0
+static struct auto_tune *get_ns_tunable(struct auto_tune *p)
+{
+	if (p->flags & TUNABLE_IPC_NS) {
+		char *shift = (char *) p;
+		struct ipc_namespace *ns = current->nsproxy->ipc_ns;
+
+		shift = (shift - (char *) &init_ipc_ns) + (char *) ns;

kernel/autotune/akt.c ssize_t store_tunable_max(struct auto_tu · line 369

Quoted 10 lines
kernel/autotune/akt.c +8 -0
+
+		return (struct auto_tune *) shift;
+	}
+
+	return p;
+}
+
+
 EXPORT_SYMBOL_GPL(register_tunable);
 EXPORT_SYMBOL_GPL(unregister_tunable);

and put EXPORT_SYMBOL/_GPL() immediately after each function that is being exported.

---
~Randy

#13 lore raw

RFC PATCH 6/6 automatic tuning applied to some kernel components

In reply to [email protected]

[PATCH 06/06]

The following kernel components register a tunable structure and call the auto-tuning routine:
. file system
. shared memory (per namespace)
. semaphore (per namespace)
. message queues (per namespace)

---
 fs/file_table.c     |   81 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/akt.h |    1 
 include/linux/ipc.h |    6 +++
 init/main.c         |    1 
 ipc/msg.c           |   19 ++++++++++++
 ipc/sem.c           |   41 ++++++++++++++++++++++++++
 ipc/shm.c           |   74 ++++++++++++++++++++++++++++++++++++++++++++---
 7 files changed, 218 insertions(+), 5 deletions(-)
fs/file_table.c +81 -0
Index: linux-2.6.20-rc4/fs/file_table.c
===================================================================
@@ -21,6 +21,8 @@
 #include <linux/fsnotify.h>
 #include <linux/sysctl.h>
 #include <linux/percpu_counter.h>
+#include <linux/akt.h>
+#include <linux/akt_ops.h>
 
 #include <asm/atomic.h>
 
@@ -34,6 +36,71 @@ __cacheline_aligned_in_smp DEFINE_SPINLO
 
 static struct percpu_counter nr_files __cacheline_aligned_in_smp;
 
+#ifdef CONFIG_AKT
+
+static int get_nr_files(void);
+
+/********** automatic tuning **********/
+#define FILPTHRESH 80		/* threshold = 80% */
+
+/*
+ * FUNCTION:    This is the routine called to accomplish auto tuning for the
+ *              max_files tunable.
+ *
+ *              Upwards adjustment:
+ *                  Adjustment is needed if nr_files has reached
+ *                  (threshold / 100 * max_files)
+ *                  In that case, max_files is set to
+ *                  (tunable + max_files * (100 - threshold) / 100)
+ *
+ *              Downards adjustment:
+ *                   Adjustment is needed if nr_files has fallen under
+ *                   (threshold / 100 * max_files previous value)
+ *                   In that case max_files is set back to its previous value,
+ *                   i.e. to (max_files * 100 / (200 - threshold))
+ *
+ * PARAMETERS:  cmd: controls the adjustment direction (up / down)
+ *              params: pointer to the registered tunable structure
+ *
+ * EXECUTION ENVIRONMENT: This routine should be called with the
+ *                        params->tunable_lck lock held
+ *
+ * RETURN VALUE: 1 if tunable has been adjusted
+ *               0 else
+ */
+static inline int maxfiles_auto_tuning(int cmd, struct auto_tune *params)
+{
+	int thr = params->threshold;
+	int min = params->min.value.val_int;
+	int max = params->max.value.val_int;
+	int tun = files_stat.max_files;
+
+	if (cmd == AKT_UP) {
+		if (get_nr_files() >= tun * thr / 100 && tun < max) {
+			int new = tun * (200 - thr) / 100;
+
+			files_stat.max_files = min(max, new);
+			return 1;
+		} else
+			return 0;
+	}
+
+	if (get_nr_files() < tun * thr / (200 - thr) && tun > min) {
+		int new = tun * 100 / (200 - thr);
+
+		files_stat.max_files = max(min, new);
+		return 1;
+	} else
+		return 0;
+}
+
+#endif /* CONFIG_AKT */
+
+/* The maximum value will be known later on */
+DEFINE_TUNABLE(maxfiles_akt, FILPTHRESH, 0, 0, &files_stat.max_files,
+		&nr_files, int);
+
+
 static inline void file_free_rcu(struct rcu_head *head)
 {
 	struct file *f =  container_of(head, struct file, f_u.fu_rcuhead);
@@ -44,6 +111,8 @@ static inline void file_free(struct file
 {
 	percpu_counter_dec(&nr_files);
 	call_rcu(&f->f_u.fu_rcuhead, file_free_rcu);
+
+	activate_auto_tuning(AKT_DOWN, &maxfiles_akt);
 }
 
 /*
@@ -91,6 +160,8 @@ struct file *get_empty_filp(void)
 	static int old_max;
 	struct file * f;
 
+	activate_auto_tuning(AKT_UP, &maxfiles_akt);
+
 	/*
 	 * Privileged users can go above max_files
 	 */
@@ -299,6 +370,16 @@ void __init files_init(unsigned long mem
 	files_stat.max_files = n; 
 	if (files_stat.max_files < NR_FILE)
 		files_stat.max_files = NR_FILE;
+
+	set_tunable_min_max(maxfiles_akt, n, n * 2, int);
+	set_autotuning_routine(&maxfiles_akt, maxfiles_auto_tuning);
+
 	files_defer_init();
 	percpu_counter_init(&nr_files, 0);
 } 
+
+void __init files_late_init(void)
+{
+	if (register_tunable(&maxfiles_akt))
+		printk(KERN_WARNING "Failed registering tunable file-max\n");
+}
include/linux/akt.h +1 -0
Index: linux-2.6.20-rc4/include/linux/akt.h
===================================================================
@@ -295,5 +295,6 @@ static inline void init_auto_tuning(void
 #endif	/* CONFIG_AKT */
 
 extern void fork_late_init(void);
+extern void files_late_init(void);
 
 #endif /* AKT_H */
init/main.c +1 -0
Index: linux-2.6.20-rc4/init/main.c
===================================================================
@@ -616,6 +616,7 @@ asmlinkage void __init start_kernel(void
 	page_writeback_init();
 	init_auto_tuning();
 	fork_late_init();
+	files_late_init();
 #ifdef CONFIG_PROC_FS
 	proc_root_init();
 #endif
ipc/msg.c +19 -0
Index: linux-2.6.20-rc4/ipc/msg.c
===================================================================
@@ -36,6 +36,8 @@
 #include <linux/seq_file.h>
 #include <linux/mutex.h>
 #include <linux/nsproxy.h>
+#include <linux/akt.h>
+#include <linux/akt_ops.h>
 
 #include <asm/current.h>
 #include <asm/uaccess.h>
@@ -94,6 +96,11 @@ static void __ipc_init __msg_init_ns(str
 	ns->msg_ctlmnb = MSGMNB;
 	ns->msg_ctlmni = MSGMNI;
 	ipc_init_ids(ids, ns->msg_ctlmni);
+
+#define MSGTHRESH 80
+
+	init_tunable_ipcns(ns, msgmni_akt, MSGTHRESH, MSGMNI, IPCMNI,
+		&ns->msg_ctlmni, &ids->in_use, int);
 }
 
 #ifdef CONFIG_IPC_NS
@@ -133,6 +140,10 @@ void msg_exit_ns(struct ipc_namespace *n
 void __init msg_init(void)
 {
 	__msg_init_ns(&init_ipc_ns, &init_msg_ids);
+
+	if (register_tunable(&init_ipc_ns.msgmni_akt))
+		printk(KERN_WARNING " Failed registering tunable msgmni\n");
+
 	ipc_init_proc_interface("sysvipc/msg",
 				"       key      msqid perms      cbytes       qnum lspid lrpid   uid   gid  cuid  cgid      stime      rtime      ctime\n",
 				IPC_MSG_IDS, sysvipc_msg_proc_show);
@@ -262,6 +273,8 @@ asmlinkage long sys_msgget(key_t key, in
 
 	ns = current->nsproxy->ipc_ns;
 	
+	activate_auto_tuning(AKT_UP, &ns->msgmni_akt);
+
 	mutex_lock(&msg_ids(ns).mutex);
 	if (key == IPC_PRIVATE) 
 		ret = newque(ns, key, msgflg);
@@ -391,6 +404,7 @@ asmlinkage long sys_msgctl(int msqid, in
 	struct msg_queue *msq;
 	int err, version;
 	struct ipc_namespace *ns;
+	int destroyed = 0;
 
 	if (msqid < 0 || cmd < 0)
 		return -EINVAL;
@@ -555,11 +569,16 @@ asmlinkage long sys_msgctl(int msqid, in
 	}
 	case IPC_RMID:
 		freeque(ns, msq, msqid);
+		destroyed = 1;
 		break;
 	}
 	err = 0;
 out_up:
 	mutex_unlock(&msg_ids(ns).mutex);
+
+	if (destroyed)
+		activate_auto_tuning(AKT_DOWN, &ns->msgmni_akt);
+
 	return err;
 out_unlock_up:
 	msg_unlock(msq);
ipc/shm.c +69 -5

138 lines not on this page · raw message

ipc/sem.c +41 -0

76 lines not on this page · raw message

include/linux/ipc.h +6 -0
Index: linux-2.6.20-rc4/include/linux/ipc.h
===================================================================
@@ -52,6 +52,7 @@ struct ipc_perm
 #ifdef __KERNEL__
 
 #include <linux/kref.h>
+#include <linux/akt.h>
 
 #define IPCMNI 32768  /* <= MAX_INT limit for ipc arrays (including sysctl changes) */
 
@@ -77,15 +78,20 @@ struct ipc_namespace {
 
 	int		sem_ctls[4];
 	int		used_sems;
+	DECLARE_TUNABLE(semmni_akt);
+	DECLARE_TUNABLE(semmns_akt);
 
 	int		msg_ctlmax;
 	int		msg_ctlmnb;
 	int		msg_ctlmni;
+	DECLARE_TUNABLE(msgmni_akt);
 
 	size_t		shm_ctlmax;
 	size_t		shm_ctlall;
 	int		shm_ctlmni;
 	int		shm_tot;
+	DECLARE_TUNABLE(shmmni_akt);
+	DECLARE_TUNABLE(shmall_akt);
 };
 
 extern struct ipc_namespace init_ipc_ns;

--

#14 lore raw

Re: [RFC][PATCH 6/6] automatic tuning applied to some kernel components

Quoted 7 lines · On Tue, 16 Jan 2007 07:15:22 +0100 [email protected] wrote:

The following kernel components register a tunable structure and call the auto-tuning routine:
. file system
. shared memory (per namespace)
. semaphore (per namespace)
. message queues (per namespace)

This is the part of the patch series which really matters, and I just don't understand it :(

Why do we want to autotune these things? What problem is this patch series solving? Please describe this part of the work much, much more completely, so we can understand the need to add such a large amount of code to the kernel.

It seems strange that the whole feature is Kconfigurable. Please also explain the thinking behind that.

I suspect the patches would be much simpler if you simply required that all these new tunables be of type `long'. About seven eighths of the code would go away. As would most of those eye-popping macros.

#15 lore raw

Re: [RFC][PATCH 6/6] automatic tuning applied to some kernel components

Quoted 9 lines · Andrew Morton
Quoted 7 lines · On Tue, 16 Jan 2007 07:15:22 +0100 [email protected] wrote:

The following kernel components register a tunable structure and call the auto-tuning routine:
. file system
. shared memory (per namespace)
. semaphore (per namespace)
. message queues (per namespace)

Quoted 7 lines

This is the part of the patch series which really matters, and I just don't understand it :(

Why do we want to autotune these things? What problem is this patch series solving? Please describe this part of the work much, much more completely, so we can understand the need to add such a large amount of code to the kernel.

1) why these tunables?
The ipc tunables have been selected as "guinea-pig" tunables for the AKT framework because they are likely to be often used in data bases. This applies to file-max too. Now, if the framework itself is accepted, the set of impacted tunables can easily be enhanced.

2) why autotuning:
There are at least 3 cases where it can be useful
. for workloads that are known to need a big amount of a given resource type (say shared memories), but we don't know what the maximum amount needed will be . to solve the case of multiple applications running on a single system, and that need the same tunable to be adjusted to feet their needs . to make a system correctly react to eventual peak loads for a given resource usage, i.e. make it tune up *and down* as needed.

In all these cases, the akt framework will enable the kernel to adapt to increasing / decreasing resource consumption:
1) avoid allocating "a priori" a big amount of memory that will be used only in extreme cases. This is the effect of doing an "echo <huge_value> > /proc/sys/kernel/shmmni"
2) the system will come back to the default values as soon as the peak load is over.

Quoted 3 lines

It seems strange that the whole feature is Kconfigurable. Please also explain the thinking behind that.

We wanted to make it configurable because it adds some overhead in terms of
1) generated kernel size
2) instructions added to the resource creation / removal code paths even if auto-tuning is not activated for th corresponding tunable -> performance impact.

Quoted 5 lines

I suspect the patches would be much simpler if you simply required that all these new tunables be of type `long'. About seven eighths of the code would go away. As would most of those eye-popping macros.

Yes, agree with you: the idea here was to make the framework more generic. But I can change that.

Regards,
Nadia

#16 lore raw

Re: [RFC][PATCH 6/6] automatic tuning applied to some kernel components

Quoted 11 lines · Nadia Derbey

2) why autotuning:
There are at least 3 cases where it can be useful
. for workloads that are known to need a big amount of a given resource type (say shared memories), but we don't know what the maximum amount needed will be . to solve the case of multiple applications running on a single system, and that need the same tunable to be adjusted to feet their needs
. to make a system correctly react to eventual peak loads for a given resource usage, i.e. make it tune up *and down* as needed.

Quoted 8 lines

In all these cases, the akt framework will enable the kernel to adapt to increasing / decreasing resource consumption:
1) avoid allocating "a priori" a big amount of memory that will be used only in extreme cases. This is the effect of doing an "echo <huge_value>

Quoted 1 line

/proc/sys/kernel/shmmni"

2) the system will come back to the default values as soon as the peak load is over.

At least the ipc ones are supposed to be DOS limits not behavior modifiers. I do admit from looking at the code that there are some consequences of increasing things like shmmni. However I think we would be better off with better data structures and implementations that remove these consequences than this autotuning of denial-of-service limits.

i.e. I think you are treating the symptom not the problem.

Does this make sense?

Eric

#17 lore raw

Re: [RFC][PATCH 6/6] automatic tuning applied to some kernel components

Quoted 24 lines · Eric W. Biederman
Quoted 15 lines · Nadia Derbey

2) why autotuning:
There are at least 3 cases where it can be useful
. for workloads that are known to need a big amount of a given resource type (say shared memories), but we don't know what the maximum amount needed will be . to solve the case of multiple applications running on a single system, and that need the same tunable to be adjusted to feet their needs
. to make a system correctly react to eventual peak loads for a given resource usage, i.e. make it tune up *and down* as needed.

In all these cases, the akt framework will enable the kernel to adapt to increasing / decreasing resource consumption:
1) avoid allocating "a priori" a big amount of memory that will be used only in extreme cases. This is the effect of doing an "echo <huge_value>

Quoted 4 lines
Quoted 1 line

/proc/sys/kernel/shmmni"

2) the system will come back to the default values as soon as the peak load is over.

Quoted 7 lines

At least the ipc ones are supposed to be DOS limits not behavior modifiers. I do admit from looking at the code that there are some consequences of increasing things like shmmni. However I think we would be better off with better data structures and implementations that remove these consequences than this autotuning of denial-of-service limits.

I do not fully agree with you:
It is true that some ipc tunables play the role of DoS limits.
But IMHO the *mni ones (semmni, msgmni, shmmni) are used by the ipc subsystem to adapt its data structures sizes to what is being asked for through the tunable value. I think this is how they manage to take into account a new tunable value without a need for rebooting the system: reallocate some more memory on demand.

Now, what the akt framework does, is that it takes advantage of this concept of "on demand memory allocation" to replace a user (or a daemon) that would periodically check its ipcs consumptions and manually adjust the ipcs tunables: Doing this from the user space would imply a latency that makes it difficult to react fast enough to resources running out.

Now, talking about DoS limits, akt implements them in a sense: each tunable managed by akt has 3 attributes exported to sysfs:
. autotune: enable / disable auto-tuning
. min: min value the tunable can ever reach
. max: max value the tunable can ever reach

Enabling a sysadmin to play with these min and max values makes it possible to refine the dynamic adjustment, and avoid that the tunable reaches really huge values.

Regards,
Nadia

#18 lore raw

Re: [RFC][PATCH 6/6] automatic tuning applied to some kernel components

Quoted 6 lines · Nadia Derbey

I do not fully agree with you:
It is true that some ipc tunables play the role of DoS limits.
But IMHO the *mni ones (semmni, msgmni, shmmni) are used by the ipc subsystem to adapt its data structures sizes to what is being asked for through the tunable value. I think this is how they manage to take into account a new tunable value without a need for rebooting the system: reallocate some more memory on demand.

Yes, they do. However if you are constantly having to play with shmmni or the others that is the problem and the array should be replaced with a hash table or some form of radix tree, so it changes it's size to fit the need. Once that is done, shmmni does become a simple DOS limit.

So what I'm asking is please fix the problem at the source don't plaster over it.

Quoted 5 lines

Now, what the akt framework does, is that it takes advantage of this concept of "on demand memory allocation" to replace a user (or a daemon) that would periodically check its ipcs consumptions and manually adjust the ipcs tunables:
Doing this from the user space would imply a latency that makes it difficult to react fast enough to resources running out.

There may be some sense in this but you haven't found something that inherently needs tuning. You have found something that has a poor data structure, and can more easily be fixed by simply fixing the data structure.

I'm guessing that we have a disconnect somewhere with kernel developers thinking shm is an old legacy api and doing minimal maintenance, expecting serious users to use tmpfs or hugetlbfs and users not used to the old stuff using the SYSV apis.

If we have serious users it makes sense to fix these things properly, in a backwards compatible way, so existing users and applications don't need to be changed.

Quoted 9 lines

Now, talking about DoS limits, akt implements them in a sense: each tunable managed by akt has 3 attributes exported to sysfs:
. autotune: enable / disable auto-tuning
. min: min value the tunable can ever reach
. max: max value the tunable can ever reach

Enabling a sysadmin to play with these min and max values makes it possible to refine the dynamic adjustment, and avoid that the tunable reaches really huge values.

This just shifts the location where you have your DOS limit and could be done transparently under the covers with shmmni being the maximum. If we can't get users to switch to something that doesn't need tuning that has been available for years, I doubt even more user tunables that tune the tunables will make the situation any better. I suspect your changes would just confuse the landscape even more and give us more weird legacy cases to support that we can never get rid of?

Eric

#19 lore raw

Re: [RFC][PATCH 6/6] automatic tuning applied to some kernel components

Quoted 27 lines · Eric W. Biederman
Quoted 6 lines · Nadia Derbey

I do not fully agree with you:
It is true that some ipc tunables play the role of DoS limits.
But IMHO the *mni ones (semmni, msgmni, shmmni) are used by the ipc subsystem to adapt its data structures sizes to what is being asked for through the tunable value. I think this is how they manage to take into account a new tunable value without a need for rebooting the system: reallocate some more memory on demand.

Yes, they do. However if you are constantly having to play with shmmni or the others that is the problem and the array should be replaced with a hash table or some form of radix tree, so it changes it's size to fit the need. Once that is done, shmmni does become a simple DOS limit.

So what I'm asking is please fix the problem at the source don't plaster over it.

Quoted 5 lines

Now, what the akt framework does, is that it takes advantage of this concept of "on demand memory allocation" to replace a user (or a daemon) that would periodically check its ipcs consumptions and manually adjust the ipcs tunables:
Doing this from the user space would imply a latency that makes it difficult to react fast enough to resources running out.

Quoted 3 lines

There may be some sense in this but you haven't found something that inherently needs tuning. You have found something that has a poor data structure, and can more easily be fixed by simply fixing the data structure.

So, should I understand from this that automatic tuning and the AKT framework itself would make sense, given that I find the rigth tunables it should be applied to? Actually, dont' know if you had the opportunity to read all the patches, but there are 2 other tunables AKT is proposed to be applied to:
. max_threads, the tunable limit on nr_threads
. max_files, the tunable limit on nr_files

Regards,
Nadia

#20 lore raw

Re: [RFC][PATCH 6/6] automatic tuning applied to some kernel components

Quoted 3 lines · Nadia Derbey

So, should I understand from this that automatic tuning and the AKT framework itself would make sense, given that I find the rigth tunables it should be applied to?

Sort of. The concept of things tuning themselves automatically makes a lot of sense.

I'm not at all certain about tunables being exported just to be hidden again. Ideally you don't even want the fact that these things are varying visible to the user.

So I think that if you can find a good example that cannot be solved better another way, you can build a case for your framework. Currently I am doubt you can find such a case.

Quoted 4 lines

Actually, dont' know if you had the opportunity to read all the patches, but there are 2 other tunables AKT is proposed to be applied to:
. max_threads, the tunable limit on nr_threads
. max_files, the tunable limit on nr_files

At a quick glance max_threads and max_files appear even more to be DOS limits and not tunables and even less applicable to needing any tuning at all. My gut feel is at worst these values may need a little better boot time defaults but otherwise they the should be good.

Eric

#21 lore raw

Re: [RFC][PATCH 6/6] automatic tuning applied to some kernel components

Quoted 26 lines · Eric W. Biederman
Quoted 3 lines · Nadia Derbey

So, should I understand from this that automatic tuning and the AKT framework itself would make sense, given that I find the rigth tunables it should be applied to?

Sort of. The concept of things tuning themselves automatically makes a lot of sense.

I'm not at all certain about tunables being exported just to be hidden again. Ideally you don't even want the fact that these things are varying visible to the user.

So I think that if you can find a good example that cannot be solved better another way, you can build a case for your framework. Currently I am doubt you can find such a case.

Quoted 4 lines

Actually, dont' know if you had the opportunity to read all the patches, but there are 2 other tunables AKT is proposed to be applied to:
. max_threads, the tunable limit on nr_threads
. max_files, the tunable limit on nr_files

Quoted 5 lines

At a quick glance max_threads and max_files appear even more to be DOS limits and not tunables and even less applicable to needing any tuning at all. My gut feel is at worst these values may need a little better boot time defaults but otherwise they the should be good.

But, what do you do with Oracle that's asking maxfiles to be set to 0x10000, while the default value might be enough for a system that's not running Oracle.
I'm afraid that giving boot time values to the max_* tunables we will loose all the benefits from /proc (or /sys): it is impossible to anticipate what an OS will be used for. So allowing such things to be changed without having to reboot the machine is in my mind quite a powerful feature we should keep taking adavntage of.

Regards,
Nadia

#22 lore raw

Re: [RFC][PATCH 6/6] automatic tuning applied to some kernel components

Quoted 7 lines · Nadia Derbey

But, what do you do with Oracle that's asking maxfiles to be set to 0x10000, while the default value might be enough for a system that's not running Oracle. I'm afraid that giving boot time values to the max_* tunables we will loose all the benefits from /proc (or /sys): it is impossible to anticipate what an OS will be used for. So allowing such things to be changed without having to reboot the machine is in my mind quite a powerful feature we should keep taking adavntage of.

I'm not saying remove user spaces' ability to set the denial-of-service limits. I'm saying if they need to be frequently changed we need to update the default so they are higher by default.

There really is no cost in moving those values up and down it is just an arbitrary integer used in comparisons. But if we can make a good guess that still catches runaway programs before they kill the machine but also allows more programs to work out of the box we are in better shape.

Eric

#23 lore raw

Re: [RFC][PATCH 6/6] automatic tuning applied to some kernel components

Quoted 16 lines · Eric W. Biederman
Quoted 7 lines · Nadia Derbey

But, what do you do with Oracle that's asking maxfiles to be set to 0x10000, while the default value might be enough for a system that's not running Oracle. I'm afraid that giving boot time values to the max_* tunables we will loose all the benefits from /proc (or /sys): it is impossible to anticipate what an OS will be used for. So allowing such things to be changed without having to reboot the machine is in my mind quite a powerful feature we should keep taking adavntage of.

I'm not saying remove user spaces' ability to set the denial-of-service limits. I'm saying if they need to be frequently changed we need to update the default so they are higher by default.

Quoted 6 lines

There really is no cost in moving those values up and down it is just an arbitrary integer used in comparisons. But if we can make a good guess that still catches runaway programs before they kill the machine but also allows more programs to work out of the box we are in better shape.

OK, happy to see we are on the same wavelength (and sorry for misunderstanding what you were saying ;-) )

Regards,
Nadia