Currently there is no protection from the root user to use up all of memory for trace buffers. If the root user allocates too many entries, the OOM killer might start kill off all tasks. This patch adds an algorith to check the following condition: pages_requested > (freeable_memory + current_trace_buffer_pages) / 4 If the above is met then the allocation fails. The above prevents more than 1/4th of freeable memory from being used by trace buffers. To determine the freeable_memory, I made determine_dirtyable_memory in mm/page-writeback.c global. Special thanks goes to Peter Zijlstra for suggesting the above calculation. Signed-off-by: Steven Rostedt <srostedt@redhat.com> --- include/linux/writeback.h | 2 ++ kernel/trace/trace.c | 38 ++++++++++++++++++++++++++++++++++++++ mm/page-writeback.c | 10 +++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) Index: linux-sched-devel.git/include/linux/writeback.h =================================================================== --- linux-sched-devel.git.orig/include/linux/writeback.h 2008-04-18 15:47:21.000000000 -0400 +++ linux-sched-devel.git/include/linux/writeback.h 2008-04-18 15:53:08.000000000 -0400 @@ -105,6 +105,8 @@ extern int vm_highmem_is_dirtyable; extern int block_dump; extern int laptop_mode; +extern unsigned long determine_dirtyable_memory(void); + extern int dirty_ratio_handler(struct ctl_table *table, int write, struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos); Index: linux-sched-devel.git/kernel/trace/trace.c =================================================================== --- linux-sched-devel.git.orig/kernel/trace/trace.c 2008-04-18 15:50:47.000000000 -0400 +++ linux-sched-devel.git/kernel/trace/trace.c 2008-04-18 15:53:08.000000000 -0400 @@ -27,6 +27,7 @@ #include <linux/poll.h> #include <linux/gfp.h> #include <linux/fs.h> +#include <linux/writeback.h> #include <linux/stacktrace.h> @@ -51,6 +52,8 @@ static int ...
On Fri, 18 Apr 2008 16:05:42 -0400 tpyo --
Damn! You don't miss a thing. Are you sure your name isn't Monk? New patch coming. Thanks, -- Steve --
We could do this all day at this level of detail :) --
Currently there is no protection from the root user to use up all of memory for trace buffers. If the root user allocates too many entries, the OOM killer might start killing off all tasks. This patch adds an algorithm to check the following condition: pages_requested > (freeable_memory + current_trace_buffer_pages) / 4 If the above is met then the allocation fails. The above prevents more than 1/4th of freeable memory from being used by trace buffers. To determine the freeable_memory, I made determine_dirtyable_memory in mm/page-writeback.c global. Special thanks goes to Peter Zijlstra for suggesting the above calculation. Signed-off-by: Steven Rostedt <srostedt@redhat.com> --- include/linux/writeback.h | 2 ++ kernel/trace/trace.c | 38 ++++++++++++++++++++++++++++++++++++++ mm/page-writeback.c | 10 +++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) Index: linux-sched-devel.git/include/linux/writeback.h =================================================================== --- linux-sched-devel.git.orig/include/linux/writeback.h 2008-04-18 23:01:57.000000000 -0400 +++ linux-sched-devel.git/include/linux/writeback.h 2008-04-18 23:06:43.000000000 -0400 @@ -105,6 +105,8 @@ extern int vm_highmem_is_dirtyable; extern int block_dump; extern int laptop_mode; +extern unsigned long determine_dirtyable_memory(void); + extern int dirty_ratio_handler(struct ctl_table *table, int write, struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos); Index: linux-sched-devel.git/kernel/trace/trace.c =================================================================== --- linux-sched-devel.git.orig/kernel/trace/trace.c 2008-04-18 23:06:40.000000000 -0400 +++ linux-sched-devel.git/kernel/trace/trace.c 2008-04-18 23:06:43.000000000 -0400 @@ -27,6 +27,7 @@ #include <linux/poll.h> #include <linux/gfp.h> #include <linux/fs.h> +#include <linux/writeback.h> #include <linux/stacktrace.h> @@ -51,6 +52,8 @@ static int ...
