Re: [PATCH -mmotm 2/3] memcg: dirty pages accounting and limiting infrastructure

From: Kirill A. Shutemov
Date: Tue Mar 02 2010 - 05:05:04 EST


On Mon, Mar 1, 2010 at 11:23 PM, Andrea Righi <arighi@xxxxxxxxxxx> wrote:
> Infrastructure to account dirty pages per cgroup and add dirty limit
> interfaces in the cgroupfs:
>
> Â- Direct write-out: memory.dirty_ratio, memory.dirty_bytes
>
> Â- Background write-out: memory.dirty_background_ratio, memory.dirty_background_bytes
>
> Signed-off-by: Andrea Righi <arighi@xxxxxxxxxxx>
> ---
> Âinclude/linux/memcontrol.h | Â 77 ++++++++++-
> Âmm/memcontrol.c      Â| Â336 ++++++++++++++++++++++++++++++++++++++++----
> Â2 files changed, 384 insertions(+), 29 deletions(-)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 1f9b119..cc88b2e 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -19,12 +19,50 @@
>
> Â#ifndef _LINUX_MEMCONTROL_H
> Â#define _LINUX_MEMCONTROL_H
> +
> +#include <linux/writeback.h>
> Â#include <linux/cgroup.h>
> +
> Âstruct mem_cgroup;
> Âstruct page_cgroup;
> Âstruct page;
> Âstruct mm_struct;
>
> +/* Cgroup memory statistics items exported to the kernel */
> +enum mem_cgroup_page_stat_item {
> + Â Â Â MEMCG_NR_DIRTYABLE_PAGES,
> + Â Â Â MEMCG_NR_RECLAIM_PAGES,
> + Â Â Â MEMCG_NR_WRITEBACK,
> + Â Â Â MEMCG_NR_DIRTY_WRITEBACK_PAGES,
> +};
> +
> +/*
> + * Statistics for memory cgroup.
> + */
> +enum mem_cgroup_stat_index {
> + Â Â Â /*
> + Â Â Â Â* For MEM_CONTAINER_TYPE_ALL, usage = pagecache + rss.
> + Â Â Â Â*/
> + Â Â Â MEM_CGROUP_STAT_CACHE, Â Â /* # of pages charged as cache */
> + Â Â Â MEM_CGROUP_STAT_RSS, Â Â Â /* # of pages charged as anon rss */
> + Â Â Â MEM_CGROUP_STAT_FILE_MAPPED, Â/* # of pages charged as file rss */
> + Â Â Â MEM_CGROUP_STAT_PGPGIN_COUNT, Â /* # of pages paged in */
> + Â Â Â MEM_CGROUP_STAT_PGPGOUT_COUNT, Â/* # of pages paged out */
> + Â Â Â MEM_CGROUP_STAT_EVENTS, /* sum of pagein + pageout for internal use */
> + Â Â Â MEM_CGROUP_STAT_SWAPOUT, /* # of pages, swapped out */
> + Â Â Â MEM_CGROUP_STAT_SOFTLIMIT, /* decrements on each page in/out.
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â used by soft limit implementation */
> + Â Â Â MEM_CGROUP_STAT_THRESHOLDS, /* decrements on each page in/out.
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â used by threshold implementation */
> + Â Â Â MEM_CGROUP_STAT_FILE_DIRTY, Â /* # of dirty pages in page cache */
> + Â Â Â MEM_CGROUP_STAT_WRITEBACK, Â /* # of pages under writeback */
> + Â Â Â MEM_CGROUP_STAT_WRITEBACK_TEMP, Â /* # of pages under writeback using
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â temporary buffers */
> + Â Â Â MEM_CGROUP_STAT_UNSTABLE_NFS, Â /* # of NFS unstable pages */
> +
> + Â Â Â MEM_CGROUP_STAT_NSTATS,
> +};
> +
> Â#ifdef CONFIG_CGROUP_MEM_RES_CTLR
> Â/*
> Â* All "charge" functions with gfp_mask should use GFP_KERNEL or
> @@ -117,6 +155,13 @@ extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
> Âextern int do_swap_account;
> Â#endif
>
> +extern long mem_cgroup_dirty_ratio(void);
> +extern unsigned long mem_cgroup_dirty_bytes(void);
> +extern long mem_cgroup_dirty_background_ratio(void);
> +extern unsigned long mem_cgroup_dirty_background_bytes(void);
> +
> +extern s64 mem_cgroup_page_stat(enum mem_cgroup_page_stat_item item);
> +
> Âstatic inline bool mem_cgroup_disabled(void)
> Â{
> Â Â Â Âif (mem_cgroup_subsys.disabled)
> @@ -125,7 +170,8 @@ static inline bool mem_cgroup_disabled(void)
> Â}
>
> Âextern bool mem_cgroup_oom_called(struct task_struct *task);
> -void mem_cgroup_update_file_mapped(struct page *page, int val);
> +void mem_cgroup_update_stat(struct page *page,
> + Â Â Â Â Â Â Â Â Â Â Â enum mem_cgroup_stat_index idx, int val);
> Âunsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âgfp_t gfp_mask, int nid,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âint zid);
> @@ -300,8 +346,8 @@ mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
> Â{
> Â}
>
> -static inline void mem_cgroup_update_file_mapped(struct page *page,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â int val)
> +static inline void mem_cgroup_update_stat(struct page *page,
> + Â Â Â Â Â Â Â Â Â Â Â enum mem_cgroup_stat_index idx, int val)
> Â{
> Â}
>
> @@ -312,6 +358,31 @@ unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
> Â Â Â Âreturn 0;
> Â}
>
> +static inline long mem_cgroup_dirty_ratio(void)
> +{
> + Â Â Â return vm_dirty_ratio;
> +}
> +
> +static inline unsigned long mem_cgroup_dirty_bytes(void)
> +{
> + Â Â Â return vm_dirty_bytes;
> +}
> +
> +static inline long mem_cgroup_dirty_background_ratio(void)
> +{
> + Â Â Â return dirty_background_ratio;
> +}
> +
> +static inline unsigned long mem_cgroup_dirty_background_bytes(void)
> +{
> + Â Â Â return dirty_background_bytes;
> +}
> +
> +static inline s64 mem_cgroup_page_stat(enum mem_cgroup_page_stat_item item)
> +{
> + Â Â Â return -ENOMEM;

Why ENOMEM? Probably, EINVAL or ENOSYS?

> +}
> +
> Â#endif /* CONFIG_CGROUP_MEM_CONT */
>
> Â#endif /* _LINUX_MEMCONTROL_H */
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index a443c30..e74cf66 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -66,31 +66,16 @@ static int really_do_swap_account __initdata = 1; /* for remember boot option*/
> Â#define SOFTLIMIT_EVENTS_THRESH (1000)
> Â#define THRESHOLDS_EVENTS_THRESH (100)
>
> -/*
> - * Statistics for memory cgroup.
> - */
> -enum mem_cgroup_stat_index {
> - Â Â Â /*
> - Â Â Â Â* For MEM_CONTAINER_TYPE_ALL, usage = pagecache + rss.
> - Â Â Â Â*/
> - Â Â Â MEM_CGROUP_STAT_CACHE, Â Â /* # of pages charged as cache */
> - Â Â Â MEM_CGROUP_STAT_RSS, Â Â Â /* # of pages charged as anon rss */
> - Â Â Â MEM_CGROUP_STAT_FILE_MAPPED, Â/* # of pages charged as file rss */
> - Â Â Â MEM_CGROUP_STAT_PGPGIN_COUNT, Â /* # of pages paged in */
> - Â Â Â MEM_CGROUP_STAT_PGPGOUT_COUNT, Â/* # of pages paged out */
> - Â Â Â MEM_CGROUP_STAT_SWAPOUT, /* # of pages, swapped out */
> - Â Â Â MEM_CGROUP_STAT_SOFTLIMIT, /* decrements on each page in/out.
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â used by soft limit implementation */
> - Â Â Â MEM_CGROUP_STAT_THRESHOLDS, /* decrements on each page in/out.
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â used by threshold implementation */
> -
> - Â Â Â MEM_CGROUP_STAT_NSTATS,
> -};
> -
> Âstruct mem_cgroup_stat_cpu {
> Â Â Â Âs64 count[MEM_CGROUP_STAT_NSTATS];
> Â};
>
> +/* Per cgroup page statistics */
> +struct mem_cgroup_page_stat {
> + Â Â Â enum mem_cgroup_page_stat_item item;
> + Â Â Â s64 value;
> +};
> +
> Â/*
> Â* per-zone information in memory controller.
> Â*/
> @@ -157,6 +142,15 @@ struct mem_cgroup_threshold_ary {
> Âstatic bool mem_cgroup_threshold_check(struct mem_cgroup *mem);
> Âstatic void mem_cgroup_threshold(struct mem_cgroup *mem);
>
> +enum mem_cgroup_dirty_param {
> + Â Â Â MEM_CGROUP_DIRTY_RATIO,
> + Â Â Â MEM_CGROUP_DIRTY_BYTES,
> + Â Â Â MEM_CGROUP_DIRTY_BACKGROUND_RATIO,
> + Â Â Â MEM_CGROUP_DIRTY_BACKGROUND_BYTES,
> +
> + Â Â Â MEM_CGROUP_DIRTY_NPARAMS,
> +};
> +
> Â/*
> Â* The memory controller data structure. The memory controller controls both
> Â* page cache and RSS per cgroup. We would eventually like to provide
> @@ -205,6 +199,9 @@ struct mem_cgroup {
>
>    Âunsigned int  Âswappiness;
>
> + Â Â Â /* control memory cgroup dirty pages */
> + Â Â Â unsigned long dirty_param[MEM_CGROUP_DIRTY_NPARAMS];
> +
> Â Â Â Â/* set when res.limit == memsw.limit */
>    Âbool      Âmemsw_is_minimum;
>
> @@ -1021,6 +1018,164 @@ static unsigned int get_swappiness(struct mem_cgroup *memcg)
> Â Â Â Âreturn swappiness;
> Â}
>
> +static unsigned long get_dirty_param(struct mem_cgroup *memcg,
> + Â Â Â Â Â Â Â Â Â Â Â enum mem_cgroup_dirty_param idx)
> +{
> + Â Â Â unsigned long ret;
> +
> + Â Â Â VM_BUG_ON(idx >= MEM_CGROUP_DIRTY_NPARAMS);
> + Â Â Â spin_lock(&memcg->reclaim_param_lock);
> + Â Â Â ret = memcg->dirty_param[idx];
> + Â Â Â spin_unlock(&memcg->reclaim_param_lock);
> +
> + Â Â Â return ret;
> +}
> +
> +long mem_cgroup_dirty_ratio(void)
> +{
> + Â Â Â struct mem_cgroup *memcg;
> + Â Â Â long ret = vm_dirty_ratio;
> +
> + Â Â Â if (mem_cgroup_disabled())
> + Â Â Â Â Â Â Â return ret;
> + Â Â Â /*
> + Â Â Â Â* It's possible that "current" may be moved to other cgroup while we
> + Â Â Â Â* access cgroup. But precise check is meaningless because the task can
> + Â Â Â Â* be moved after our access and writeback tends to take long time.
> + Â Â Â Â* At least, "memcg" will not be freed under rcu_read_lock().
> + Â Â Â Â*/
> + Â Â Â rcu_read_lock();
> + Â Â Â memcg = mem_cgroup_from_task(current);
> + Â Â Â if (likely(memcg))
> + Â Â Â Â Â Â Â ret = get_dirty_param(memcg, MEM_CGROUP_DIRTY_RATIO);
> + Â Â Â rcu_read_unlock();
> +
> + Â Â Â return ret;
> +}
> +
> +unsigned long mem_cgroup_dirty_bytes(void)
> +{
> + Â Â Â struct mem_cgroup *memcg;
> + Â Â Â unsigned long ret = vm_dirty_bytes;
> +
> + Â Â Â if (mem_cgroup_disabled())
> + Â Â Â Â Â Â Â return ret;
> + Â Â Â rcu_read_lock();
> + Â Â Â memcg = mem_cgroup_from_task(current);
> + Â Â Â if (likely(memcg))
> + Â Â Â Â Â Â Â ret = get_dirty_param(memcg, MEM_CGROUP_DIRTY_BYTES);
> + Â Â Â rcu_read_unlock();
> +
> + Â Â Â return ret;
> +}
> +
> +long mem_cgroup_dirty_background_ratio(void)
> +{
> + Â Â Â struct mem_cgroup *memcg;
> + Â Â Â long ret = dirty_background_ratio;
> +
> + Â Â Â if (mem_cgroup_disabled())
> + Â Â Â Â Â Â Â return ret;
> + Â Â Â rcu_read_lock();
> + Â Â Â memcg = mem_cgroup_from_task(current);
> + Â Â Â if (likely(memcg))
> + Â Â Â Â Â Â Â ret = get_dirty_param(memcg, MEM_CGROUP_DIRTY_BACKGROUND_RATIO);
> + Â Â Â rcu_read_unlock();
> +
> + Â Â Â return ret;
> +}
> +
> +unsigned long mem_cgroup_dirty_background_bytes(void)
> +{
> + Â Â Â struct mem_cgroup *memcg;
> + Â Â Â unsigned long ret = dirty_background_bytes;
> +
> + Â Â Â if (mem_cgroup_disabled())
> + Â Â Â Â Â Â Â return ret;
> + Â Â Â rcu_read_lock();
> + Â Â Â memcg = mem_cgroup_from_task(current);
> + Â Â Â if (likely(memcg))
> + Â Â Â Â Â Â Â ret = get_dirty_param(memcg, MEM_CGROUP_DIRTY_BACKGROUND_BYTES);
> + Â Â Â rcu_read_unlock();
> +
> + Â Â Â return ret;
> +}
> +
> +static inline bool mem_cgroup_can_swap(struct mem_cgroup *memcg)
> +{
> + Â Â Â return do_swap_account ?
> + Â Â Â Â Â Â Â Â Â Â Â res_counter_read_u64(&memcg->memsw, RES_LIMIT) :
> + Â Â Â Â Â Â Â Â Â Â Â nr_swap_pages > 0;
> +}
> +
> +static s64 mem_cgroup_get_local_page_stat(struct mem_cgroup *memcg,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â enum mem_cgroup_page_stat_item item)
> +{
> + Â Â Â s64 ret;
> +
> + Â Â Â switch (item) {
> + Â Â Â case MEMCG_NR_DIRTYABLE_PAGES:
> + Â Â Â Â Â Â Â ret = res_counter_read_u64(&memcg->res, RES_LIMIT) -
> + Â Â Â Â Â Â Â Â Â Â Â res_counter_read_u64(&memcg->res, RES_USAGE);
> + Â Â Â Â Â Â Â /* Translate free memory in pages */
> + Â Â Â Â Â Â Â ret >>= PAGE_SHIFT;
> + Â Â Â Â Â Â Â ret += mem_cgroup_read_stat(memcg, LRU_ACTIVE_FILE) +
> + Â Â Â Â Â Â Â Â Â Â Â mem_cgroup_read_stat(memcg, LRU_INACTIVE_FILE);
> + Â Â Â Â Â Â Â if (mem_cgroup_can_swap(memcg))
> + Â Â Â Â Â Â Â Â Â Â Â ret += mem_cgroup_read_stat(memcg, LRU_ACTIVE_ANON) +
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â mem_cgroup_read_stat(memcg, LRU_INACTIVE_ANON);
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEMCG_NR_RECLAIM_PAGES:
> + Â Â Â Â Â Â Â ret = mem_cgroup_read_stat(memcg, MEM_CGROUP_STAT_FILE_DIRTY) +
> + Â Â Â Â Â Â Â Â Â Â Â mem_cgroup_read_stat(memcg,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MEM_CGROUP_STAT_UNSTABLE_NFS);
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEMCG_NR_WRITEBACK:
> + Â Â Â Â Â Â Â ret = mem_cgroup_read_stat(memcg, MEM_CGROUP_STAT_WRITEBACK);
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEMCG_NR_DIRTY_WRITEBACK_PAGES:
> + Â Â Â Â Â Â Â ret = mem_cgroup_read_stat(memcg, MEM_CGROUP_STAT_WRITEBACK) +
> + Â Â Â Â Â Â Â Â Â Â Â mem_cgroup_read_stat(memcg,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MEM_CGROUP_STAT_UNSTABLE_NFS);
> + Â Â Â Â Â Â Â break;
> + Â Â Â default:
> + Â Â Â Â Â Â Â ret = 0;
> + Â Â Â Â Â Â Â WARN_ON_ONCE(1);

I think it's a bug, not warning.

> + Â Â Â }
> + Â Â Â return ret;
> +}
> +
> +static int mem_cgroup_page_stat_cb(struct mem_cgroup *mem, void *data)
> +{
> + Â Â Â struct mem_cgroup_page_stat *stat = (struct mem_cgroup_page_stat *)data;
> +
> + Â Â Â stat->value += mem_cgroup_get_local_page_stat(mem, stat->item);
> + Â Â Â return 0;
> +}
> +
> +s64 mem_cgroup_page_stat(enum mem_cgroup_page_stat_item item)
> +{
> + Â Â Â struct mem_cgroup_page_stat stat = {};
> + Â Â Â struct mem_cgroup *memcg;
> +
> + Â Â Â if (mem_cgroup_disabled())
> + Â Â Â Â Â Â Â return -ENOMEM;

EINVAL/ENOSYS?

> + Â Â Â rcu_read_lock();
> + Â Â Â memcg = mem_cgroup_from_task(current);
> + Â Â Â if (memcg) {
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* Recursively evaulate page statistics against all cgroup
> + Â Â Â Â Â Â Â Â* under hierarchy tree
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â stat.item = item;
> + Â Â Â Â Â Â Â mem_cgroup_walk_tree(memcg, &stat, mem_cgroup_page_stat_cb);
> + Â Â Â } else
> + Â Â Â Â Â Â Â stat.value = -ENOMEM;

ditto.

> + Â Â Â rcu_read_unlock();
> +
> + Â Â Â return stat.value;
> +}
> +
> Âstatic int mem_cgroup_count_children_cb(struct mem_cgroup *mem, void *data)
> Â{
> Â Â Â Âint *val = data;
> @@ -1263,14 +1418,16 @@ static void record_last_oom(struct mem_cgroup *mem)
> Â}
>
> Â/*
> - * Currently used to update mapped file statistics, but the routine can be
> - * generalized to update other statistics as well.
> + * Generalized routine to update memory cgroup statistics.
> Â*/
> -void mem_cgroup_update_file_mapped(struct page *page, int val)
> +void mem_cgroup_update_stat(struct page *page,
> + Â Â Â Â Â Â Â Â Â Â Â enum mem_cgroup_stat_index idx, int val)

EXPORT_SYMBOL_GPL(mem_cgroup_update_stat) is needed, since
it uses by filesystems.

> Â{
> Â Â Â Âstruct mem_cgroup *mem;
> Â Â Â Âstruct page_cgroup *pc;
>
> + Â Â Â if (mem_cgroup_disabled())
> + Â Â Â Â Â Â Â return;
> Â Â Â Âpc = lookup_page_cgroup(page);
> Â Â Â Âif (unlikely(!pc))
> Â Â Â Â Â Â Â Âreturn;
> @@ -1286,7 +1443,8 @@ void mem_cgroup_update_file_mapped(struct page *page, int val)
> Â Â Â Â/*
> Â Â Â Â * Preemption is already disabled. We can use __this_cpu_xxx
> Â Â Â Â */
> - Â Â Â __this_cpu_add(mem->stat->count[MEM_CGROUP_STAT_FILE_MAPPED], val);
> + Â Â Â VM_BUG_ON(idx >= MEM_CGROUP_STAT_NSTATS);
> + Â Â Â __this_cpu_add(mem->stat->count[idx], val);
>
> Âdone:
> Â Â Â Âunlock_page_cgroup(pc);
> @@ -3033,6 +3191,10 @@ enum {
> Â Â Â ÂMCS_PGPGIN,
> Â Â Â ÂMCS_PGPGOUT,
> Â Â Â ÂMCS_SWAP,
> + Â Â Â MCS_FILE_DIRTY,
> + Â Â Â MCS_WRITEBACK,
> + Â Â Â MCS_WRITEBACK_TEMP,
> + Â Â Â MCS_UNSTABLE_NFS,
> Â Â Â ÂMCS_INACTIVE_ANON,
> Â Â Â ÂMCS_ACTIVE_ANON,
> Â Â Â ÂMCS_INACTIVE_FILE,
> @@ -3055,6 +3217,10 @@ struct {
> Â Â Â Â{"pgpgin", "total_pgpgin"},
> Â Â Â Â{"pgpgout", "total_pgpgout"},
> Â Â Â Â{"swap", "total_swap"},
> + Â Â Â {"filedirty", "dirty_pages"},
> + Â Â Â {"writeback", "writeback_pages"},
> + Â Â Â {"writeback_tmp", "writeback_temp_pages"},
> + Â Â Â {"nfs", "nfs_unstable"},
> Â Â Â Â{"inactive_anon", "total_inactive_anon"},
> Â Â Â Â{"active_anon", "total_active_anon"},
> Â Â Â Â{"inactive_file", "total_inactive_file"},
> @@ -3083,6 +3249,14 @@ static int mem_cgroup_get_local_stat(struct mem_cgroup *mem, void *data)
> Â Â Â Â Â Â Â Âval = mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_SWAPOUT);
> Â Â Â Â Â Â Â Âs->stat[MCS_SWAP] += val * PAGE_SIZE;
> Â Â Â Â}
> + Â Â Â val = mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_DIRTY);
> + Â Â Â s->stat[MCS_FILE_DIRTY] += val;
> + Â Â Â val = mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_WRITEBACK);
> + Â Â Â s->stat[MCS_WRITEBACK] += val;
> + Â Â Â val = mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_WRITEBACK_TEMP);
> + Â Â Â s->stat[MCS_WRITEBACK_TEMP] += val;
> + Â Â Â val = mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_UNSTABLE_NFS);
> + Â Â Â s->stat[MCS_UNSTABLE_NFS] += val;
>
> Â Â Â Â/* per zone stat */
> Â Â Â Âval = mem_cgroup_get_local_zonestat(mem, LRU_INACTIVE_ANON);
> @@ -3467,6 +3641,50 @@ unlock:
> Â Â Â Âreturn ret;
> Â}
>
> +static u64 mem_cgroup_dirty_read(struct cgroup *cgrp, struct cftype *cft)
> +{
> + Â Â Â struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> + Â Â Â int type = cft->private;
> +
> + Â Â Â return get_dirty_param(memcg, type);
> +}
> +
> +static int
> +mem_cgroup_dirty_write(struct cgroup *cgrp, struct cftype *cft, u64 val)
> +{
> + Â Â Â struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> + Â Â Â int type = cft->private;
> +
> + Â Â Â if (cgrp->parent == NULL)
> + Â Â Â Â Â Â Â return -EINVAL;
> + Â Â Â if (((type == MEM_CGROUP_DIRTY_RATIO) ||
> + Â Â Â Â Â Â Â (type == MEM_CGROUP_DIRTY_BACKGROUND_RATIO)) && (val > 100))

Too many unnecessary brackets

if ((type == MEM_CGROUP_DIRTY_RATIO ||
type == MEM_CGROUP_DIRTY_BACKGROUND_RATIO) && val > 100)

> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â spin_lock(&memcg->reclaim_param_lock);
> + Â Â Â switch (type) {
> + Â Â Â case MEM_CGROUP_DIRTY_RATIO:
> + Â Â Â Â Â Â Â memcg->dirty_param[MEM_CGROUP_DIRTY_RATIO] = val;
> + Â Â Â Â Â Â Â memcg->dirty_param[MEM_CGROUP_DIRTY_BYTES] = 0;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEM_CGROUP_DIRTY_BYTES:
> + Â Â Â Â Â Â Â memcg->dirty_param[MEM_CGROUP_DIRTY_RATIO] = 0;
> + Â Â Â Â Â Â Â memcg->dirty_param[MEM_CGROUP_DIRTY_BYTES] = val;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEM_CGROUP_DIRTY_BACKGROUND_RATIO:
> + Â Â Â Â Â Â Â memcg->dirty_param[MEM_CGROUP_DIRTY_BACKGROUND_RATIO] = val;
> + Â Â Â Â Â Â Â memcg->dirty_param[MEM_CGROUP_DIRTY_BACKGROUND_BYTES] = 0;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEM_CGROUP_DIRTY_BACKGROUND_BYTES:
> + Â Â Â Â Â Â Â memcg->dirty_param[MEM_CGROUP_DIRTY_BACKGROUND_RATIO] = 0;
> + Â Â Â Â Â Â Â memcg->dirty_param[MEM_CGROUP_DIRTY_BACKGROUND_BYTES] = val;
> + Â Â Â Â Â Â Â break;
> + Â Â Â }
> + Â Â Â spin_unlock(&memcg->reclaim_param_lock);
> +
> + Â Â Â return 0;
> +}
> +
> Âstatic struct cftype mem_cgroup_files[] = {
> Â Â Â Â{
> Â Â Â Â Â Â Â Â.name = "usage_in_bytes",
> @@ -3518,6 +3736,30 @@ static struct cftype mem_cgroup_files[] = {
> Â Â Â Â Â Â Â Â.write_u64 = mem_cgroup_swappiness_write,
> Â Â Â Â},
> Â Â Â Â{
> + Â Â Â Â Â Â Â .name = "dirty_ratio",
> + Â Â Â Â Â Â Â .read_u64 = mem_cgroup_dirty_read,
> + Â Â Â Â Â Â Â .write_u64 = mem_cgroup_dirty_write,
> + Â Â Â Â Â Â Â .private = MEM_CGROUP_DIRTY_RATIO,
> + Â Â Â },
> + Â Â Â {
> + Â Â Â Â Â Â Â .name = "dirty_bytes",
> + Â Â Â Â Â Â Â .read_u64 = mem_cgroup_dirty_read,
> + Â Â Â Â Â Â Â .write_u64 = mem_cgroup_dirty_write,
> + Â Â Â Â Â Â Â .private = MEM_CGROUP_DIRTY_BYTES,
> + Â Â Â },
> + Â Â Â {
> + Â Â Â Â Â Â Â .name = "dirty_background_ratio",
> + Â Â Â Â Â Â Â .read_u64 = mem_cgroup_dirty_read,
> + Â Â Â Â Â Â Â .write_u64 = mem_cgroup_dirty_write,
> + Â Â Â Â Â Â Â .private = MEM_CGROUP_DIRTY_BACKGROUND_RATIO,
> + Â Â Â },
> + Â Â Â {
> + Â Â Â Â Â Â Â .name = "dirty_background_bytes",
> + Â Â Â Â Â Â Â .read_u64 = mem_cgroup_dirty_read,
> + Â Â Â Â Â Â Â .write_u64 = mem_cgroup_dirty_write,
> + Â Â Â Â Â Â Â .private = MEM_CGROUP_DIRTY_BACKGROUND_BYTES,
> + Â Â Â },
> + Â Â Â {
> Â Â Â Â Â Â Â Â.name = "move_charge_at_immigrate",
> Â Â Â Â Â Â Â Â.read_u64 = mem_cgroup_move_charge_read,
> Â Â Â Â Â Â Â Â.write_u64 = mem_cgroup_move_charge_write,
> @@ -3725,6 +3967,19 @@ static int mem_cgroup_soft_limit_tree_init(void)
> Â Â Â Âreturn 0;
> Â}
>
> +/*
> + * NOTE: called only with &src->reclaim_param_lock held from
> + * mem_cgroup_create().
> + */
> +static inline void
> +copy_dirty_params(struct mem_cgroup *dst, struct mem_cgroup *src)
> +{
> + Â Â Â int i;
> +
> + Â Â Â for (i = 0; i < MEM_CGROUP_DIRTY_NPARAMS; i++)
> + Â Â Â Â Â Â Â dst->dirty_param[i] = src->dirty_param[i];
> +}
> +
> Âstatic struct cgroup_subsys_state * __ref
> Âmem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
> Â{
> @@ -3776,8 +4031,37 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
> Â Â Â Âmem->last_scanned_child = 0;
> Â Â Â Âspin_lock_init(&mem->reclaim_param_lock);
>
> - Â Â Â if (parent)
> + Â Â Â if (parent) {
> Â Â Â Â Â Â Â Âmem->swappiness = get_swappiness(parent);
> +
> + Â Â Â Â Â Â Â spin_lock(&parent->reclaim_param_lock);
> + Â Â Â Â Â Â Â copy_dirty_params(mem, parent);
> + Â Â Â Â Â Â Â spin_unlock(&parent->reclaim_param_lock);
> + Â Â Â } else {
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* XXX: should we need a lock here? we could switch from
> + Â Â Â Â Â Â Â Â* vm_dirty_ratio to vm_dirty_bytes or vice versa but we're not
> + Â Â Â Â Â Â Â Â* reading them atomically. The same for dirty_background_ratio
> + Â Â Â Â Â Â Â Â* and dirty_background_bytes.
> + Â Â Â Â Â Â Â Â*
> + Â Â Â Â Â Â Â Â* For now, try to read them speculatively and retry if a
> + Â Â Â Â Â Â Â Â* "conflict" is detected.
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â do {
> + Â Â Â Â Â Â Â Â Â Â Â mem->dirty_param[MEM_CGROUP_DIRTY_RATIO] =
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â vm_dirty_ratio;
> + Â Â Â Â Â Â Â Â Â Â Â mem->dirty_param[MEM_CGROUP_DIRTY_BYTES] =
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â vm_dirty_bytes;
> + Â Â Â Â Â Â Â } while (mem->dirty_param[MEM_CGROUP_DIRTY_RATIO] &&
> + Â Â Â Â Â Â Â Â Â Â Â Âmem->dirty_param[MEM_CGROUP_DIRTY_BYTES]);
> + Â Â Â Â Â Â Â do {
> + Â Â Â Â Â Â Â Â Â Â Â mem->dirty_param[MEM_CGROUP_DIRTY_BACKGROUND_RATIO] =
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dirty_background_ratio;
> + Â Â Â Â Â Â Â Â Â Â Â mem->dirty_param[MEM_CGROUP_DIRTY_BACKGROUND_BYTES] =
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dirty_background_bytes;
> + Â Â Â Â Â Â Â } while (mem->dirty_param[MEM_CGROUP_DIRTY_BACKGROUND_RATIO] &&
> + Â Â Â Â Â Â Â Â Â Â Â mem->dirty_param[MEM_CGROUP_DIRTY_BACKGROUND_BYTES]);
> + Â Â Â }
> Â Â Â Âatomic_set(&mem->refcnt, 1);
> Â Â Â Âmem->move_charge_at_immigrate = 0;
> Â Â Â Âmutex_init(&mem->thresholds_lock);
> --
> 1.6.3.3
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/