From: Christoph Lameter In the 2.6.11 development cycle function calls have been added to lots of hot vm paths to do accounting. I think these should not go into the final 2.6.1 release because these statistics can be collected in a different way that does not require the updating of counters from frequently used vm code paths and is consistent with the methods use elsewhere in the kernel to obtain statistics. These function calls are acct_update_integrals -> Account for processes based on stime changes update_mem_hiwater -> takes rss and total_vm hiwater marks. acct_update_integrals is only useful to call if stime changes otherwise it will simply return. It is therefore best to relocate the function call to acct_update_integral into the function that updates stime which is account_system_time and remove it from the vm code paths. update_mem_hiwater finds the rss hiwater mark. We call that from timer context as well. This means that processes' high-water marks are now sampled statistically, at timer-interrupt time rather than deterministically. This may or may not be a problem.. This means that the rss limit is not always updated if rss is increased and thus not as accurate. But the benefit is that the rss checks do no pollute the vm paths and that it is consistent with the rss limit check. The following patch removes acct_update_integrals and update_mem_hiwater from the hot vm paths. Signed-off-by: Christoph Lameter From: Jay Lan The new "move-accounting-function-calls-out-of-critical-vm-code-paths" patch in 2.6.11-rc3-mm2 was different from the code i tested. In particular, it mistakenly dropped the accounting routine calls in fs/exec.c. The calls in do_execve() are needed to properly initialize accounting fields. Specifically, the tsk->acct_stimexpd needs to be initialized to tsk->stime. I have discussed this with Christoph Lameter and he gave me full blessings to bring the calls back. Signed-off-by: Jay Lan Signed-off-by: Andrew Morton --- 25-akpm/fs/exec.c | 4 ++-- 25-akpm/include/linux/acct.h | 4 ++-- 25-akpm/include/linux/mm.h | 2 +- 25-akpm/kernel/acct.c | 4 +--- 25-akpm/kernel/exit.c | 4 ++-- 25-akpm/kernel/sched.c | 5 +++++ 25-akpm/mm/memory.c | 19 +++---------------- 25-akpm/mm/mmap.c | 7 ------- 25-akpm/mm/mremap.c | 6 ------ 25-akpm/mm/nommu.c | 4 +--- 25-akpm/mm/rmap.c | 3 --- 25-akpm/mm/swapfile.c | 3 --- 12 files changed, 17 insertions(+), 48 deletions(-) diff -puN fs/exec.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch fs/exec.c --- 25/fs/exec.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch 2005-02-24 23:12:59.000000000 -0800 +++ 25-akpm/fs/exec.c 2005-02-24 23:12:59.000000000 -0800 @@ -1193,8 +1193,8 @@ int do_execve(char * filename, /* execve success */ security_bprm_free(bprm); - acct_update_integrals(); - update_mem_hiwater(); + acct_update_integrals(current); + update_mem_hiwater(current); kfree(bprm); return retval; } diff -puN include/linux/acct.h~move-accounting-function-calls-out-of-critical-vm-code-pathspatch include/linux/acct.h --- 25/include/linux/acct.h~move-accounting-function-calls-out-of-critical-vm-code-pathspatch 2005-02-24 23:12:59.000000000 -0800 +++ 25-akpm/include/linux/acct.h 2005-02-24 23:12:59.000000000 -0800 @@ -120,12 +120,12 @@ struct acct_v3 struct super_block; extern void acct_auto_close(struct super_block *sb); extern void acct_process(long exitcode); -extern void acct_update_integrals(void); +extern void acct_update_integrals(struct task_struct *tsk); extern void acct_clear_integrals(struct task_struct *tsk); #else #define acct_auto_close(x) do { } while (0) #define acct_process(x) do { } while (0) -#define acct_update_integrals() do { } while (0) +#define acct_update_integrals(x) do { } while (0) #define acct_clear_integrals(task) do { } while (0) #endif diff -puN include/linux/mm.h~move-accounting-function-calls-out-of-critical-vm-code-pathspatch include/linux/mm.h --- 25/include/linux/mm.h~move-accounting-function-calls-out-of-critical-vm-code-pathspatch 2005-02-24 23:12:59.000000000 -0800 +++ 25-akpm/include/linux/mm.h 2005-02-24 23:12:59.000000000 -0800 @@ -838,7 +838,7 @@ static inline void vm_stat_unaccount(str } /* update per process rss and vm hiwater data */ -extern void update_mem_hiwater(void); +extern void update_mem_hiwater(struct task_struct *tsk); #ifndef CONFIG_DEBUG_PAGEALLOC static inline void diff -puN kernel/acct.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch kernel/acct.c --- 25/kernel/acct.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch 2005-02-24 23:12:59.000000000 -0800 +++ 25-akpm/kernel/acct.c 2005-02-24 23:12:59.000000000 -0800 @@ -534,10 +534,8 @@ void acct_process(long exitcode) * acct_update_integrals * - update mm integral fields in task_struct */ -void acct_update_integrals(void) +void acct_update_integrals(struct task_struct *tsk) { - struct task_struct *tsk = current; - if (likely(tsk->mm)) { long delta = tsk->stime - tsk->acct_stimexpd; diff -puN kernel/exit.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch kernel/exit.c --- 25/kernel/exit.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch 2005-02-24 23:12:59.000000000 -0800 +++ 25-akpm/kernel/exit.c 2005-02-24 23:12:59.000000000 -0800 @@ -806,8 +806,8 @@ fastcall NORET_TYPE void do_exit(long co current->comm, current->pid, preempt_count()); - acct_update_integrals(); - update_mem_hiwater(); + acct_update_integrals(tsk); + update_mem_hiwater(tsk); group_dead = atomic_dec_and_test(&tsk->signal->live); if (group_dead) acct_process(code); diff -puN kernel/sched.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch kernel/sched.c --- 25/kernel/sched.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch 2005-02-24 23:12:59.000000000 -0800 +++ 25-akpm/kernel/sched.c 2005-02-24 23:12:59.000000000 -0800 @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -2379,6 +2380,10 @@ void account_system_time(struct task_str cpustat->iowait = cputime64_add(cpustat->iowait, tmp); else cpustat->idle = cputime64_add(cpustat->idle, tmp); + /* Account for system time used */ + acct_update_integrals(p); + /* Update rss highwater mark */ + update_mem_hiwater(p); } /* diff -puN mm/memory.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch mm/memory.c --- 25/mm/memory.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch 2005-02-24 23:12:59.000000000 -0800 +++ 25-akpm/mm/memory.c 2005-02-24 23:12:59.000000000 -0800 @@ -46,7 +46,6 @@ #include #include #include -#include #include #include @@ -747,7 +746,6 @@ void zap_page_range(struct vm_area_struc tlb = tlb_gather_mmu(mm, 0); unmap_vmas(&tlb, mm, vma, address, end, &nr_accounted, details); tlb_finish_mmu(tlb, address, end); - acct_update_integrals(); spin_unlock(&mm->page_table_lock); } @@ -1350,11 +1348,9 @@ static int do_wp_page(struct mm_struct * if (likely(pte_same(*page_table, pte))) { if (PageAnon(old_page)) mm->anon_rss--; - if (PageReserved(old_page)) { + if (PageReserved(old_page)) ++mm->rss; - acct_update_integrals(); - update_mem_hiwater(); - } else + else page_remove_rmap(old_page); break_cow(vma, new_page, address, page_table); lru_cache_add_active(new_page); @@ -1759,9 +1755,6 @@ static int do_swap_page(struct mm_struct remove_exclusive_swap_page(page); mm->rss++; - acct_update_integrals(); - update_mem_hiwater(); - pte = mk_pte(page, vma->vm_page_prot); if (write_access && can_share_swap_page(page)) { pte = maybe_mkwrite(pte_mkdirty(pte), vma); @@ -1826,8 +1819,6 @@ do_anonymous_page(struct mm_struct *mm, goto out; } mm->rss++; - acct_update_integrals(); - update_mem_hiwater(); entry = maybe_mkwrite(pte_mkdirty(mk_pte(page, vma->vm_page_prot)), vma); @@ -1944,8 +1935,6 @@ retry: if (pte_none(*page_table)) { if (!PageReserved(new_page)) ++mm->rss; - acct_update_integrals(); - update_mem_hiwater(); flush_icache_page(vma, new_page); entry = mk_pte(new_page, vma->vm_page_prot); @@ -2265,10 +2254,8 @@ EXPORT_SYMBOL(vmalloc_to_pfn); * update_mem_hiwater * - update per process rss and vm high water data */ -void update_mem_hiwater(void) +void update_mem_hiwater(struct task_struct *tsk) { - struct task_struct *tsk = current; - if (tsk->mm) { if (tsk->mm->hiwater_rss < tsk->mm->rss) tsk->mm->hiwater_rss = tsk->mm->rss; diff -puN mm/mmap.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch mm/mmap.c --- 25/mm/mmap.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch 2005-02-24 23:12:59.000000000 -0800 +++ 25-akpm/mm/mmap.c 2005-02-24 23:12:59.000000000 -0800 @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -1121,8 +1120,6 @@ out: pgoff, flags & MAP_NONBLOCK); down_write(&mm->mmap_sem); } - acct_update_integrals(); - update_mem_hiwater(); return addr; unmap_and_free_vma: @@ -1448,8 +1445,6 @@ static int acct_stack_growth(struct vm_a if (vma->vm_flags & VM_LOCKED) mm->locked_vm += grow; __vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow); - acct_update_integrals(); - update_mem_hiwater(); return 0; } @@ -1953,8 +1948,6 @@ out: mm->locked_vm += len >> PAGE_SHIFT; make_pages_present(addr, addr + len); } - acct_update_integrals(); - update_mem_hiwater(); return addr; } diff -puN mm/mremap.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch mm/mremap.c --- 25/mm/mremap.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch 2005-02-24 23:12:59.000000000 -0800 +++ 25-akpm/mm/mremap.c 2005-02-24 23:12:59.000000000 -0800 @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -255,9 +254,6 @@ static unsigned long move_vma(struct vm_ new_addr + new_len); } - acct_update_integrals(); - update_mem_hiwater(); - return new_addr; } @@ -394,8 +390,6 @@ unsigned long do_mremap(unsigned long ad make_pages_present(addr + old_len, addr + new_len); } - acct_update_integrals(); - update_mem_hiwater(); ret = addr; goto out; } diff -puN mm/nommu.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch mm/nommu.c --- 25/mm/nommu.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch 2005-02-24 23:12:59.000000000 -0800 +++ 25-akpm/mm/nommu.c 2005-02-24 23:12:59.000000000 -0800 @@ -959,10 +959,8 @@ void arch_unmap_area(struct vm_area_stru { } -void update_mem_hiwater(void) +void update_mem_hiwater(struct task_struct *tsk) { - struct task_struct *tsk = current; - if (likely(tsk->mm)) { if (tsk->mm->hiwater_rss < tsk->mm->rss) tsk->mm->hiwater_rss = tsk->mm->rss; diff -puN mm/rmap.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch mm/rmap.c --- 25/mm/rmap.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch 2005-02-24 23:12:59.000000000 -0800 +++ 25-akpm/mm/rmap.c 2005-02-24 23:12:59.000000000 -0800 @@ -51,7 +51,6 @@ #include #include #include -#include #include #include @@ -600,7 +599,6 @@ static int try_to_unmap_one(struct page } mm->rss--; - acct_update_integrals(); page_remove_rmap(page); page_cache_release(page); @@ -705,7 +703,6 @@ static void try_to_unmap_cluster(unsigne page_remove_rmap(page); page_cache_release(page); - acct_update_integrals(); mm->rss--; (*mapcount)--; } diff -puN mm/swapfile.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch mm/swapfile.c --- 25/mm/swapfile.c~move-accounting-function-calls-out-of-critical-vm-code-pathspatch 2005-02-24 23:12:59.000000000 -0800 +++ 25-akpm/mm/swapfile.c 2005-02-24 23:12:59.000000000 -0800 @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -419,8 +418,6 @@ unuse_pte(struct vm_area_struct *vma, un set_pte(dir, pte_mkold(mk_pte(page, vma->vm_page_prot))); page_add_anon_rmap(page, vma, address); swap_free(entry); - acct_update_integrals(); - update_mem_hiwater(); } /* vma->vm_mm->page_table_lock is held */ _