From: Ying Han <yinghan@google.com>
To: Zhu Yanhai <zhu.yanhai@gmail.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
Pavel Emelyanov <xemul@openvz.org>,
Balbir Singh <balbir@linux.vnet.ibm.com>,
Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>,
Li Zefan <lizf@cn.fujitsu.com>, Mel Gorman <mel@csn.ul.ie>,
Christoph Lameter <cl@linux.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Rik van Riel <riel@redhat.com>, Hugh Dickins <hughd@google.com>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Tejun Heo <tj@kernel.org>, Michal Hocko <mhocko@suse.cz>,
Andrew Morton <akpm@linux-foundation.org>,
Dave Hansen <dave@linux.vnet.ibm.com>,
linux-mm@kvack.org
Subject: Re: [PATCH V3 4/7] Infrastructure to support per-memcg reclaim.
Date: Wed, 13 Apr 2011 23:32:51 -0700 [thread overview]
Message-ID: <BANLkTing9_Y6EcFEcQFmFBZTzB+_FmsubA@mail.gmail.com> (raw)
In-Reply-To: <BANLkTi=Qdv3RZuhN++OX2-S8OZqrL7=KBg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 14201 bytes --]
On Wed, Apr 13, 2011 at 8:57 PM, Zhu Yanhai <zhu.yanhai@gmail.com> wrote:
> Hi Ying,
>
> 2011/4/13 Ying Han <yinghan@google.com>:
> > -extern int kswapd_run(int nid);
> > -extern void kswapd_stop(int nid);
> > +extern int kswapd_run(int nid, struct mem_cgroup *mem);
> > +extern void kswapd_stop(int nid, struct mem_cgroup *mem);
>
> This breaks online_pages() and offline_pages(), which are also
> the caller of kswaped_run() and kswaped_stop().
>
Thanks, that will be fixed in the next post.
--Ying
>
> Thanks,
> Zhu Yanhai
>
> >
> > #ifdef CONFIG_MMU
> > /* linux/mm/shmem.c */
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index 36ae377..acd84a8 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -274,6 +274,8 @@ struct mem_cgroup {
> > spinlock_t pcp_counter_lock;
> >
> > int wmark_ratio;
> > +
> > + wait_queue_head_t *kswapd_wait;
> > };
> >
> > /* Stuffs for move charges at task migration. */
> > @@ -4622,6 +4624,33 @@ int mem_cgroup_watermark_ok(struct mem_cgroup
> *mem,
> > return ret;
> > }
> >
> > +int mem_cgroup_init_kswapd(struct mem_cgroup *mem, struct kswapd
> *kswapd_p)
> > +{
> > + if (!mem || !kswapd_p)
> > + return 0;
> > +
> > + mem->kswapd_wait = &kswapd_p->kswapd_wait;
> > + kswapd_p->kswapd_mem = mem;
> > +
> > + return css_id(&mem->css);
> > +}
> > +
> > +void mem_cgroup_clear_kswapd(struct mem_cgroup *mem)
> > +{
> > + if (mem)
> > + mem->kswapd_wait = NULL;
> > +
> > + return;
> > +}
> > +
> > +wait_queue_head_t *mem_cgroup_kswapd_wait(struct mem_cgroup *mem)
> > +{
> > + if (!mem)
> > + return NULL;
> > +
> > + return mem->kswapd_wait;
> > +}
> > +
> > static int mem_cgroup_soft_limit_tree_init(void)
> > {
> > struct mem_cgroup_tree_per_node *rtpn;
> > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > index 77ac74f..a1a1211 100644
> > --- a/mm/vmscan.c
> > +++ b/mm/vmscan.c
> > @@ -2242,6 +2242,7 @@ static bool pgdat_balanced(pg_data_t *pgdat,
> unsigned long balanced_pages,
> > }
> >
> > static DEFINE_SPINLOCK(kswapds_spinlock);
> > +#define is_node_kswapd(kswapd_p) (!(kswapd_p)->kswapd_mem)
> >
> > /* is kswapd sleeping prematurely? */
> > static int sleeping_prematurely(struct kswapd *kswapd, int order,
> > @@ -2251,11 +2252,16 @@ static int sleeping_prematurely(struct kswapd
> *kswapd, int order,
> > unsigned long balanced = 0;
> > bool all_zones_ok = true;
> > pg_data_t *pgdat = kswapd->kswapd_pgdat;
> > + struct mem_cgroup *mem = kswapd->kswapd_mem;
> >
> > /* If a direct reclaimer woke kswapd within HZ/10, it's premature
> */
> > if (remaining)
> > return true;
> >
> > + /* Doesn't support for per-memcg reclaim */
> > + if (mem)
> > + return false;
> > +
> > /* Check the watermark levels */
> > for (i = 0; i < pgdat->nr_zones; i++) {
> > struct zone *zone = pgdat->node_zones + i;
> > @@ -2598,19 +2604,25 @@ static void kswapd_try_to_sleep(struct kswapd
> *kswapd_p, int order,
> > * go fully to sleep until explicitly woken up.
> > */
> > if (!sleeping_prematurely(kswapd_p, order, remaining,
> classzone_idx)) {
> > - trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
> > + if (is_node_kswapd(kswapd_p)) {
> > + trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
> >
> > - /*
> > - * vmstat counters are not perfectly accurate and the
> estimated
> > - * value for counters such as NR_FREE_PAGES can deviate
> from the
> > - * true value by nr_online_cpus * threshold. To avoid the
> zone
> > - * watermarks being breached while under pressure, we
> reduce the
> > - * per-cpu vmstat threshold while kswapd is awake and
> restore
> > - * them before going back to sleep.
> > - */
> > - set_pgdat_percpu_threshold(pgdat,
> calculate_normal_threshold);
> > - schedule();
> > - set_pgdat_percpu_threshold(pgdat,
> calculate_pressure_threshold);
> > + /*
> > + * vmstat counters are not perfectly accurate and
> the
> > + * estimated value for counters such as
> NR_FREE_PAGES
> > + * can deviate from the true value by
> nr_online_cpus *
> > + * threshold. To avoid the zone watermarks being
> > + * breached while under pressure, we reduce the
> per-cpu
> > + * vmstat threshold while kswapd is awake and
> restore
> > + * them before going back to sleep.
> > + */
> > + set_pgdat_percpu_threshold(pgdat,
> > +
> calculate_normal_threshold);
> > + schedule();
> > + set_pgdat_percpu_threshold(pgdat,
> > +
> calculate_pressure_threshold);
> > + } else
> > + schedule();
> > } else {
> > if (remaining)
> > count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
> > @@ -2620,6 +2632,12 @@ static void kswapd_try_to_sleep(struct kswapd
> *kswapd_p, int order,
> > finish_wait(wait_h, &wait);
> > }
> >
> > +static unsigned long balance_mem_cgroup_pgdat(struct mem_cgroup
> *mem_cont,
> > + int order)
> > +{
> > + return 0;
> > +}
> > +
> > /*
> > * The background pageout daemon, started as a kernel thread
> > * from the init process.
> > @@ -2639,6 +2657,7 @@ int kswapd(void *p)
> > int classzone_idx;
> > struct kswapd *kswapd_p = (struct kswapd *)p;
> > pg_data_t *pgdat = kswapd_p->kswapd_pgdat;
> > + struct mem_cgroup *mem = kswapd_p->kswapd_mem;
> > wait_queue_head_t *wait_h = &kswapd_p->kswapd_wait;
> > struct task_struct *tsk = current;
> >
> > @@ -2649,10 +2668,12 @@ int kswapd(void *p)
> >
> > lockdep_set_current_reclaim_state(GFP_KERNEL);
> >
> > - BUG_ON(pgdat->kswapd_wait != wait_h);
> > - cpumask = cpumask_of_node(pgdat->node_id);
> > - if (!cpumask_empty(cpumask))
> > - set_cpus_allowed_ptr(tsk, cpumask);
> > + if (is_node_kswapd(kswapd_p)) {
> > + BUG_ON(pgdat->kswapd_wait != wait_h);
> > + cpumask = cpumask_of_node(pgdat->node_id);
> > + if (!cpumask_empty(cpumask))
> > + set_cpus_allowed_ptr(tsk, cpumask);
> > + }
> > current->reclaim_state = &reclaim_state;
> >
> > /*
> > @@ -2677,24 +2698,29 @@ int kswapd(void *p)
> > int new_classzone_idx;
> > int ret;
> >
> > - new_order = pgdat->kswapd_max_order;
> > - new_classzone_idx = pgdat->classzone_idx;
> > - pgdat->kswapd_max_order = 0;
> > - pgdat->classzone_idx = MAX_NR_ZONES - 1;
> > - if (order < new_order || classzone_idx >
> new_classzone_idx) {
> > - /*
> > - * Don't sleep if someone wants a larger 'order'
> > - * allocation or has tigher zone constraints
> > - */
> > - order = new_order;
> > - classzone_idx = new_classzone_idx;
> > - } else {
> > - kswapd_try_to_sleep(kswapd_p, order,
> classzone_idx);
> > - order = pgdat->kswapd_max_order;
> > - classzone_idx = pgdat->classzone_idx;
> > + if (is_node_kswapd(kswapd_p)) {
> > + new_order = pgdat->kswapd_max_order;
> > + new_classzone_idx = pgdat->classzone_idx;
> > pgdat->kswapd_max_order = 0;
> > pgdat->classzone_idx = MAX_NR_ZONES - 1;
> > - }
> > + if (order < new_order ||
> > + classzone_idx >
> new_classzone_idx) {
> > + /*
> > + * Don't sleep if someone wants a larger
> 'order'
> > + * allocation or has tigher zone
> constraints
> > + */
> > + order = new_order;
> > + classzone_idx = new_classzone_idx;
> > + } else {
> > + kswapd_try_to_sleep(kswapd_p, order,
> > + classzone_idx);
> > + order = pgdat->kswapd_max_order;
> > + classzone_idx = pgdat->classzone_idx;
> > + pgdat->kswapd_max_order = 0;
> > + pgdat->classzone_idx = MAX_NR_ZONES - 1;
> > + }
> > + } else
> > + kswapd_try_to_sleep(kswapd_p, order,
> classzone_idx);
> >
> > ret = try_to_freeze();
> > if (kthread_should_stop())
> > @@ -2705,8 +2731,13 @@ int kswapd(void *p)
> > * after returning from the refrigerator
> > */
> > if (!ret) {
> > - trace_mm_vmscan_kswapd_wake(pgdat->node_id,
> order);
> > - order = balance_pgdat(pgdat, order,
> &classzone_idx);
> > + if (is_node_kswapd(kswapd_p)) {
> > +
> trace_mm_vmscan_kswapd_wake(pgdat->node_id,
> > + order);
> > + order = balance_pgdat(pgdat, order,
> > + &classzone_idx);
> > + } else
> > + balance_mem_cgroup_pgdat(mem, order);
> > }
> > }
> > return 0;
> > @@ -2853,30 +2884,53 @@ static int __devinit cpu_callback(struct
> notifier_block *nfb,
> > * This kswapd start function will be called by init and node-hot-add.
> > * On node-hot-add, kswapd will moved to proper cpus if cpus are
> hot-added.
> > */
> > -int kswapd_run(int nid)
> > +int kswapd_run(int nid, struct mem_cgroup *mem)
> > {
> > - pg_data_t *pgdat = NODE_DATA(nid);
> > struct task_struct *kswapd_thr;
> > + pg_data_t *pgdat = NULL;
> > struct kswapd *kswapd_p;
> > + static char name[TASK_COMM_LEN];
> > + int memcg_id;
> > int ret = 0;
> >
> > - if (pgdat->kswapd_wait)
> > - return 0;
> > + if (!mem) {
> > + pgdat = NODE_DATA(nid);
> > + if (pgdat->kswapd_wait)
> > + return ret;
> > + }
> >
> > kswapd_p = kzalloc(sizeof(struct kswapd), GFP_KERNEL);
> > if (!kswapd_p)
> > return -ENOMEM;
> >
> > init_waitqueue_head(&kswapd_p->kswapd_wait);
> > - pgdat->kswapd_wait = &kswapd_p->kswapd_wait;
> > - kswapd_p->kswapd_pgdat = pgdat;
> >
> > - kswapd_thr = kthread_run(kswapd, kswapd_p, "kswapd%d", nid);
> > + if (!mem) {
> > + pgdat->kswapd_wait = &kswapd_p->kswapd_wait;
> > + kswapd_p->kswapd_pgdat = pgdat;
> > + snprintf(name, TASK_COMM_LEN, "kswapd_%d", nid);
> > + } else {
> > + memcg_id = mem_cgroup_init_kswapd(mem, kswapd_p);
> > + if (!memcg_id) {
> > + kfree(kswapd_p);
> > + return ret;
> > + }
> > + snprintf(name, TASK_COMM_LEN, "memcg_%d", memcg_id);
> > + }
> > +
> > + kswapd_thr = kthread_run(kswapd, kswapd_p, name);
> > if (IS_ERR(kswapd_thr)) {
> > /* failure at boot is fatal */
> > BUG_ON(system_state == SYSTEM_BOOTING);
> > - printk("Failed to start kswapd on node %d\n",nid);
> > - pgdat->kswapd_wait = NULL;
> > + if (!mem) {
> > + printk(KERN_ERR "Failed to start kswapd on node
> %d\n",
> > + nid);
> > + pgdat->kswapd_wait = NULL;
> > + } else {
> > + printk(KERN_ERR "Failed to start kswapd on memcg
> %d\n",
> > +
> memcg_id);
> > + mem_cgroup_clear_kswapd(mem);
> > + }
> > kfree(kswapd_p);
> > ret = -1;
> > } else
> > @@ -2887,16 +2941,18 @@ int kswapd_run(int nid)
> > /*
> > * Called by memory hotplug when all memory in a node is offlined.
> > */
> > -void kswapd_stop(int nid)
> > +void kswapd_stop(int nid, struct mem_cgroup *mem)
> > {
> > struct task_struct *kswapd_thr = NULL;
> > struct kswapd *kswapd_p = NULL;
> > wait_queue_head_t *wait;
> >
> > - pg_data_t *pgdat = NODE_DATA(nid);
> > -
> > spin_lock(&kswapds_spinlock);
> > - wait = pgdat->kswapd_wait;
> > + if (!mem)
> > + wait = NODE_DATA(nid)->kswapd_wait;
> > + else
> > + wait = mem_cgroup_kswapd_wait(mem);
> > +
> > if (wait) {
> > kswapd_p = container_of(wait, struct kswapd, kswapd_wait);
> > kswapd_thr = kswapd_p->kswapd_task;
> > @@ -2916,7 +2972,7 @@ static int __init kswapd_init(void)
> >
> > swap_setup();
> > for_each_node_state(nid, N_HIGH_MEMORY)
> > - kswapd_run(nid);
> > + kswapd_run(nid, NULL);
> > hotcpu_notifier(cpu_callback, 0);
> > return 0;
> > }
> > --
> > 1.7.3.1
> >
> > --
> > To unsubscribe, send a message with 'unsubscribe linux-mm' in
> > the body to majordomo@kvack.org. For more info on Linux MM,
> > see: http://www.linux-mm.org/ .
> > Fight unfair telecom internet charges in Canada: sign
> http://stopthemeter.ca/
> > Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
> >
>
[-- Attachment #2: Type: text/html, Size: 17372 bytes --]
next prev parent reply other threads:[~2011-04-14 6:32 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-13 7:03 [PATCH V3 0/7] memcg: per cgroup background reclaim Ying Han
2011-04-13 7:03 ` [PATCH V3 1/7] Add kswapd descriptor Ying Han
2011-04-13 7:03 ` [PATCH V3 2/7] Add per memcg reclaim watermarks Ying Han
2011-04-13 8:25 ` KAMEZAWA Hiroyuki
2011-04-13 18:40 ` Ying Han
2011-04-14 0:27 ` KAMEZAWA Hiroyuki
2011-04-14 8:24 ` Zhu Yanhai
2011-04-14 17:43 ` Ying Han
2011-04-13 7:03 ` [PATCH V3 3/7] New APIs to adjust per-memcg wmarks Ying Han
2011-04-13 8:30 ` KAMEZAWA Hiroyuki
2011-04-13 18:46 ` Ying Han
2011-04-13 7:03 ` [PATCH V3 4/7] Infrastructure to support per-memcg reclaim Ying Han
2011-04-14 3:57 ` Zhu Yanhai
2011-04-14 6:32 ` Ying Han [this message]
2011-04-13 7:03 ` [PATCH V3 5/7] Per-memcg background reclaim Ying Han
2011-04-13 8:58 ` KAMEZAWA Hiroyuki
2011-04-13 22:45 ` Ying Han
2011-04-13 7:03 ` [PATCH V3 6/7] Enable per-memcg " Ying Han
2011-04-13 9:05 ` KAMEZAWA Hiroyuki
2011-04-13 21:20 ` Ying Han
2011-04-14 0:30 ` KAMEZAWA Hiroyuki
2011-04-13 7:03 ` [PATCH V3 7/7] Add some per-memcg stats Ying Han
2011-04-13 7:47 ` [PATCH V3 0/7] memcg: per cgroup background reclaim KAMEZAWA Hiroyuki
2011-04-13 17:53 ` Ying Han
2011-04-14 0:14 ` KAMEZAWA Hiroyuki
2011-04-14 17:38 ` Ying Han
2011-04-14 21:59 ` Ying Han
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BANLkTing9_Y6EcFEcQFmFBZTzB+_FmsubA@mail.gmail.com \
--to=yinghan@google.com \
--cc=akpm@linux-foundation.org \
--cc=balbir@linux.vnet.ibm.com \
--cc=cl@linux.com \
--cc=dave@linux.vnet.ibm.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-mm@kvack.org \
--cc=lizf@cn.fujitsu.com \
--cc=mel@csn.ul.ie \
--cc=mhocko@suse.cz \
--cc=nishimura@mxp.nes.nec.co.jp \
--cc=riel@redhat.com \
--cc=tj@kernel.org \
--cc=xemul@openvz.org \
--cc=zhu.yanhai@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).