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

From: Kirill A. Shutemov
Date: Mon Mar 01 2010 - 03:58:42 EST


On Sat, Feb 27, 2010 at 12:52 AM, Andrea Righi <arighi@xxxxxxxxxxx> wrote:
> Infrastructure to account dirty pages per cgroup and add dirty limit
> interfaces in the cgroupfs:
>
> Â- Active 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 | Â 74 +++++++++-
> Âmm/memcontrol.c      Â| Â354 ++++++++++++++++++++++++++++++++++++++++----
> Â2 files changed, 399 insertions(+), 29 deletions(-)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 1f9b119..e6af95c 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -25,6 +25,41 @@ 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 +152,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 +167,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 +343,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 +355,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;
> +}
> +
> Â#endif /* CONFIG_CGROUP_MEM_CONT */
>
> Â#endif /* _LINUX_MEMCONTROL_H */
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index a443c30..56f3204 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.
> Â*/
> @@ -205,6 +190,14 @@ struct mem_cgroup {
>
>    Âunsigned int  Âswappiness;
>
> + Â Â Â /* control memory cgroup dirty pages */
> + Â Â Â long dirty_ratio;
> + Â Â Â unsigned long dirty_bytes;
> +
> + Â Â Â /* control background writeback (via writeback threads) */
> + Â Â Â long dirty_background_ratio;
> + Â Â Â unsigned long dirty_background_bytes;
> +
> Â Â Â Â/* set when res.limit == memsw.limit */
>    Âbool      Âmemsw_is_minimum;
>
> @@ -1021,6 +1014,169 @@ static unsigned int get_swappiness(struct mem_cgroup *memcg)
> Â Â Â Âreturn swappiness;
> Â}
>
> +enum mem_cgroup_dirty_param {
> + Â Â Â MEM_CGROUP_DIRTY_RATIO,
> + Â Â Â MEM_CGROUP_DIRTY_BYTES,
> + Â Â Â MEM_CGROUP_DIRTY_BACKGROUND_RATIO,
> + Â Â Â MEM_CGROUP_DIRTY_BACKGROUND_BYTES,
> +};
> +
> +static unsigned long get_dirty_param(struct mem_cgroup *memcg,
> + Â Â Â Â Â Â Â Â Â Â Â enum mem_cgroup_dirty_param idx)
> +{
> + Â Â Â unsigned long ret;
> +
> + Â Â Â spin_lock(&memcg->reclaim_param_lock);
> + Â Â Â switch (idx) {
> + Â Â Â case MEM_CGROUP_DIRTY_RATIO:
> + Â Â Â Â Â Â Â ret = memcg->dirty_ratio;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEM_CGROUP_DIRTY_BYTES:
> + Â Â Â Â Â Â Â ret = memcg->dirty_bytes;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEM_CGROUP_DIRTY_BACKGROUND_RATIO:
> + Â Â Â Â Â Â Â ret = memcg->dirty_background_ratio;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEM_CGROUP_DIRTY_BACKGROUND_BYTES:
> + Â Â Â Â Â Â Â ret = memcg->dirty_background_bytes;
> + Â Â Â Â Â Â Â break;
> + Â Â Â default:
> + Â Â Â Â Â Â Â VM_BUG_ON(1);
> + Â Â Â }
> + Â Â Â 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())
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â rcu_read_lock();
> + Â Â Â memcg = mem_cgroup_from_task(current);
> + Â Â Â if (likely(memcg))
> + Â Â Â Â Â Â Â ret = get_dirty_param(memcg, MEM_CGROUP_DIRTY_RATIO);
> + Â Â Â rcu_read_unlock();
> +out:
> + Â Â Â return ret;
> +}
> +
> +unsigned long mem_cgroup_dirty_bytes(void)
> +{
> + Â Â Â struct mem_cgroup *memcg;
> + Â Â Â unsigned long ret = vm_dirty_bytes;
> +
> + Â Â Â if (mem_cgroup_disabled())
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â rcu_read_lock();
> + Â Â Â memcg = mem_cgroup_from_task(current);
> + Â Â Â if (likely(memcg))
> + Â Â Â Â Â Â Â ret = get_dirty_param(memcg, MEM_CGROUP_DIRTY_BYTES);
> + Â Â Â rcu_read_unlock();
> +out:
> + Â Â Â return ret;
> +}
> +
> +long mem_cgroup_dirty_background_ratio(void)
> +{
> + Â Â Â struct mem_cgroup *memcg;
> + Â Â Â long ret = dirty_background_ratio;
> +
> + Â Â Â if (mem_cgroup_disabled())
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â 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();
> +out:
> + Â Â Â return ret;
> +}
> +
> +unsigned long mem_cgroup_dirty_background_bytes(void)
> +{
> + Â Â Â struct mem_cgroup *memcg;
> + Â Â Â unsigned long ret = dirty_background_bytes;
> +
> + Â Â Â if (mem_cgroup_disabled())
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â 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();
> +out:
> + Â Â Â return ret;
> +}
> +
> +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_ANON) +
> + Â Â Â Â Â Â Â Â Â Â Â mem_cgroup_read_stat(memcg, LRU_ACTIVE_FILE) +
> + Â Â Â Â Â Â Â Â Â Â Â mem_cgroup_read_stat(memcg, LRU_INACTIVE_ANON) +
> + Â Â Â Â Â Â Â Â Â Â Â mem_cgroup_read_stat(memcg, LRU_INACTIVE_FILE);
> + Â Â Â Â Â Â Â 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);
> + Â Â Â }
> + Â Â Â 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;
> +
> + Â Â Â 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;
> + Â Â Â rcu_read_unlock();
> +
> + Â Â Â return stat.value;
> +}
> +
> Âstatic int mem_cgroup_count_children_cb(struct mem_cgroup *mem, void *data)
> Â{
> Â Â Â Âint *val = data;
> @@ -1263,10 +1419,10 @@ 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)
> Â{
> Â Â Â Âstruct mem_cgroup *mem;
> Â Â Â Âstruct page_cgroup *pc;
> @@ -1286,7 +1442,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 +3190,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 +3216,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 +3248,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 +3640,100 @@ unlock:
> Â Â Â Âreturn ret;
> Â}
>
> +static u64 mem_cgroup_dirty_ratio_read(struct cgroup *cgrp, struct cftype *cft)
> +{
> + Â Â Â struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> +
> + Â Â Â return get_dirty_param(memcg, MEM_CGROUP_DIRTY_RATIO);
> +}
> +
> +static int
> +mem_cgroup_dirty_ratio_write(struct cgroup *cgrp, struct cftype *cft, u64 val)
> +{
> + Â Â Â struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> +
> + Â Â Â if ((cgrp->parent == NULL) || (val > 100))
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â spin_lock(&memcg->reclaim_param_lock);
> + Â Â Â memcg->dirty_ratio = val;
> + Â Â Â memcg->dirty_bytes = 0;
> + Â Â Â spin_unlock(&memcg->reclaim_param_lock);
> +
> + Â Â Â return 0;
> +}
> +
> +static u64 mem_cgroup_dirty_bytes_read(struct cgroup *cgrp, struct cftype *cft)
> +{
> + Â Â Â struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> +
> + Â Â Â return get_dirty_param(memcg, MEM_CGROUP_DIRTY_BYTES);
> +}
> +
> +static int
> +mem_cgroup_dirty_bytes_write(struct cgroup *cgrp, struct cftype *cft, u64 val)
> +{
> + Â Â Â struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> +
> + Â Â Â if (cgrp->parent == NULL)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â spin_lock(&memcg->reclaim_param_lock);
> + Â Â Â memcg->dirty_ratio = 0;
> + Â Â Â memcg->dirty_bytes = val;
> + Â Â Â spin_unlock(&memcg->reclaim_param_lock);
> +
> + Â Â Â return 0;
> +}
> +
> +static u64
> +mem_cgroup_dirty_background_ratio_read(struct cgroup *cgrp, struct cftype *cft)
> +{
> + Â Â Â struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> +
> + Â Â Â return get_dirty_param(memcg, MEM_CGROUP_DIRTY_BACKGROUND_RATIO);
> +}
> +
> +static int mem_cgroup_dirty_background_ratio_write(struct cgroup *cgrp,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct cftype *cft, u64 val)
> +{
> + Â Â Â struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> +
> + Â Â Â if ((cgrp->parent == NULL) || (val > 100))
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â spin_lock(&memcg->reclaim_param_lock);
> + Â Â Â memcg->dirty_background_ratio = val;
> + Â Â Â memcg->dirty_background_bytes = 0;
> + Â Â Â spin_unlock(&memcg->reclaim_param_lock);
> +
> + Â Â Â return 0;
> +}
> +
> +static u64
> +mem_cgroup_dirty_background_bytes_read(struct cgroup *cgrp, struct cftype *cft)
> +{
> + Â Â Â struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> +
> + Â Â Â return get_dirty_param(memcg, MEM_CGROUP_DIRTY_BACKGROUND_BYTES);
> +}
> +
> +static int mem_cgroup_dirty_background_bytes_write(struct cgroup *cgrp,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct cftype *cft, u64 val)
> +{
> + Â Â Â struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> +
> + Â Â Â if (cgrp->parent == NULL)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â spin_lock(&memcg->reclaim_param_lock);
> + Â Â Â memcg->dirty_background_ratio = 0;
> + Â Â Â memcg->dirty_background_bytes = val;
> + Â Â Â spin_unlock(&memcg->reclaim_param_lock);
> +
> + Â Â Â return 0;
> +}
> +
> Âstatic struct cftype mem_cgroup_files[] = {
> Â Â Â Â{
> Â Â Â Â Â Â Â Â.name = "usage_in_bytes",
> @@ -3518,6 +3785,26 @@ static struct cftype mem_cgroup_files[] = {
> Â Â Â Â Â Â Â Â.write_u64 = mem_cgroup_swappiness_write,
> Â Â Â Â},
> Â Â Â Â{
> + Â Â Â Â Â Â Â .name = "dirty_ratio",
> + Â Â Â Â Â Â Â .read_u64 = mem_cgroup_dirty_ratio_read,
> + Â Â Â Â Â Â Â .write_u64 = mem_cgroup_dirty_ratio_write,
> + Â Â Â },
> + Â Â Â {
> + Â Â Â Â Â Â Â .name = "dirty_bytes",
> + Â Â Â Â Â Â Â .read_u64 = mem_cgroup_dirty_bytes_read,
> + Â Â Â Â Â Â Â .write_u64 = mem_cgroup_dirty_bytes_write,
> + Â Â Â },
> + Â Â Â {
> + Â Â Â Â Â Â Â .name = "dirty_background_ratio",
> + Â Â Â Â Â Â Â .read_u64 = mem_cgroup_dirty_background_ratio_read,
> + Â Â Â Â Â Â Â .write_u64 = mem_cgroup_dirty_background_ratio_write,
> + Â Â Â },
> + Â Â Â {
> + Â Â Â Â Â Â Â .name = "dirty_background_bytes",
> + Â Â Â Â Â Â Â .read_u64 = mem_cgroup_dirty_background_bytes_read,
> + Â Â Â Â Â Â Â .write_u64 = mem_cgroup_dirty_background_bytes_write,
> + Â Â Â },
> + Â Â Â {

mem_cgroup_dirty_background_* functions are too similar to
mem_cgroup_dirty_bytes_*. I think they should be combined
like mem_cgroup_read() and mem_cgroup_write(). It will be
cleaner.

> Â Â Â Â Â Â Â Â.name = "move_charge_at_immigrate",
> Â Â Â Â Â Â Â Â.read_u64 = mem_cgroup_move_charge_read,
> Â Â Â Â Â Â Â Â.write_u64 = mem_cgroup_move_charge_write,
> @@ -3776,8 +4063,23 @@ 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);
> +
> + Â Â Â Â Â Â Â mem->dirty_ratio = get_dirty_param(parent,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MEM_CGROUP_DIRTY_RATIO);
> + Â Â Â Â Â Â Â mem->dirty_bytes = get_dirty_param(parent,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MEM_CGROUP_DIRTY_BYTES);
> + Â Â Â Â Â Â Â mem->dirty_background_ratio = get_dirty_param(parent,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MEM_CGROUP_DIRTY_BACKGROUND_RATIO);
> + Â Â Â Â Â Â Â mem->dirty_background_bytes = get_dirty_param(parent,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MEM_CGROUP_DIRTY_BACKGROUND_BYTES);
> + Â Â Â } else {
> + Â Â Â Â Â Â Â mem->dirty_ratio = vm_dirty_ratio;
> + Â Â Â Â Â Â Â mem->dirty_bytes = vm_dirty_bytes;
> + Â Â Â Â Â Â Â mem->dirty_background_ratio = vm_dirty_ratio;
> + Â Â Â Â Â Â Â mem->dirty_background_bytes = vm_dirty_bytes;
> + Â Â Â }
> Â Â Â Âatomic_set(&mem->refcnt, 1);
> Â Â Â Âmem->move_charge_at_immigrate = 0;
> Â Â Â Âmutex_init(&mem->thresholds_lock);
> --
> 1.6.3.3
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@xxxxxxxxxx ÂFor more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>
>
--
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/