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

From: Kirill A. Shutemov
Date: Thu Mar 04 2010 - 06:55:02 EST


On Thu, Mar 4, 2010 at 12:40 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 | Â 80 ++++++++-
> Âmm/memcontrol.c      Â| Â420 +++++++++++++++++++++++++++++++++++++++-----
> Â2 files changed, 450 insertions(+), 50 deletions(-)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 1f9b119..cc3421b 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -19,12 +19,66 @@
>
> Â#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,
> +};
> +
> +/* Dirty memory parameters */
> +struct dirty_param {
> + Â Â Â int dirty_ratio;
> + Â Â Â unsigned long dirty_bytes;
> + Â Â Â int dirty_background_ratio;
> + Â Â Â unsigned long dirty_background_bytes;
> +};
> +
> +/*
> + * 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_EVENTS, Â Â Â/* incremented at every Âpagein/pageout */
> + Â Â Â 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,
> +};
> +
> +/*
> + * TODO: provide a validation check routine. And retry if validation
> + * fails.
> + */
> +static inline void get_global_dirty_param(struct dirty_param *param)
> +{
> + Â Â Â param->dirty_ratio = vm_dirty_ratio;
> + Â Â Â param->dirty_bytes = vm_dirty_bytes;
> + Â Â Â param->dirty_background_ratio = dirty_background_ratio;
> + Â Â Â param->dirty_background_bytes = dirty_background_bytes;
> +}
> +
> Â#ifdef CONFIG_CGROUP_MEM_RES_CTLR
> Â/*
> Â* All "charge" functions with gfp_mask should use GFP_KERNEL or
> @@ -117,6 +171,10 @@ extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
> Âextern int do_swap_account;
> Â#endif
>
> +extern bool mem_cgroup_has_dirty_limit(void);
> +extern void get_dirty_param(struct dirty_param *param);
> +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 +183,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 +359,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 +371,21 @@ unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
> Â Â Â Âreturn 0;
> Â}
>
> +static inline bool mem_cgroup_has_dirty_limit(void)
> +{
> + Â Â Â return false;
> +}
> +
> +static inline void get_dirty_param(struct dirty_param *param)
> +{
> + Â Â Â get_global_dirty_param(param);
> +}
> +
> +static inline s64 mem_cgroup_page_stat(enum mem_cgroup_page_stat_item item)
> +{
> + Â Â Â return -ENOSYS;
> +}
> +
> Â#endif /* CONFIG_CGROUP_MEM_CONT */
>
> Â#endif /* _LINUX_MEMCONTROL_H */
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 497b6f7..9842e7b 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -73,28 +73,23 @@ static int really_do_swap_account __initdata = 1; /* for remember boot option*/
> Â#define THRESHOLDS_EVENTS_THRESH (7) /* once in 128 */
> Â#define SOFTLIMIT_EVENTS_THRESH (10) /* once in 1024 */
>
> -/*
> - * 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_EVENTS, Â Â Â/* incremented at every Âpagein/pageout */
> -
> - Â Â Â 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;
> +};
> +
> +enum {
> + Â Â Â MEM_CGROUP_DIRTY_RATIO,
> + Â Â Â MEM_CGROUP_DIRTY_BYTES,
> + Â Â Â MEM_CGROUP_DIRTY_BACKGROUND_RATIO,
> + Â Â Â MEM_CGROUP_DIRTY_BACKGROUND_BYTES,
> +};
> +
> Â/*
> Â* per-zone information in memory controller.
> Â*/
> @@ -208,6 +203,9 @@ struct mem_cgroup {
>
>    Âunsigned int  Âswappiness;
>
> + Â Â Â /* control memory cgroup dirty pages */
> + Â Â Â struct dirty_param dirty_param;
> +
> Â Â Â Â/* set when res.limit == memsw.limit */
>    Âbool      Âmemsw_is_minimum;
>
> @@ -1033,6 +1031,156 @@ static unsigned int get_swappiness(struct mem_cgroup *memcg)
> Â Â Â Âreturn swappiness;
> Â}
>
> +static bool dirty_param_is_valid(struct dirty_param *param)
> +{
> + Â Â Â if (param->dirty_ratio && param->dirty_bytes)
> + Â Â Â Â Â Â Â return false;
> + Â Â Â if (param->dirty_background_ratio && param->dirty_background_bytes)
> + Â Â Â Â Â Â Â return false;
> + Â Â Â return true;
> +}
> +
> +static void
> +__mem_cgroup_get_dirty_param(struct dirty_param *param, struct mem_cgroup *mem)
> +{
> + Â Â Â param->dirty_ratio = mem->dirty_param.dirty_ratio;
> + Â Â Â param->dirty_bytes = mem->dirty_param.dirty_bytes;
> + Â Â Â param->dirty_background_ratio = mem->dirty_param.dirty_background_ratio;
> + Â Â Â param->dirty_background_bytes = mem->dirty_param.dirty_background_bytes;
> +}
> +
> +/*
> + * get_dirty_param() - get dirty memory parameters of the current memcg
> + * @param: Â Â a structure is filled with the dirty memory settings
> + *
> + * The function fills @param with the current memcg dirty memory settings. If
> + * memory cgroup is disabled or in case of error the structure is filled with
> + * the global dirty memory settings.
> + */
> +void get_dirty_param(struct dirty_param *param)
> +{
> + Â Â Â struct mem_cgroup *memcg;
> +
> + Â Â Â if (mem_cgroup_disabled()) {
> + Â Â Â Â Â Â Â get_global_dirty_param(param);
> + Â Â Â Â Â Â Â return;
> + Â Â Â }
> + Â Â Â /*
> + Â Â Â Â* 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().
> + Â Â Â Â*/
> + Â Â Â while (1) {
> + Â Â Â Â Â Â Â rcu_read_lock();
> + Â Â Â Â Â Â Â memcg = mem_cgroup_from_task(current);
> + Â Â Â Â Â Â Â if (likely(memcg))
> + Â Â Â Â Â Â Â Â Â Â Â __mem_cgroup_get_dirty_param(param, memcg);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â get_global_dirty_param(param);
> + Â Â Â Â Â Â Â rcu_read_unlock();
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* Since global and memcg dirty_param are not protected we try
> + Â Â Â Â Â Â Â Â* to speculatively read them and retry if we get inconsistent
> + Â Â Â Â Â Â Â Â* values.
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â if (likely(dirty_param_is_valid(param)))
> + Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â }
> +}
> +
> +static inline bool mem_cgroup_can_swap(struct mem_cgroup *memcg)
> +{
> + Â Â Â if (!do_swap_account)
> + Â Â Â Â Â Â Â return nr_swap_pages > 0;
> + Â Â Â return !memcg->memsw_is_minimum &&
> + Â Â Â Â Â Â Â (res_counter_read_u64(&memcg->memsw, RES_LIMIT) > 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:
> + Â Â Â Â Â Â Â BUG_ON(1);

Just BUG()?
Andd add 'break;', please.

> + Â Â Â }
> + Â Â Â 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;
> +}
> +
> +/*
> + * mem_cgroup_has_dirty_limit() - check if current memcg has local dirty limits
> + *
> + * Return true if the current memory cgroup has local dirty memory settings,
> + * false otherwise.
> + */
> +bool mem_cgroup_has_dirty_limit(void)
> +{
> + Â Â Â if (mem_cgroup_disabled())
> + Â Â Â Â Â Â Â return false;
> + Â Â Â return mem_cgroup_from_task(current) != NULL;
> +}
> +
> +/*
> + * mem_cgroup_page_stat() - get memory cgroup file cache statistics
> + * @item: Â Â Âmemory statistic item exported to the kernel
> + *
> + * Return the accounted statistic value, or a negative value in case of error.
> + */
> +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 = -EINVAL;
> + Â Â Â rcu_read_unlock();
> +
> + Â Â Â return stat.value;
> +}
> +
> Âstatic int mem_cgroup_count_children_cb(struct mem_cgroup *mem, void *data)
> Â{
> Â Â Â Âint *val = data;
> @@ -1275,34 +1423,70 @@ 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 file cache's status for memcg.
> + *
> + * Before calling this, mapping->tree_lock should be held and preemption is
> + * disabled. ÂThen, it's guarnteed that the page is not uncharged while we
> + * access page_cgroup. We can make use of that.
> Â*/
> -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;
>
> + Â Â Â if (mem_cgroup_disabled())
> + Â Â Â Â Â Â Â return;
> Â Â Â Âpc = lookup_page_cgroup(page);
> - Â Â Â if (unlikely(!pc))
> + Â Â Â if (unlikely(!pc) || !PageCgroupUsed(pc))
> Â Â Â Â Â Â Â Âreturn;
>
> - Â Â Â lock_page_cgroup(pc);
> - Â Â Â mem = pc->mem_cgroup;
> - Â Â Â if (!mem)
> - Â Â Â Â Â Â Â goto done;
> -
> - Â Â Â if (!PageCgroupUsed(pc))
> - Â Â Â Â Â Â Â goto done;
> -
> + Â Â Â lock_page_cgroup_migrate(pc);
> Â Â Â Â/*
> - Â Â Â Â* Preemption is already disabled. We can use __this_cpu_xxx
> - Â Â Â Â*/
> - Â Â Â __this_cpu_add(mem->stat->count[MEM_CGROUP_STAT_FILE_MAPPED], val);
> -
> -done:
> - Â Â Â unlock_page_cgroup(pc);
> + Â Â Â * It's guarnteed that this page is never uncharged.
> + Â Â Â * The only racy problem is moving account among memcgs.
> + Â Â Â */
> + Â Â Â switch (idx) {
> + Â Â Â case MEM_CGROUP_STAT_FILE_MAPPED:
> + Â Â Â Â Â Â Â if (val > 0)
> + Â Â Â Â Â Â Â Â Â Â Â SetPageCgroupFileMapped(pc);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â ClearPageCgroupFileMapped(pc);
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEM_CGROUP_STAT_FILE_DIRTY:
> + Â Â Â Â Â Â Â if (val > 0)
> + Â Â Â Â Â Â Â Â Â Â Â SetPageCgroupDirty(pc);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â ClearPageCgroupDirty(pc);
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEM_CGROUP_STAT_WRITEBACK:
> + Â Â Â Â Â Â Â if (val > 0)
> + Â Â Â Â Â Â Â Â Â Â Â SetPageCgroupWriteback(pc);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â ClearPageCgroupWriteback(pc);
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEM_CGROUP_STAT_WRITEBACK_TEMP:
> + Â Â Â Â Â Â Â if (val > 0)
> + Â Â Â Â Â Â Â Â Â Â Â SetPageCgroupWritebackTemp(pc);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â ClearPageCgroupWritebackTemp(pc);
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEM_CGROUP_STAT_UNSTABLE_NFS:
> + Â Â Â Â Â Â Â if (val > 0)
> + Â Â Â Â Â Â Â Â Â Â Â SetPageCgroupUnstableNFS(pc);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â ClearPageCgroupUnstableNFS(pc);
> + Â Â Â Â Â Â Â break;
> + Â Â Â default:
> + Â Â Â Â Â Â Â BUG();
> + Â Â Â Â Â Â Â break;
> + Â Â Â }
> + Â Â Â mem = pc->mem_cgroup;
> + Â Â Â if (likely(mem))
> + Â Â Â Â Â Â Â __this_cpu_add(mem->stat->count[idx], val);
> + Â Â Â unlock_page_cgroup_migrate(pc);
> Â}
> +EXPORT_SYMBOL_GPL(mem_cgroup_update_stat);
>
> Â/*
> Â* size of first charge trial. "32" comes from vmscan.c's magic value.
> @@ -1701,6 +1885,45 @@ static void __mem_cgroup_commit_charge(struct mem_cgroup *mem,
> Â Â Â Âmemcg_check_events(mem, pc->page);
> Â}
>
> +/*
> + * Update file cache accounted statistics on task migration.
> + *
> + * TODO: We don't move charges of file (including shmem/tmpfs) pages for now.
> + * So, at the moment this function simply returns without updating accounted
> + * statistics, because we deal only with anonymous pages here.
> + */
> +static void __mem_cgroup_update_file_stat(struct page_cgroup *pc,
> + Â Â Â struct mem_cgroup *from, struct mem_cgroup *to)
> +{
> + Â Â Â struct page *page = pc->page;
> +
> + Â Â Â if (!page_mapped(page) || PageAnon(page))
> + Â Â Â Â Â Â Â return;
> +
> + Â Â Â if (PageCgroupFileMapped(pc)) {
> + Â Â Â Â Â Â Â __this_cpu_dec(from->stat->count[MEM_CGROUP_STAT_FILE_MAPPED]);
> + Â Â Â Â Â Â Â __this_cpu_inc(to->stat->count[MEM_CGROUP_STAT_FILE_MAPPED]);
> + Â Â Â }
> + Â Â Â if (PageCgroupDirty(pc)) {
> + Â Â Â Â Â Â Â __this_cpu_dec(from->stat->count[MEM_CGROUP_STAT_FILE_DIRTY]);
> + Â Â Â Â Â Â Â __this_cpu_inc(to->stat->count[MEM_CGROUP_STAT_FILE_DIRTY]);
> + Â Â Â }
> + Â Â Â if (PageCgroupWriteback(pc)) {
> + Â Â Â Â Â Â Â __this_cpu_dec(from->stat->count[MEM_CGROUP_STAT_WRITEBACK]);
> + Â Â Â Â Â Â Â __this_cpu_inc(to->stat->count[MEM_CGROUP_STAT_WRITEBACK]);
> + Â Â Â }
> + Â Â Â if (PageCgroupWritebackTemp(pc)) {
> + Â Â Â Â Â Â Â __this_cpu_dec(
> + Â Â Â Â Â Â Â Â Â Â Â from->stat->count[MEM_CGROUP_STAT_WRITEBACK_TEMP]);
> + Â Â Â Â Â Â Â __this_cpu_inc(to->stat->count[MEM_CGROUP_STAT_WRITEBACK_TEMP]);
> + Â Â Â }
> + Â Â Â if (PageCgroupUnstableNFS(pc)) {
> + Â Â Â Â Â Â Â __this_cpu_dec(
> + Â Â Â Â Â Â Â Â Â Â Â from->stat->count[MEM_CGROUP_STAT_UNSTABLE_NFS]);
> + Â Â Â Â Â Â Â __this_cpu_inc(to->stat->count[MEM_CGROUP_STAT_UNSTABLE_NFS]);
> + Â Â Â }
> +}
> +
> Â/**
> Â* __mem_cgroup_move_account - move account of the page
> Â* @pc: Â Â Â Âpage_cgroup of the page.
> @@ -1721,22 +1944,16 @@ static void __mem_cgroup_commit_charge(struct mem_cgroup *mem,
> Âstatic void __mem_cgroup_move_account(struct page_cgroup *pc,
> Â Â Â Âstruct mem_cgroup *from, struct mem_cgroup *to, bool uncharge)
> Â{
> - Â Â Â struct page *page;
> -
> Â Â Â ÂVM_BUG_ON(from == to);
> Â Â Â ÂVM_BUG_ON(PageLRU(pc->page));
> Â Â Â ÂVM_BUG_ON(!PageCgroupLocked(pc));
> Â Â Â ÂVM_BUG_ON(!PageCgroupUsed(pc));
> Â Â Â ÂVM_BUG_ON(pc->mem_cgroup != from);
>
> - Â Â Â page = pc->page;
> - Â Â Â if (page_mapped(page) && !PageAnon(page)) {
> - Â Â Â Â Â Â Â /* Update mapped_file data for mem_cgroup */
> - Â Â Â Â Â Â Â preempt_disable();
> - Â Â Â Â Â Â Â __this_cpu_dec(from->stat->count[MEM_CGROUP_STAT_FILE_MAPPED]);
> - Â Â Â Â Â Â Â __this_cpu_inc(to->stat->count[MEM_CGROUP_STAT_FILE_MAPPED]);
> - Â Â Â Â Â Â Â preempt_enable();
> - Â Â Â }
> + Â Â Â preempt_disable();
> + Â Â Â lock_page_cgroup_migrate(pc);
> + Â Â Â __mem_cgroup_update_file_stat(pc, from, to);
> +
> Â Â Â Âmem_cgroup_charge_statistics(from, pc, false);
> Â Â Â Âif (uncharge)
> Â Â Â Â Â Â Â Â/* This is not "cancel", but cancel_charge does all we need. */
> @@ -1745,6 +1962,8 @@ static void __mem_cgroup_move_account(struct page_cgroup *pc,
> Â Â Â Â/* caller should have done css_get */
> Â Â Â Âpc->mem_cgroup = to;
> Â Â Â Âmem_cgroup_charge_statistics(to, pc, true);
> + Â Â Â unlock_page_cgroup_migrate(pc);
> + Â Â Â preempt_enable();
> Â Â Â Â/*
> Â Â Â Â * We charges against "to" which may not have any tasks. Then, "to"
> Â Â Â Â * can be under rmdir(). But in current implementation, caller of
> @@ -3042,6 +3261,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,
> @@ -3064,6 +3287,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"},
> @@ -3092,6 +3319,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);
> @@ -3453,6 +3688,60 @@ unlock:
> Â Â Â Âreturn ret;
> Â}
>
> +static u64 mem_cgroup_dirty_read(struct cgroup *cgrp, struct cftype *cft)
> +{
> + Â Â Â struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> +
> + Â Â Â switch (cft->private) {
> + Â Â Â case MEM_CGROUP_DIRTY_RATIO:
> + Â Â Â Â Â Â Â return memcg->dirty_param.dirty_ratio;
> + Â Â Â case MEM_CGROUP_DIRTY_BYTES:
> + Â Â Â Â Â Â Â return memcg->dirty_param.dirty_bytes;
> + Â Â Â case MEM_CGROUP_DIRTY_BACKGROUND_RATIO:
> + Â Â Â Â Â Â Â return memcg->dirty_param.dirty_background_ratio;
> + Â Â Â case MEM_CGROUP_DIRTY_BACKGROUND_BYTES:
> + Â Â Â Â Â Â Â return memcg->dirty_param.dirty_background_bytes;
> + Â Â Â default:
> + Â Â Â Â Â Â Â BUG();
> + Â Â Â }
> +}
> +
> +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)
> + Â Â Â Â Â Â Â return -EINVAL;
> + Â Â Â /*
> + Â Â Â Â* TODO: provide a validation check routine. And retry if validation
> + Â Â Â Â* fails.
> + Â Â Â Â*/
> + Â Â Â switch (type) {
> + Â Â Â case MEM_CGROUP_DIRTY_RATIO:
> + Â Â Â Â Â Â Â memcg->dirty_param.dirty_ratio = val;
> + Â Â Â Â Â Â Â memcg->dirty_param.dirty_bytes = 0;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEM_CGROUP_DIRTY_BYTES:
> + Â Â Â Â Â Â Â memcg->dirty_param.dirty_ratio Â= 0;
> + Â Â Â Â Â Â Â memcg->dirty_param.dirty_bytes = val;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEM_CGROUP_DIRTY_BACKGROUND_RATIO:
> + Â Â Â Â Â Â Â memcg->dirty_param.dirty_background_ratio = val;
> + Â Â Â Â Â Â Â memcg->dirty_param.dirty_background_bytes = 0;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case MEM_CGROUP_DIRTY_BACKGROUND_BYTES:
> + Â Â Â Â Â Â Â memcg->dirty_param.dirty_background_ratio = 0;
> + Â Â Â Â Â Â Â memcg->dirty_param.dirty_background_bytes = val;
> + Â Â Â Â Â Â Â break;

default:
BUG();
break;

> + Â Â Â }
> + Â Â Â return 0;
> +}
> +
> Âstatic struct cftype mem_cgroup_files[] = {
> Â Â Â Â{
> Â Â Â Â Â Â Â Â.name = "usage_in_bytes",
> @@ -3504,6 +3793,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,
> @@ -3762,8 +4075,21 @@ 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_param = parent->dirty_param;
> + Â Â Â } else {
> + Â Â Â Â Â Â Â while (1) {
> + Â Â Â Â Â Â Â Â Â Â Â get_global_dirty_param(&mem->dirty_param);
> + Â Â Â Â Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â Â Â Â Â* Since global dirty parameters are not protected we
> + Â Â Â Â Â Â Â Â Â Â Â Â* try to speculatively read them and retry if we get
> + Â Â Â Â Â Â Â Â Â Â Â Â* inconsistent values.
> + Â Â Â Â Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â Â Â Â Â if (likely(dirty_param_is_valid(&mem->dirty_param)))
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> Â Â Â Â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/