From c518b108234a2418fb65a09e6219202eda316d6c Mon Sep 17 00:00:00 2001 From: Arjan van de Ven Date: Fri, 4 Mar 2005 17:24:57 -0800 Subject: [PATCH] Randomisation: add PF_RANDOMIZE Even though there is a global flag to disable randomisation, it's useful to have a per process flag too; the patch below introduces this per process flag and automatically sets it for "new" binaries. Eventually we will want to tie this to the legacy-va-space personality Signed-off-by: Arjan van de Ven Signed-off-by: Ingo Molnar Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- fs/exec.c | 1 + 1 file changed, 1 insertion(+) (limited to 'fs/exec.c') diff --git a/fs/exec.c b/fs/exec.c index ee58e91a9d7f..694e3c141012 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -877,6 +877,7 @@ int flush_old_exec(struct linux_binprm * bprm) tcomm[i] = '\0'; set_task_comm(current, tcomm); + current->flags &= ~PF_RANDOMIZE; flush_thread(); if (bprm->e_uid != current->euid || bprm->e_gid != current->egid || -- cgit v1.2.3 From ccc875c1d2fe18b50020d501f1005ef46fc55fed Mon Sep 17 00:00:00 2001 From: Arjan van de Ven Date: Fri, 4 Mar 2005 17:25:13 -0800 Subject: [PATCH] Randomisation: stack randomisation The patch below replaces the existing 8Kb randomisation of the userspace stack pointer (which is currently only done for Hyperthreaded P-IVs) with a more general randomisation over a 64Kb range. 64Kb is not a lot, but it's a start and once the dust settles we can increase this value to a more agressive value. Signed-off-by: Arjan van de Ven Signed-off-by: Ingo Molnar Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/i386/kernel/process.c | 7 +++++++ arch/x86_64/kernel/process.c | 8 ++++++++ fs/binfmt_elf.c | 11 ++--------- fs/exec.c | 3 ++- include/asm-alpha/system.h | 2 ++ include/asm-arm/system.h | 2 ++ include/asm-arm26/system.h | 2 ++ include/asm-cris/system.h | 2 ++ include/asm-frv/system.h | 2 ++ include/asm-h8300/system.h | 2 ++ include/asm-i386/system.h | 2 ++ include/asm-ia64/system.h | 3 +++ include/asm-m32r/system.h | 2 ++ include/asm-m68k/system.h | 2 ++ include/asm-m68knommu/system.h | 1 + include/asm-mips/system.h | 2 ++ include/asm-parisc/system.h | 2 ++ include/asm-ppc/system.h | 2 ++ include/asm-ppc64/system.h | 2 ++ include/asm-s390/system.h | 2 ++ include/asm-sh/system.h | 2 ++ include/asm-sh64/system.h | 2 ++ include/asm-sparc/system.h | 2 ++ include/asm-sparc64/system.h | 2 ++ include/asm-v850/system.h | 2 ++ include/asm-x86_64/system.h | 2 ++ 26 files changed, 63 insertions(+), 10 deletions(-) (limited to 'fs/exec.c') diff --git a/arch/i386/kernel/process.c b/arch/i386/kernel/process.c index 28b0d7bf0a84..5bdb839b2bb6 100644 --- a/arch/i386/kernel/process.c +++ b/arch/i386/kernel/process.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -828,3 +829,9 @@ asmlinkage int sys_get_thread_area(struct user_desc __user *u_info) return 0; } +unsigned long arch_align_stack(unsigned long sp) +{ + if (randomize_va_space) + sp -= get_random_int() % 8192; + return sp & ~0xf; +} diff --git a/arch/x86_64/kernel/process.c b/arch/x86_64/kernel/process.c index 3a3522b9c885..0282960ddc91 100644 --- a/arch/x86_64/kernel/process.c +++ b/arch/x86_64/kernel/process.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -749,3 +750,10 @@ int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs) return 1; } + +unsigned long arch_align_stack(unsigned long sp) +{ + if (randomize_va_space) + sp -= get_random_int() % 8192; + return sp & ~0xf; +} diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 1740bac44917..91ad281f851d 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -165,21 +165,14 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr * exec, if (k_platform) { size_t len = strlen(k_platform) + 1; -#ifdef CONFIG_X86_HT /* * In some cases (e.g. Hyper-Threading), we want to avoid L1 * evictions by the processes running on the same package. One * thing we can do is to shuffle the initial stack for them. - * - * The conditionals here are unneeded, but kept in to make the - * code behaviour the same as pre change unless we have - * hyperthreaded processors. This should be cleaned up - * before 2.6 */ - if (smp_num_siblings > 1) - STACK_ALLOC(p, ((current->pid % 64) << 7)); -#endif + p = arch_align_stack(p); + u_platform = (elf_addr_t __user *)STACK_ALLOC(p, len); if (__copy_to_user(u_platform, k_platform, len)) return -EFAULT; diff --git a/fs/exec.c b/fs/exec.c index 694e3c141012..6e505b1b3db6 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -400,7 +400,8 @@ int setup_arg_pages(struct linux_binprm *bprm, while (i < MAX_ARG_PAGES) bprm->page[i++] = NULL; #else - stack_base = stack_top - MAX_ARG_PAGES * PAGE_SIZE; + stack_base = arch_align_stack(STACK_TOP - MAX_ARG_PAGES*PAGE_SIZE); + stack_base = PAGE_ALIGN(stack_base); bprm->p += stack_base; mm->arg_start = bprm->p; arg_size = stack_top - (PAGE_MASK & (unsigned long) mm->arg_start); diff --git a/include/asm-alpha/system.h b/include/asm-alpha/system.h index bba276c50b15..c08ce970ff8c 100644 --- a/include/asm-alpha/system.h +++ b/include/asm-alpha/system.h @@ -621,4 +621,6 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size) #endif /* __ASSEMBLY__ */ +#define arch_align_stack(x) (x) + #endif diff --git a/include/asm-arm/system.h b/include/asm-arm/system.h index 77d0dcf0b713..b5731290b4e5 100644 --- a/include/asm-arm/system.h +++ b/include/asm-arm/system.h @@ -383,6 +383,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size #endif /* __ASSEMBLY__ */ +#define arch_align_stack(x) (x) + #endif /* __KERNEL__ */ #endif diff --git a/include/asm-arm26/system.h b/include/asm-arm26/system.h index 6361b6c71f8c..f23fac1938f3 100644 --- a/include/asm-arm26/system.h +++ b/include/asm-arm26/system.h @@ -245,6 +245,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size #endif /* __ASSEMBLY__ */ +#define arch_align_stack(x) (x) + #endif /* __KERNEL__ */ #endif diff --git a/include/asm-cris/system.h b/include/asm-cris/system.h index f9cf80262574..e06739806d4e 100644 --- a/include/asm-cris/system.h +++ b/include/asm-cris/system.h @@ -69,4 +69,6 @@ extern inline unsigned long __xchg(unsigned long x, volatile void * ptr, int siz return x; } +#define arch_align_stack(x) (x) + #endif diff --git a/include/asm-frv/system.h b/include/asm-frv/system.h index 29cfa21ec2fe..d2aea70a5f64 100644 --- a/include/asm-frv/system.h +++ b/include/asm-frv/system.h @@ -123,4 +123,6 @@ do { \ extern void die_if_kernel(const char *, ...) __attribute__((format(printf, 1, 2))); extern void free_initmem(void); +#define arch_align_stack(x) (x) + #endif /* _ASM_SYSTEM_H */ diff --git a/include/asm-h8300/system.h b/include/asm-h8300/system.h index b91dae2a90c3..dfe96c7121cf 100644 --- a/include/asm-h8300/system.h +++ b/include/asm-h8300/system.h @@ -144,4 +144,6 @@ static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int siz asm("jmp @@0"); \ }) +#define arch_align_stack(x) (x) + #endif /* _H8300_SYSTEM_H */ diff --git a/include/asm-i386/system.h b/include/asm-i386/system.h index c705fa77b138..6f74d4c44a0e 100644 --- a/include/asm-i386/system.h +++ b/include/asm-i386/system.h @@ -468,4 +468,6 @@ void enable_hlt(void); extern int es7000_plat; void cpu_idle_wait(void); +extern unsigned long arch_align_stack(unsigned long sp); + #endif diff --git a/include/asm-ia64/system.h b/include/asm-ia64/system.h index f28b920e9089..6f516e76d1f0 100644 --- a/include/asm-ia64/system.h +++ b/include/asm-ia64/system.h @@ -285,6 +285,9 @@ do { \ #define ia64_platform_is(x) (strcmp(x, platform_name) == 0) void cpu_idle_wait(void); + +#define arch_align_stack(x) (x) + #endif /* __KERNEL__ */ #endif /* __ASSEMBLY__ */ diff --git a/include/asm-m32r/system.h b/include/asm-m32r/system.h index 5828af7d4122..73348c3f858b 100644 --- a/include/asm-m32r/system.h +++ b/include/asm-m32r/system.h @@ -294,4 +294,6 @@ static __inline__ unsigned long __xchg(unsigned long x, volatile void * ptr, #define set_mb(var, value) do { xchg(&var, value); } while (0) #define set_wmb(var, value) do { var = value; wmb(); } while (0) +#define arch_align_stack(x) (x) + #endif /* _ASM_M32R_SYSTEM_H */ diff --git a/include/asm-m68k/system.h b/include/asm-m68k/system.h index f0f36fca11bb..64d3481df74c 100644 --- a/include/asm-m68k/system.h +++ b/include/asm-m68k/system.h @@ -194,6 +194,8 @@ static inline unsigned long __cmpxchg(volatile void *p, unsigned long old, (unsigned long)(n),sizeof(*(ptr)))) #endif +#define arch_align_stack(x) (x) + #endif /* __KERNEL__ */ #endif /* _M68K_SYSTEM_H */ diff --git a/include/asm-m68knommu/system.h b/include/asm-m68knommu/system.h index ce3f0b0226df..c341b66c147b 100644 --- a/include/asm-m68knommu/system.h +++ b/include/asm-m68knommu/system.h @@ -281,5 +281,6 @@ cmpxchg(volatile int *p, int old, int new) }) #endif #endif +#define arch_align_stack(x) (x) #endif /* _M68KNOMMU_SYSTEM_H */ diff --git a/include/asm-mips/system.h b/include/asm-mips/system.h index a421cdb1e0da..888fd8908467 100644 --- a/include/asm-mips/system.h +++ b/include/asm-mips/system.h @@ -433,4 +433,6 @@ do { \ #define finish_arch_switch(rq, prev) spin_unlock_irq(&(prev)->switch_lock) #define task_running(rq, p) ((rq)->curr == (p) || spin_is_locked(&(p)->switch_lock)) +#define arch_align_stack(x) (x) + #endif /* _ASM_SYSTEM_H */ diff --git a/include/asm-parisc/system.h b/include/asm-parisc/system.h index 8aecb9e93fc0..d91428ed57d6 100644 --- a/include/asm-parisc/system.h +++ b/include/asm-parisc/system.h @@ -205,4 +205,6 @@ extern spinlock_t pa_tlb_lock; #endif +#define arch_align_stack(x) (x) + #endif diff --git a/include/asm-ppc/system.h b/include/asm-ppc/system.h index 5cff9a0fd84b..25050b76db44 100644 --- a/include/asm-ppc/system.h +++ b/include/asm-ppc/system.h @@ -201,5 +201,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size) (unsigned long)_n_, sizeof(*(ptr))); \ }) +#define arch_align_stack(x) (x) + #endif /* __KERNEL__ */ #endif /* __PPC_SYSTEM_H */ diff --git a/include/asm-ppc64/system.h b/include/asm-ppc64/system.h index 6785e69e8b9e..98d120ca8a91 100644 --- a/include/asm-ppc64/system.h +++ b/include/asm-ppc64/system.h @@ -300,5 +300,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size) */ #define NET_IP_ALIGN 0 +#define arch_align_stack(x) (x) + #endif /* __KERNEL__ */ #endif diff --git a/include/asm-s390/system.h b/include/asm-s390/system.h index 8565a8aee735..037b8d16e435 100644 --- a/include/asm-s390/system.h +++ b/include/asm-s390/system.h @@ -461,6 +461,8 @@ extern void (*_machine_restart)(char *command); extern void (*_machine_halt)(void); extern void (*_machine_power_off)(void); +#define arch_align_stack(x) (x) + #endif /* __KERNEL__ */ #endif diff --git a/include/asm-sh/system.h b/include/asm-sh/system.h index 5e67caf8885e..28a3c2d8bcd7 100644 --- a/include/asm-sh/system.h +++ b/include/asm-sh/system.h @@ -259,4 +259,6 @@ static __inline__ unsigned long __xchg(unsigned long x, volatile void * ptr, int void disable_hlt(void); void enable_hlt(void); +#define arch_align_stack(x) (x) + #endif diff --git a/include/asm-sh64/system.h b/include/asm-sh64/system.h index 8b3a6f9e62fb..8aaabc92f9fb 100644 --- a/include/asm-sh64/system.h +++ b/include/asm-sh64/system.h @@ -191,4 +191,6 @@ extern void print_seg(char *file,int line); #define PL() printk("@ <%s,%s:%d>\n",__FILE__,__FUNCTION__,__LINE__) +#define arch_align_stack(x) (x) + #endif /* __ASM_SH64_SYSTEM_H */ diff --git a/include/asm-sparc/system.h b/include/asm-sparc/system.h index a8e77ad1ea46..80cf20cfaee1 100644 --- a/include/asm-sparc/system.h +++ b/include/asm-sparc/system.h @@ -257,4 +257,6 @@ extern void die_if_kernel(char *str, struct pt_regs *regs) __attribute__ ((noret #endif /* __ASSEMBLY__ */ +#define arch_align_stack(x) (x) + #endif /* !(__SPARC_SYSTEM_H) */ diff --git a/include/asm-sparc64/system.h b/include/asm-sparc64/system.h index ef77358abf24..e8ba9d5277e1 100644 --- a/include/asm-sparc64/system.h +++ b/include/asm-sparc64/system.h @@ -341,4 +341,6 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size) #endif /* !(__ASSEMBLY__) */ +#define arch_align_stack(x) (x) + #endif /* !(__SPARC64_SYSTEM_H) */ diff --git a/include/asm-v850/system.h b/include/asm-v850/system.h index 072a997dc5a9..20f4c738c04e 100644 --- a/include/asm-v850/system.h +++ b/include/asm-v850/system.h @@ -108,4 +108,6 @@ extern inline unsigned long __xchg (unsigned long with, return tmp; } +#define arch_align_stack(x) (x) + #endif /* __V850_SYSTEM_H__ */ diff --git a/include/asm-x86_64/system.h b/include/asm-x86_64/system.h index c1710933828f..76165736e43a 100644 --- a/include/asm-x86_64/system.h +++ b/include/asm-x86_64/system.h @@ -338,4 +338,6 @@ void enable_hlt(void); #define HAVE_EAT_KEY void eat_key(void); +extern unsigned long arch_align_stack(unsigned long sp); + #endif -- cgit v1.2.3 From bf57909ff72b7e1481b38590edd036c1ef5991e9 Mon Sep 17 00:00:00 2001 From: Arjan van de Ven Date: Fri, 4 Mar 2005 17:26:09 -0800 Subject: [PATCH] Randomisation: top-of-stack randomization In addition to randomisation of the stack pointer within the stack, the stack itself should be randomized too. We need both approaches, we can only randomize the stack itself in pagesize increments. However randomizing large ranges with the stackpointer runs into the situation where a huge chunk of the stack rlimit is used by the randomisation; this is undesirable so we need to do both. Signed-off-by: Arjan van de Ven Signed-off-by: Ingo Molnar Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- fs/binfmt_elf.c | 17 ++++++++++++++++- fs/exec.c | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'fs/exec.c') diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 9fc7140228e8..3ad9cef2cd28 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -494,6 +495,19 @@ out: #define INTERPRETER_ELF 2 +static unsigned long randomize_stack_top(unsigned long stack_top) +{ + unsigned int random_variable = 0; + + if (current->flags & PF_RANDOMIZE) + random_variable = get_random_int() % (8*1024*1024); +#ifdef CONFIG_STACK_GROWSUP + return PAGE_ALIGN(stack_top + random_variable); +#else + return PAGE_ALIGN(stack_top - random_variable); +#endif +} + static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs) { struct file *interpreter = NULL; /* to shut gcc up */ @@ -761,7 +775,8 @@ static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs) change some of these later */ current->mm->rss = 0; current->mm->free_area_cache = current->mm->mmap_base; - retval = setup_arg_pages(bprm, STACK_TOP, executable_stack); + retval = setup_arg_pages(bprm, randomize_stack_top(STACK_TOP), + executable_stack); if (retval < 0) { send_sig(SIGKILL, current, 0); goto out_free_dentry; diff --git a/fs/exec.c b/fs/exec.c index 6e505b1b3db6..84427b0e2236 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -400,7 +400,7 @@ int setup_arg_pages(struct linux_binprm *bprm, while (i < MAX_ARG_PAGES) bprm->page[i++] = NULL; #else - stack_base = arch_align_stack(STACK_TOP - MAX_ARG_PAGES*PAGE_SIZE); + stack_base = arch_align_stack(stack_top - MAX_ARG_PAGES*PAGE_SIZE); stack_base = PAGE_ALIGN(stack_base); bprm->p += stack_base; mm->arg_start = bprm->p; -- cgit v1.2.3 From 545a604c163b11bc625e7d031dbe1c02a520d6d6 Mon Sep 17 00:00:00 2001 From: Christoph Lameter Date: Fri, 4 Mar 2005 17:26:24 -0800 Subject: [PATCH] Move accounting function calls out of critical vm code paths 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 Signed-off-by: Linus Torvalds --- fs/exec.c | 4 ++-- include/linux/acct.h | 4 ++-- include/linux/mm.h | 2 +- kernel/acct.c | 4 +--- kernel/exit.c | 4 ++-- kernel/sched.c | 5 +++++ mm/memory.c | 19 +++---------------- mm/mmap.c | 7 ------- mm/mremap.c | 6 ------ mm/nommu.c | 4 +--- mm/rmap.c | 3 --- mm/swapfile.c | 3 --- 12 files changed, 17 insertions(+), 48 deletions(-) (limited to 'fs/exec.c') diff --git a/fs/exec.c b/fs/exec.c index 84427b0e2236..393605cdc101 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -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 --git a/include/linux/acct.h b/include/linux/acct.h index 39cd52f7f557..1993a3691768 100644 --- a/include/linux/acct.h +++ b/include/linux/acct.h @@ -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 --git a/include/linux/mm.h b/include/linux/mm.h index 3a8c47c5dc9c..418b928a6617 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -838,7 +838,7 @@ static inline void vm_stat_unaccount(struct vm_area_struct *vma) } /* 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 --git a/kernel/acct.c b/kernel/acct.c index 32e39accbb86..78ed87b13de6 100644 --- a/kernel/acct.c +++ b/kernel/acct.c @@ -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 --git a/kernel/exit.c b/kernel/exit.c index f40a50f69850..4173fa7536dc 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -806,8 +806,8 @@ fastcall NORET_TYPE void do_exit(long code) 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 --git a/kernel/sched.c b/kernel/sched.c index 95042b27d30c..f32101f5e31a 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -2379,6 +2380,10 @@ void account_system_time(struct task_struct *p, int hardirq_offset, 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 --git a/mm/memory.c b/mm/memory.c index 48cbd6b7b98b..e9b47f5ddb05 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -46,7 +46,6 @@ #include #include #include -#include #include #include @@ -735,7 +734,6 @@ void zap_page_range(struct vm_area_struct *vma, unsigned long address, 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); } @@ -1338,11 +1336,9 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct * vma, 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); @@ -1747,9 +1743,6 @@ static int do_swap_page(struct mm_struct * mm, 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); @@ -1814,8 +1807,6 @@ do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma, goto out; } mm->rss++; - acct_update_integrals(); - update_mem_hiwater(); entry = maybe_mkwrite(pte_mkdirty(mk_pte(page, vma->vm_page_prot)), vma); @@ -1932,8 +1923,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); @@ -2253,10 +2242,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 --git a/mm/mmap.c b/mm/mmap.c index b8af0c8db48d..a8990719c87a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -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: @@ -1463,8 +1460,6 @@ static int acct_stack_growth(struct vm_area_struct * vma, unsigned long size, un 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; } @@ -1968,8 +1963,6 @@ out: mm->locked_vm += len >> PAGE_SHIFT; make_pages_present(addr, addr + len); } - acct_update_integrals(); - update_mem_hiwater(); return addr; } diff --git a/mm/mremap.c b/mm/mremap.c index ebdf621984ac..3c6d60454296 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -255,9 +254,6 @@ static unsigned long move_vma(struct vm_area_struct *vma, new_addr + new_len); } - acct_update_integrals(); - update_mem_hiwater(); - return new_addr; } @@ -394,8 +390,6 @@ unsigned long do_mremap(unsigned long addr, make_pages_present(addr + old_len, addr + new_len); } - acct_update_integrals(); - update_mem_hiwater(); ret = addr; goto out; } diff --git a/mm/nommu.c b/mm/nommu.c index 8e70b95a8d9f..f72d40c31a96 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -959,10 +959,8 @@ void arch_unmap_area(struct vm_area_struct *area) { } -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 --git a/mm/rmap.c b/mm/rmap.c index 4ff8183fa18e..9ff4bfc6adb6 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -51,7 +51,6 @@ #include #include #include -#include #include #include @@ -600,7 +599,6 @@ static int try_to_unmap_one(struct page *page, struct vm_area_struct *vma) } mm->rss--; - acct_update_integrals(); page_remove_rmap(page); page_cache_release(page); @@ -705,7 +703,6 @@ static void try_to_unmap_cluster(unsigned long cursor, page_remove_rmap(page); page_cache_release(page); - acct_update_integrals(); mm->rss--; (*mapcount)--; } diff --git a/mm/swapfile.c b/mm/swapfile.c index 547ecd9c060d..8f2a388911b1 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -437,8 +436,6 @@ unuse_pte(struct vm_area_struct *vma, unsigned long address, pte_t *dir, 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 */ -- cgit v1.2.3