ulimit RSS enforcement for 2.4.0-test13-pre4
Subsystems (11)
PATCH 1/1 ulimit RSS enforcement for 2.4.0-test13-pre4
Hi Linus, Alan, Stephen,
the patch below implements trivial RSS ulimit enforcement for the 2.4 kernel.
The hard limit (rlim_max) is enforced as a true hard limit, both at page fault time and again from kswapd. The soft limit is "enforced" by simply scanning and swapping the process more agressively from kswapd ...
This behaviour is "comperable" to disk quotas and allows the sysadmin to set the limits such that the user can have the memory if it's available but that the processes will be swapped out first if the memory is needed.
Due to the fact that swapout IO is moved from try_to_swap_out to page_launder, the enforcement of even the hard limit doesn't give *ANY* disk IO at all ... the "extra" pages will just sit in the inactive_dirty list doing nothing; this makes RSS ulimit enforcement possible without the performance problems we would have had some time ago.
Since this patch is both trivial and has a very often requested feature, would you consider adding this to the next pre-patch ?
regards,
Rik
--
Hollywood goes for world dumbination,
Trailer at 11. http://www.surriel.com/
http://www.conectiva.com/ http://distro.conectiva.com.br/
mm/filemap.c renamed from mm/filemap.c.orig +1 -1
@@ -1900,7 +1900,7 @@/* Make sure this doesn't exceed the process's max rss. */ error = -EIO ; - rlim_rss = current->rlim ? current->rlim[RLIMIT_RSS ].rlim_cur : + rlim_rss = current->rlim ? (current->rlim[RLIMIT_RSS ].rlim_cur >>PAGE_SHIFT ) :LONG_MAX ;/* default: see resource.h */ if ((vma->vm_mm->rss + (end - start)) > rlim_rss)return error;
mm/memory.c renamed from mm/memory.c.orig +6 -0
@@ -1198,6 +1198,12 @@ pgd =pgd_offset (mm, address); pmd =pmd_alloc (pgd, address); +if (mm->rss >= (current->rlim[RLIMIT_RSS ].rlim_max >>PAGE_SHIFT )) { +lock_kernel (); +enforce_rss_limit (mm,GFP_HIGHUSER ); +unlock_kernel (); + } +if (pmd) {pte_t * pte =pte_alloc (pmd, address);if (pte)
mm/vmscan.c renamed from mm/vmscan.c.orig +73 -10
138 lines not on this page · raw message
include/linux/mm.h renamed from include/linux/mm.h.orig +1 -0
@@ -463,6 +463,7 @@#else #define __GFP_HIGHMEM 0x0/* noop */ #endif +#define __GFP_RSS_LIMIT 0x20#define GFP_BUFFER (__GFP_HIGH | __GFP_WAIT)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
PATCH 1/1 maintain a dirty RSS count for 2.4.0-test13-pre7
Rik, Linus, all.
The following patch is intended to compliment the work done with the max RSS limit patch. For now all I do is track the number of dirty pages that are in a processes working set. The code compiles but hasn't _yet_ been run.
The idea is simple. We manually handle the transition from clean mapped page to dirty page so we can always get the dirty counts. There were only two places in the kernel that needed to be changed to get this to work.
For the rest I just added code to increment dirty_rss in appropriate places.
I'm not quite certain how we want to take advantage of this code. But in situations where we are heavily swapping but not yet thrashing knowing which processes have dirty pages in them should be a help.
I haven't evaluated 2.4's swapping behavior, but I know classically not being to limit the number of dirty pages in the system has been an Achilles heal of our swap code.
Comments?
Eric
arch/ia64/ia32/binfmt_elf32.c +1 -0
@@ -201,6 +201,7 @@for (i =0 ; i <MAX_ARG_PAGES ; i++) {if (bprm->page[i]) { current->mm->rss++; + current->mm->dirty_rss++;put_dirty_page (current,bprm->page[i],stack_base); } stack_base +=PAGE_SIZE ;
arch/mips/kernel/irixelf.c +1 -0
@@ -690,6 +690,7 @@* change some of these later. */ current->mm->rss =0 ; + current->mm->dirty_rss =0 ;setup_arg_pages (bprm); current->mm->start_stack = bprm->p;
arch/mips/mm/umap.c +2 -0
@@ -121,6 +121,8 @@__free_page (ptpage);if (current->mm->rss <=0 )return ; +if (pte_dirty (page)) + current->mm->rss_dirty--; current->mm->rss--;return ; }
arch/sparc64/kernel/binfmt_aout32.c +1 -0
@@ -239,6 +239,7 @@ (current->mm->start_brk =N_BSSADDR (ex)); current->mm->rss =0 ; + current->mm->dirty_rss =0 ; current->mm->mmap =NULL ;compute_creds (bprm); current->flags &= ~PF_FORKNOEXEC ;
Binary files linux-2.4.0-test13-pre7/drivers/net/hamradio/soundmodem/gentbl and linux-2.4.0-test13-pre7.rss-dirty-count/drivers/net/hamradio/soundmodem/gentbl differ
fs/binfmt_aout.c +1 -0
@@ -302,6 +302,7 @@ (current->mm->start_brk =N_BSSADDR (ex)); current->mm->rss =0 ; + current->mm->dirty_rss =0 ; current->mm->mmap =NULL ;compute_creds (bprm); current->flags &= ~PF_FORKNOEXEC ;
fs/binfmt_elf.c +1 -0
@@ -589,6 +589,7 @@/* Do this so that we can load the interpreter, if need be. We will change some of these later */ current->mm->rss =0 ; + current->mm->dirty_rss =0 ;setup_arg_pages (bprm);/* XXX: check error */ current->mm->start_stack = bprm->p;
fs/exec.c +1 -0
@@ -322,6 +322,7 @@if (page) { bprm->page[i] =NULL ; current->mm->rss++; + current->mm->dirty_rss++;put_dirty_page (current,page,stack_base); } stack_base +=PAGE_SIZE ;
fs/proc/array.c +4 -2
@@ -206,12 +206,14 @@"VmData:\t%8lu kB\n" "VmStk:\t%8lu kB\n" "VmExe:\t%8lu kB\n" -"VmLib:\t%8lu kB\n" , +"VmLib:\t%8lu kB\n" +"VmDirtyRSS:\t%8lu Kb\n" , mm->total_vm << (PAGE_SHIFT -10 ), mm->locked_vm << (PAGE_SHIFT -10 ), mm->rss << (PAGE_SHIFT -10 ), data - stack, stack, - exec - lib, lib); + exec - lib, lib, + mm->dirty_rss << (PAGE_SHIFT-10));up (&mm->mmap_sem);return buffer; }
include/linux/sched.h +1 -1
@@ -212,7 +212,7 @@unsigned long start_code, end_code, start_data, end_data;unsigned long start_brk, brk, start_stack;unsigned long arg_start, arg_end, env_start, env_end; -unsigned long rss, total_vm, locked_vm; +unsigned long rss, dirty_rss, total_vm, locked_vm;unsigned long def_flags;unsigned long cpu_vm_mask;unsigned long swap_cnt;/* number of pages to swap on next pass */
mm/memory.c +30 -26
156 lines not on this page · raw message
mm/mmap.c +1 -0
@@ -881,6 +881,7 @@ mm->mmap = mm->mmap_avl = mm->mmap_cache =NULL ;spin_unlock (&mm->page_table_lock); mm->rss =0 ; + mm->dirty_rss =0 ; mm->total_vm =0 ; mm->locked_vm =0 ;while (mpnt) {
mm/vmscan.c +4 -1
@@ -90,8 +90,10 @@*/ if (PageSwapCache (page)) { entry.val = page->index; -if (pte_dirty (pte)) +if (pte_dirty (pte)) { + mm->dirty_rss--;set_page_dirty (page); + } set_swap_pte:swap_duplicate (entry);set_pte (page_table,swp_entry_to_pte (entry));
@@ -130,6 +132,7 @@*/ if (page->mapping) {set_page_dirty (page); + mm->dirty_rss--; goto drop_pte; }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/