OpenVZ Forum - RDF feed
type: channel
items: [PATCH] BC: resource beancounters (v5) (added userpages reclamation)
items: [PATCH 1/10] BC: introduce atomic_dec_and_lock_irqsave()
items: [PATCH 2/10] BC: kconfig
items: [PATCH 3/10] BC: beancounters core (API)
items: [PATCH 4/10] BC: context inheriting and changing
items: [PATCH 5/10] BC: user interface (syscalls)
items: [PATCH 6/10] BC: kernel memory (core)
items: [PATCH 7/10] BC: kernel memory (marks)
items: [PATCH 8/10] BC: private pages (mappings) accounting (core)
items: [PATCH 9/10] BC: physical pages accounting/reclamation (core)
items: [PATCH 10/10] BC: user memory accounting (hooks)
items: [TOOL] BC: bcctl.c

[PATCH] BC: resource beancounters (v5) (added userpages reclamation)
type: item
description: MAJOR CHANGES: - phys pages limit hit leads to user pages reclamation - bc can be changed on arbitrary task ----------------------------------------------------- Core Resource Beancounters (BC) + kernel/user memory control. BC allows to account and control consumption of kernel resources used by group of processes. Draft UBC description on OpenVZ wiki can be found at http://wiki.openvz.org/UBC_parameters The full BC patch set allows to control: - kernel memory. All the kernel objects allocatable on user demand should be accounted and limited for DoS protection. E.g. page tables, task structs, vmas etc. - virtual memory pages. BCs allow to limit a container to some amount of memory and introduces 2-level OOM killer taking into account container's consumption. pages shared between containers are correctly charged as fractions (tunable). - network buffers. These includes TCP/IP rcv/snd buffers, dgram snd buffers, unix, netlinks and other buffers. - minor resources accounted/limited by number: tasks, files, flocks, ptys, siginfo, pinned dcache mem, sockets, iptentries (for containers with virtualized networking) As the first step we want to propose for discussion the most complicated parts of resource management: kernel memory and virtual memory. The patch set to be sent provides core for BC and management of kernel memory only. Virtual memory management will be sent in a couple of days. The patches in these series are: * diff-atomic-dec-and-lock-irqsave.patch: introduce atomic_dec_and_lock_irqsave() * diff-bc-kconfig.patch: Adds kernel/bc/Kconfig file with UBC options and includes it into arch Kconfigs * diff-bc-core.patch: Contains core functionality and interfaces of BC: find/create beancounter, initialization, charge/uncharge of resource, core objects' declarations. * diff-bc-task.patch: Contains code responsible for setting BC on task, it's inheriting and setting host context in interrupts. * diff-bc-syscalls.patch: Patch adds system calls for BC management: 1. sys…
creator: Kirill Korotaev
date: 2006-10-05T15:27:47-00:00

[PATCH 1/10] BC: introduce atomic_dec_and_lock_irqsave()
type: item
description: Oleg Nesterov noticed to me that the construction like (used in beancounter patches and free_uid()): local_irq_save(flags); if (atomic_dec_and_lock(&refcnt, &lock)) ... is not that good for preemtible kernels, since with preemption spin_lock() can schedule() to reduce latency. However, it won't schedule if interrupts are disabled. So this patch introduces atomic_dec_and_lock_irqsave() as a logical counterpart to atomic_dec_and_lock(). Signed-Off-By: Pavel Emelianov <xemul@openvz.org> Signed-Off-By: Kirill Korotaev <dev@openvz.org> --- include/linux/spinlock.h | 6 ++++++ kernel/user.c | 5 +---- lib/dec_and_lock.c | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) --- ./include/linux/spinlock.h.dlirq 2006-08-28 10:17:35.000000000 +0400 +++ ./include/linux/spinlock.h 2006-08-28 11:22:37.000000000 +0400 @@ -266,6 +266,12 @@ extern int _atomic_dec_and_lock(atomic_t #define atomic_dec_and_lock(atomic, lock) \ __cond_lock(lock, _atomic_dec_and_lock(atomic, lock)) +extern int _atomic_dec_and_lock_irqsave(atomic_t *atomic, spinlock_t *lock, + unsigned long *flagsp); +#define atomic_dec_and_lock_irqsave(atomic, lock, flags) \ + __cond_lock(lock, \ + _atomic_dec_and_lock_irqsave(atomic, lock, &flags)) + /** * spin_can_lock - would spin_trylock() succeed? * @lock: the spinlock in question. --- ./kernel/user.c.dlirq 2006-07-10 12:39:20.000000000 +0400 +++ ./kernel/user.c 2006-08-28 11:08:56.000000000 +0400 @@ -108,15 +108,12 @@ void free_uid(struct user_struct *up) if (!up) return; - local_irq_save(flags); - if (atomic_dec_and_lock(&up->__count, &uidhash_lock)) { + if (atomic_dec_and_lock_irqsave(&up->__count, &uidhash_lock, flags)) { uid_hash_remove(up); spin_unlock_irqrestore(&uidhash_lock, flags); key_put(up->uid_keyring); key_put(up->session_keyring); kmem_cache_free(uid_cachep, up); - } else { - local_irq_restore(flags); } } --- ./lib/dec_and_lock.c.dlirq 2006-04-21 11:59:36.000000000 +0400 +++ ./lib/dec_and_lock.c 2006-08-28 11:22:08.000000000 +0400…
creator: dev
date: 2006-10-05T15:46:42-00:00

[PATCH 2/10] BC: kconfig
type: item
description: Add kernel/bc/Kconfig file with BC options and include it into arch Kconfigs Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: Kirill Korotaev <dev@openvz.org> --- init/Kconfig | 4 ++++ kernel/bc/Kconfig | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) --- ./init/Kconfig.bc_kconfig 2006-10-05 11:42:43.000000000 +0400 +++ ./init/Kconfig 2006-10-05 11:43:56.000000000 +0400 @@ -564,6 +564,10 @@ config STOP_MACHINE Need stop_machine() primitive. endmenu +menu "Beancounters" +source "kernel/bc/Kconfig" +endmenu + menu "Block layer" source "block/Kconfig" endmenu --- /dev/null 2006-07-18 14:52:43.075228448 +0400 +++ ./kernel/bc/Kconfig 2006-10-05 11:43:56.000000000 +0400 @@ -0,0 +1,16 @@ +config BEANCOUNTERS + bool "Enable resource accounting/control" + default n + help + When Y this option provides accounting and allows configuring + limits for user's consumption of exhaustible system resources. + The most important resource controlled by this patch is unswappable + memory (either mlock'ed or used by internal kernel structures and + buffers). The main goal of this patch is to protect processes + from running short of important resources because of accidental + misbehavior of processes or malicious activity aiming to ``kill'' + the system. It's worth mentioning that resource limits configured + by setrlimit(2) do not give an acceptable level of protection + because they cover only a small fraction of resources and work on a + per-process basis. Per-process accounting doesn't prevent malicious + users from spawning a lot of resource-consuming processes.
creator: dev
date: 2006-10-05T15:46:55-00:00

[PATCH 3/10] BC: beancounters core (API)
type: item
description: Core functionality and interfaces of BCs: find/create beancounter, initialization, charge/uncharge of resource, core objects' declarations. Basic structures: bc_resource_parm - resource description beancounter - set of resources, id, lock Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: Kirill Korotaev <dev@openvz.org> --- include/bc/beancounter.h | 169 +++++++++++++++++++++++++++++++++++++ include/linux/types.h | 16 +++ init/main.c | 3 kernel/Makefile | 1 kernel/bc/Makefile | 12 ++ kernel/bc/beancounter.c | 214 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 415 insertions(+) --- /dev/null 2006-07-18 14:52:43.075228448 +0400 +++ ./include/bc/beancounter.h 2006-10-05 12:05:33.000000000 +0400 @@ -0,0 +1,169 @@ +/* + * include/bc/beancounter.h + * + * Copyright (C) 2006 OpenVZ SWsoft Inc + * + */ + +#ifndef __BEANCOUNTER_H__ +#define __BEANCOUNTER_H__ + +#define BC_KMEMSIZE 0 +#define BC_PRIVVMPAGES 1 +#define BC_PHYSPAGES 2 + +#define BC_RESOURCES 3 + +struct bc_resource_parm { + unsigned long barrier; + unsigned long limit; + unsigned long held; + unsigned long minheld; + unsigned long maxheld; + unsigned long failcnt; +}; + +#ifdef __KERNEL__ + +#include <linux/list.h> +#include <linux/spinlock.h> +#include <linux/init.h> +#include <asm/atomic.h> + +#define BC_MAXVALUE ((unsigned long)LONG_MAX) + +enum bc_severity { + BC_BARRIER, + BC_LIMIT, + BC_FORCE, +}; + +#ifdef CONFIG_BEANCOUNTERS + +struct beancounter { + atomic_t bc_refcount; + spinlock_t bc_lock; + bcid_t bc_id; + struct hlist_node bc_hash; + + struct bc_resource_parm bc_parms[BC_RESOURCES]; + + struct list_head bc_page_list; + spinlock_t bc_page_lock; +}; + +struct bc_resource { + char *bcr_name; + + int (*bcr_init)(struct beancounter *bc, gfp_t mask); + int (*bcr_change)(struct beancounter *bc, + unsigned long new_bar, unsigned long new_lim); + void (*bcr_barrier_hit)(struct beancounter *bc); + int (*bcr_limit_hit)(struct beancounter *bc, unsigned long val, + unsigned lon…
creator: Kirill Korotaev
date: 2006-10-05T15:47:53-00:00

[PATCH 4/10] BC: context inheriting and changing
type: item
description: Contains code responsible for setting BC on task, it's inheriting and setting host context in interrupts. Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: Kirill Korotaev <dev@openvz.org> --- include/bc/task.h | 51 ++++++++++++++++++++++++++++++++++++ include/linux/sched.h | 5 +++ kernel/bc/misc.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/fork.c | 5 +++ kernel/irq/handle.c | 6 ++++ kernel/softirq.c | 5 +++ 6 files changed, 142 insertions(+) --- /dev/null 2006-07-18 14:52:43.075228448 +0400 +++ ./include/bc/task.h 2006-10-05 12:11:44.000000000 +0400 @@ -0,0 +1,51 @@ +/* + * include/bc/beancounter.h + * + * Copyright (C) 2006 OpenVZ SWsoft Inc + * + */ + +#ifndef __BC_TASK_H__ +#define __BC_TASK_H__ + +struct beancounter; +struct task_struct; + +#ifdef CONFIG_BEANCOUNTERS +#define get_exec_bc() (current->exec_bc) + +#define set_exec_bc(bc) ({ \ + struct task_struct *t; \ + struct beancounter *old; \ + t = current; \ + old = t->exec_bc; \ + t->exec_bc = bc; \ + old; \ + }) + +#define reset_exec_bc(old, expected) do { \ + struct task_struct *t; \ + t = current; \ + BUG_ON(t->exec_bc != expected);\ + t->exec_bc = old; \ + } while (0) + +extern struct beancounter init_bc; + +void copy_beancounter(struct task_struct *tsk, struct task_struct *parent); +void free_beancounter(struct task_struct *tsk); +int bc_task_move(struct task_struct *tsk, struct beancounter *bc); +#else +static inline void copy_beancounter(struct task_struct *tsk, + struct task_struct *parent) +{ +} + +static inline void free_beancounter(struct task_struct *tsk) +{ +} + +#define set_exec_bc(bc) (NULL) +#define reset_exec_bc(bc, exp) do { } while (0) +#endif +#endif --- ./include/linux/sched.h.bc_task 2006-10-05 11:42:43.000000000 +0400 +++ ./include/linux/sched.h 2006-10-05 12:11:44.000000000 +0400 @@ -77,6 +77,8 @@ struct sched_param { #include <linux/futex.h> #include <linux/rtmutex.h> +#include <bc/task.h> + #include <linux/time.h> #include <linux/param.h> #include…
creator: Kirill Korotaev
date: 2006-10-05T15:50:05-00:00

[PATCH 5/10] BC: user interface (syscalls)
type: item
description: Add the following system calls for BC management: 1. sys_get_bcid - get current BC id 2. sys_set_bcid - change BC on task 3. sys_set_bclimit - set limits for resources consumtions 4. sys_get_bcstat - return br_resource_parm on resource Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: Kirill Korotaev <dev@openvz.org> --- arch/i386/kernel/syscall_table.S | 4 + arch/ia64/kernel/entry.S | 4 + arch/sparc/kernel/entry.S | 2 arch/sparc/kernel/systbls.S | 6 + arch/sparc64/kernel/entry.S | 2 arch/sparc64/kernel/systbls.S | 10 ++- include/asm-i386/unistd.h | 6 + include/asm-ia64/unistd.h | 6 + include/asm-powerpc/systbl.h | 4 + include/asm-powerpc/unistd.h | 6 + include/asm-sparc/unistd.h | 4 + include/asm-sparc64/unistd.h | 4 + include/asm-x86_64/unistd.h | 10 ++- kernel/bc/sys.c | 130 +++++++++++++++++++++++++++++++++++++++ kernel/sys_ni.c | 6 + 15 files changed, 195 insertions(+), 9 deletions(-) --- ./arch/i386/kernel/syscall_table.S.bc_syscalls 2006-10-05 11:42:39.000000000 +0400 +++ ./arch/i386/kernel/syscall_table.S 2006-10-05 12:09:09.000000000 +0400 @@ -322,3 +322,7 @@ ENTRY(sys_call_table) .long sys_kevent_get_events /* 320 */ .long sys_kevent_ctl .long sys_kevent_wait + .long sys_get_bcid + .long sys_set_bcid + .long sys_set_bclimit /* 325 */ + .long sys_get_bcstat --- ./arch/ia64/kernel/entry.S.bc_syscalls 2006-10-05 11:42:39.000000000 +0400 +++ ./arch/ia64/kernel/entry.S 2006-10-05 12:09:09.000000000 +0400 @@ -1610,5 +1610,9 @@ sys_call_table: data8 sys_sync_file_range // 1300 data8 sys_tee data8 sys_vmsplice + data8 sys_get_bcid + data8 sys_set_bcid + data8 sys_set_bclimit // 1305 + data8 sys_get_bcstat .org sys_call_table + 8*NR_syscalls // guard against failures to increase NR_syscalls --- ./arch/sparc/kernel/entry.S.bc_syscalls 2006-09-20 14:46:17.000000000 +0400 +++ ./arch/sparc/kernel/entry.S 2006-10-05 12:09:09.000000000 +0400 @@ -37,7 +37,7 @@ #define curptr g6 -#define NR_SYSCALLS 300 /* Each OS is different... */ +#define NR_SYSCALLS 304 …
creator: Kirill Korotaev
date: 2006-10-05T15:50:57-00:00

[PATCH 6/10] BC: kernel memory (core)
type: item
description: Introduce BC_KMEMSIZE resource which accounts kernel objects allocated by task's request. Reference to BC is kept on struct page or slab object. For slabs each struct slab contains a set of pointers corresponding objects are charged to. Allocation charge rules: 1. Pages - if allocation is performed with __GFP_BC flag - page is charged to current's exec_bc. 2. Slabs - kmem_cache may be created with SLAB_BC flag - in this case each allocation is charged. Caches used by kmalloc are created with SLAB_BC | SLAB_BC_NOCHARGE flags. In this case only __GFP_BC allocations are charged. Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: Kirill Korotaev <dev@openvz.org> --- include/bc/kmem.h | 48 ++++++++++++++++++++ include/linux/gfp.h | 8 ++- include/linux/mm.h | 1 include/linux/mm_types.h | 3 + include/linux/slab.h | 4 + include/linux/vmalloc.h | 1 kernel/bc/kmem.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++ mm/mempool.c | 2 mm/page_alloc.c | 11 ++++ mm/slab.c | 112 +++++++++++++++++++++++++++++++++++++++-------- mm/vmalloc.c | 6 ++ 11 files changed, 287 insertions(+), 21 deletions(-) --- /dev/null 2006-07-18 14:52:43.075228448 +0400 +++ ./include/bc/kmem.h 2006-10-05 12:13:58.000000000 +0400 @@ -0,0 +1,48 @@ +/* + * include/bc/kmem.h + * + * Copyright (C) 2006 OpenVZ SWsoft Inc + * + */ + +#ifndef __BC_KMEM_H_ +#define __BC_KMEM_H_ + +/* + * BC_KMEMSIZE accounting + */ + +#include <linux/slab.h> +#include <linux/gfp.h> + +struct page; +struct beancounter; + +#ifdef CONFIG_BEANCOUNTERS +int __must_check bc_page_charge(struct page *page, int order, gfp_t flags); +void bc_page_uncharge(struct page *page, int order); + +int __must_check bc_slab_charge(kmem_cache_t *cachep, void *obj, gfp_t flags); +void bc_slab_uncharge(kmem_cache_t *cachep, void *obj); +#else +static inline int __must_check bc_page_charge(struct page *page, int order, + gfp_t flags) +{ + return 0; +} + +static inline void bc_page_uncharge(struct page *page, int order) +{ +} + +static in…
creator: Kirill Korotaev
date: 2006-10-05T15:52:13-00:00

[PATCH 7/10] BC: kernel memory (marks)
type: item
description: Mark some kmem caches with SLAB_BC and some allocations with __GFP_BC to cause charging/limiting of appropriate kernel resources. Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: Kirill Korotaev <dev@openvz.org> --- arch/i386/kernel/ldt.c | 4 ++-- arch/i386/mm/init.c | 4 ++-- arch/i386/mm/pgtable.c | 6 ++++-- drivers/char/tty_io.c | 10 +++++----- fs/file.c | 8 ++++---- fs/locks.c | 2 +- fs/namespace.c | 3 ++- fs/select.c | 7 ++++--- include/asm-i386/thread_info.h | 4 ++-- include/asm-ia64/pgalloc.h | 24 +++++++++++++++++------- include/asm-x86_64/pgalloc.h | 12 ++++++++---- include/asm-x86_64/thread_info.h | 5 +++-- ipc/msgutil.c | 4 ++-- ipc/sem.c | 7 ++++--- ipc/util.c | 8 ++++---- kernel/fork.c | 15 ++++++++------- kernel/posix-timers.c | 3 ++- kernel/signal.c | 2 +- kernel/user.c | 2 +- mm/rmap.c | 3 ++- mm/shmem.c | 3 ++- mm/slab.c | 9 ++++++--- 22 files changed, 86 insertions(+), 59 deletions(-) --- ./arch/i386/kernel/ldt.c.bc_kmem_charge 2006-10-05 11:42:39.000000000 +0400 +++ ./arch/i386/kernel/ldt.c 2006-10-05 12:14:35.000000000 +0400 @@ -39,9 +39,9 @@ static int alloc_ldt(mm_context_t *pc, i oldsize = pc->size; mincount = (mincount+511)&(~511); if (mincount*LDT_ENTRY_SIZE > PAGE_SIZE) - newldt = vmalloc(mincount*LDT_ENTRY_SIZE); + newldt = vmalloc_bc(mincount*LDT_ENTRY_SIZE); else - newldt = kmalloc(mincount*LDT_ENTRY_SIZE, GFP_KERNEL); + newldt = kmalloc(mincount*LDT_ENTRY_SIZE, GFP_KERNEL_BC); if (!newldt) return -ENOMEM; --- ./arch/i386/mm/init.c.bc_kmem_charge 2006-10-05 11:42:39.000000000 +0400 +++ ./arch/i386/mm/init.c 2006-10-05 12:14:35.000000000 +0400 @@ -709,7 +709,7 @@ void __init pgtable_cache_init(void) pmd_cache = kmem_cache_create("pmd", PTRS_PER_PMD*sizeof(pmd_t), PTRS_PER_PMD*sizeof(pmd_t), - 0, + SLAB_BC, pmd_ctor, NULL); if (!pmd_cache) @@ -718,7 +718,7 @@ void __init pgtable_cache_init(void) pgd_cache = kmem_cache_create("pgd", PTRS_PER_PGD*sizeof(pgd_t), PTRS_PER_PGD*sizeof(pgd_t), - 0, + SLAB_BC, pgd_ctor, PTRS_PER_PMD…
creator: dev
date: 2006-10-05T15:53:10-00:00

[PATCH 8/10] BC: private pages (mappings) accounting (core)
type: item
description: Accounting of private pages. Accounting is performed on mmap per vma. When mm changes its BC, vmas are not recharged. On mlock and mprotect vma status may change from BC point of view, so recharging is done accordingly. See definition of private pages at http://wiki.openvz.org/User_pages_accounting Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: Kirill Korotaev <dev@openvz.org> --- include/bc/vmpages.h | 90 ++++++++++++++++++++++++++++++++ include/linux/mm.h | 3 + include/linux/sched.h | 3 + kernel/bc/vmpages.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 234 insertions(+) --- /dev/null 2006-07-18 14:52:43.075228448 +0400 +++ ./include/bc/vmpages.h 2006-10-05 12:19:59.000000000 +0400 @@ -0,0 +1,90 @@ +/* + * include/bc/vmpages.h + * + * Copyright (C) 2006 OpenVZ SWsoft Inc + * + */ + +#ifndef __BC_VMPAGES_H_ +#define __BC_VMPAGES_H_ + +#include <bc/beancounter.h> + +struct vm_area_struct; +struct mm_struct; +struct file; + +#define BC_NOCHARGE 0 +#define BC_UNCHARGE 1 +#define BC_CHARGE 2 + +#ifdef CONFIG_BEANCOUNTERS +#define __vma_set_bc(vma, bc) do { (vma)->vma_bc = bc_get(bc); } while (0) +#define vma_set_bc(vma) __vma_set_bc(vma, (vma)->vm_mm->mm_bc) +#define vma_copy_bc(vma) __vma_set_bc(vma, (vma)->vma_bc) +#define vma_release_bc(vma) do { bc_put((vma)->vma_bc); } while (0) + +#define mm_init_beancounter(mm) do { \ + struct beancounter *bc; \ + bc = get_exec_bc(); \ + (mm)->mm_bc = bc_get(bc); \ + } while (0) +#define mm_free_beancounter(mm) do { bc_put(mm->mm_bc); } while (0) + +int __must_check bc_need_memory_recharge(struct vm_area_struct *vma, + struct file *new_file, unsigned long new_flags); + +int __must_check __bc_memory_charge(struct mm_struct *mm, unsigned long len, + int severity); +int __must_check bc_memory_charge(struct mm_struct *mm, unsigned long len, + struct file *file, unsigned long flags, int severity); +int __must_check bc_vma_charge(struct vm_area_struct *vma); + +void __bc_memory_uncharge(st…
creator: dev
date: 2006-10-05T15:54:25-00:00

[PATCH 9/10] BC: physical pages accounting/reclamation (core)
type: item
description: Accounting of physical pages. Accounting is performed on page mapping into address space. If page is shared, it is charged to its first user. If physpages limit is hit, BC pages are reclaimed on the same basis as try_to_free_pages() does. Full BC implementation allows fractions of pages accounting as well: http://wiki.openvz.org/RSS_fractions_accounting Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: Kirill Korotaev <dev@openvz.org> --- include/bc/rsspages.h | 46 +++++++ include/linux/mm.h | 1 include/linux/mm_types.h | 5 include/linux/page-flags.h | 4 kernel/bc/rsspages.c | 270 +++++++++++++++++++++++++++++++++++++++++++++ mm/vmscan.c | 190 +++++++++++++++++++++++++++++++ 6 files changed, 515 insertions(+), 1 deletion(-) --- ./include/bc/rsspages.h.bc_rsspages 2006-10-05 12:20:42.000000000 +0400 +++ ./include/bc/rsspages.h 2006-10-05 12:35:57.000000000 +0400 @@ -0,0 +1,46 @@ +/* + * include/bc/rsspages.h + * + * Copyright (C) 2006 OpenVZ SWsoft Inc + * + */ + +#ifndef __BC_RSSPAGES_H_ +#define __BC_RSSPAGES_H_ + +#include <linux/compiler.h> + +struct page; +struct vm_area_struct; +struct page_beancounter; + +#ifdef CONFIG_BEANCOUNTERS +int __must_check bc_rsspage_prepare(struct page *p, + struct vm_area_struct *vma, struct page_beancounter **ppb); +void bc_rsspage_charge(struct page_beancounter *pb); +void bc_rsspage_release(struct page_beancounter *pb); +void bc_rsspage_uncharge(struct page *p); + +unsigned long bc_try_to_free_pages(struct beancounter *bc); +unsigned long bc_isolate_pages(unsigned long nr_to_scan, + struct beancounter *bc, struct list_head *dst, + int active, unsigned long *scanned); +unsigned long bc_nr_physpages(struct beancounter *bc); +#else +static inline int __must_check bc_rsspage_prepare(struct page *p, + struct vm_area_struct *vma, struct page_beancounter **ppb) +{ + return 0; +} + +static inline void bc_rsspage_charge(struct page_beancounter *pb) +{ +} +static inline void bc_rsspage_release(struct page_beancounter *pb) +…
creator: Kirill Korotaev
date: 2006-10-05T15:55:40-00:00

[PATCH 10/10] BC: user memory accounting (hooks)
type: item
description: Install BC hooks in appropriate places for user memory accounting. Signed-off-by: Pavel Emelianov <xemul@openvz.org> Signed-off-by: Kirill Korotaev <dev@openvz.org> --- fs/binfmt_elf.c | 5 +-- fs/exec.c | 14 +++++++- include/asm-alpha/mman.h | 1 include/asm-generic/mman.h | 1 include/asm-mips/mman.h | 1 include/asm-parisc/mman.h | 1 include/asm-xtensa/mman.h | 1 kernel/fork.c | 11 ++++++ mm/fremap.c | 10 ++++++ mm/memory.c | 40 +++++++++++++++++++++++- mm/migrate.c | 10 ++++++ mm/mlock.c | 16 +++++++++ mm/mmap.c | 74 ++++++++++++++++++++++++++++++++++++++------- mm/mprotect.c | 18 ++++++++++ mm/mremap.c | 22 ++++++++++--- mm/rmap.c | 3 + mm/shmem.c | 15 +++++++++ 17 files changed, 219 insertions(+), 24 deletions(-) --- ./fs/binfmt_elf.c.bc_userpages 2006-10-05 11:42:42.000000000 +0400 +++ ./fs/binfmt_elf.c 2006-10-05 12:44:20.000000000 +0400 @@ -360,7 +360,7 @@ static unsigned long load_elf_interp(str eppnt = elf_phdata; for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) { if (eppnt->p_type == PT_LOAD) { - int elf_type = MAP_PRIVATE | MAP_DENYWRITE; + int elf_type = MAP_PRIVATE|MAP_DENYWRITE|MAP_EXECPRIO; int elf_prot = 0; unsigned long vaddr = 0; unsigned long k, map_addr; @@ -846,7 +846,8 @@ static int load_elf_binary(struct linux_ if (elf_ppnt->p_flags & PF_X) elf_prot |= PROT_EXEC; - elf_flags = MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE; + elf_flags = MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE | + MAP_EXECPRIO; vaddr = elf_ppnt->p_vaddr; if (loc->elf_ex.e_type == ET_EXEC || load_addr_set) { --- ./fs/exec.c.bc_userpages 2006-10-05 11:42:42.000000000 +0400 +++ ./fs/exec.c 2006-10-05 12:44:20.000000000 +0400 @@ -50,6 +50,8 @@ #include <linux/cn_proc.h> #include <linux/audit.h> +#include <bc/rsspages.h> + #include <asm/uaccess.h> #include <asm/mmu_context.h> @@ -308,27 +310,35 @@ void install_arg_page(struct vm_area_str struct mm_struct *mm = vma->vm_mm; pte_t * pte; spinlock_t *ptl; + struct page_beancounter *pc; if (unlikely(anon_vma_prepare(vma))) goto ou…
creator: Kirill Korotaev
date: 2006-10-05T15:56:50-00:00

[TOOL] BC: bcctl.c
type: item
description: Utility (bcctl) usage and examples: Usage: bcctl <cmd> [args...] Commands: get gets current bc id enter <id> [<pid>] moves task into bc. if no pid - moves parent task stat <id> [<resource>] prints stats for bc's resource. if no resource - prints all resources set <id> <resource> <barrier> [<limit>] sets barrier/limit for bc's resource if no limit - it is set equal to barrier Resources: kmemsize privvmpages physpages Examples: Move shell into beancounter $ bcctl enter 1 Look statistics $ bcctl stat 1 resource held minheld maxheld barrier limit failcnt kmemsize 824 0 1056 65536 65536 0 privvmpages 100 0 304 2147483647 2147483647 0 physpages 40 0 150 2147483647 2147483647 0 See how reclamation work $ bcctl set 1 physpages 200 $ memeat $ bcctl stat 1 physpages resource held minheld maxheld barrier limit failcnt physpages 40 0 200 200 200 0 Now turn swap off and run memeater again $ swapoff -a $ memeat Killed $ bcctl stat 1 physpages resource held minheld maxheld barrier limit failcnt physpages 41 0 200 200 200 1 --- #include <sys/syscall.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> typedef unsigned int bcid_t; #include "bc/beancounter.h" #define get_bcid() (syscall(__NR_get_bcid)) #define set_bcid(id, pid) (syscall(__NR_set_bcid, id, pid)) #define set_bclimit(id, res, l) (syscall(__NR_set_bclimit, id, res, l)) #define get_bcstat(id, res, s) (syscall(__NR_get_bcstat, id, res, s)) static char *res_names[] = { "kmemsize", "privvmpages", "physpages", NULL, }; static int bc_get_id(int argc, char **argv) { bcid_t id; id = get_bcid(); printf("%u\n", id); return 0; } static int bc_enter_id(int argc, char **argv) { bcid_t id; pid_t pid; char *end; int ret; if (argc < 1) return -2; id = strtol(argv[0], &end, 10); if (*end != '\0') return -2; if (argc > 1) { pid = strtol(argv[1], &end, 10); if (*end != '\0') return -2; } else pid = getppid(); ret = set_bcid(id, pid); if (ret < 0) perror("Can't set bcid"); return ret; } static int bc_set_parms(int argc, char **argv…
creator: Kirill Korotaev
date: 2006-10-05T15:59:20-00:00