From: Michal Hocko <mhocko@kernel.org> To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp> Cc: Andrew Morton <akpm@linux-foundation.org>, Chris Metcalf <chris.d.metcalf@gmail.com>, Rusty Russell <rusty@rustcorp.com.au>, linux-mm@kvack.org, Guenter Roeck <linux@roeck-us.net> Subject: Re: [PATCH] mm/swap.c: workaround for_each_cpu() bug on UP kernel. Date: Tue, 12 Feb 2019 12:29:54 +0100 [thread overview] Message-ID: <20190212112954.GV15609@dhcp22.suse.cz> (raw) In-Reply-To: <20190212112117.GT15609@dhcp22.suse.cz> On Tue 12-02-19 12:21:17, Michal Hocko wrote: > On Tue 12-02-19 19:25:46, Tetsuo Handa wrote: > > On 2019/02/12 19:11, Michal Hocko wrote: > > > This patch is ugly as hell! I do agree that for_each_cpu not working on > > > CONFIG_SMP=n sucks but why do we even care about lru_add_drain_all when > > > there is a single cpu? Why don't we simply do > > > > > > diff --git a/mm/swap.c b/mm/swap.c > > > index aa483719922e..952f24b09070 100644 > > > --- a/mm/swap.c > > > +++ b/mm/swap.c > > > @@ -660,6 +660,7 @@ static void lru_add_drain_per_cpu(struct work_struct *dummy) > > > > > > static DEFINE_PER_CPU(struct work_struct, lru_add_drain_work); > > > > > > +#ifdef CONFIG_SMP > > > /* > > > * Doesn't need any cpu hotplug locking because we do rely on per-cpu > > > * kworkers being shut down before our page_alloc_cpu_dead callback is > > > @@ -702,6 +703,10 @@ void lru_add_drain_all(void) > > > > > > mutex_unlock(&lock); > > > } > > > +#else > > > +#define lru_add_drain_all() lru_add_drain() > > > + > > > +#endif > > > > If there is no need to evaluate the "if" conditions, I'm fine with this shortcut. > > lru_add_drain does drain only pagevecs which have pages and so we do not > really have to duplicate the check. There is also no need to defer the > execution to the workqueue for a local cpu. So we are left with only the > lock to prevent parallel execution but the preemption disabling acts the > same purpose on UP so the approach should be equivalent from the > correctness point of view. The patch with the full changelog follows: From db104f132bd6e1c02ecbe65e62c12caa7e4e2e2a Mon Sep 17 00:00:00 2001 From: Michal Hocko <mhocko@suse.com> Date: Tue, 12 Feb 2019 12:25:28 +0100 Subject: [PATCH] mm: handle lru_add_drain_all for UP properly Since for_each_cpu(cpu, mask) added by commit 2d3854a37e8b767a ("cpumask: introduce new API, without changing anything") did not evaluate the mask argument if NR_CPUS == 1 due to CONFIG_SMP=n, lru_add_drain_all() is hitting WARN_ON() at __flush_work() added by commit 4d43d395fed12463 ("workqueue: Try to catch flush_work() without INIT_WORK().") by unconditionally calling flush_work() [1]. Workaround this issue by using CONFIG_SMP=n specific lru_add_drain_all implementation. There is no real need to defer the implementation to the workqueue as the draining is going to happen on the local cpu. So alias lru_add_drain_all to lru_add_drain which does all the necessary work. [1] https://lkml.kernel.org/r/18a30387-6aa5-6123-e67c-57579ecc3f38@roeck-us.net Reported-by: Guenter Roeck <linux@roeck-us.net> Debugged-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: Michal Hocko <mhocko@suse.com> --- mm/swap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/swap.c b/mm/swap.c index 4929bc1be60e..88a6021fce11 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -660,6 +660,7 @@ static void lru_add_drain_per_cpu(struct work_struct *dummy) static DEFINE_PER_CPU(struct work_struct, lru_add_drain_work); +#ifdef CONFIG_SMP /* * Doesn't need any cpu hotplug locking because we do rely on per-cpu * kworkers being shut down before our page_alloc_cpu_dead callback is @@ -702,6 +703,10 @@ void lru_add_drain_all(void) mutex_unlock(&lock); } +#else +#define lru_add_drain_all() lru_add_drain() + +#endif /** * release_pages - batched put_page() -- 2.20.1 -- Michal Hocko SUSE Labs
next prev parent reply other threads:[~2019-02-12 11:29 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-02-07 9:53 Tetsuo Handa 2019-02-07 14:07 ` Guenter Roeck 2019-02-07 14:18 ` William Kucharski 2019-02-12 10:11 ` Michal Hocko 2019-02-12 10:25 ` Tetsuo Handa 2019-02-12 11:21 ` Michal Hocko 2019-02-12 11:29 ` Michal Hocko [this message] 2019-02-12 11:37 ` Tetsuo Handa 2019-02-12 21:06 ` Andrew Morton 2019-02-13 12:43 ` Michal Hocko 2019-02-13 21:37 ` Andrew Morton 2019-02-12 23:19 ` [PATCH] mm: handle lru_add_drain_all for UP properly kbuild test robot 2019-02-12 23:48 ` kbuild test robot
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=20190212112954.GV15609@dhcp22.suse.cz \ --to=mhocko@kernel.org \ --cc=akpm@linux-foundation.org \ --cc=chris.d.metcalf@gmail.com \ --cc=linux-mm@kvack.org \ --cc=linux@roeck-us.net \ --cc=penguin-kernel@i-love.sakura.ne.jp \ --cc=rusty@rustcorp.com.au \ --subject='Re: [PATCH] mm/swap.c: workaround for_each_cpu() bug on UP kernel.' \ /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
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.