2014-07-31 03:29:38

by Lai Jiangshan

[permalink] [raw]
Subject: [PATCH] swap: remove the struct cpumask has_work

It is suggested that cpumask_var_t and alloc_cpumask_var() should be used
instead of struct cpumask. But I don't want to add this complicity nor
leave this unwelcome "static struct cpumask has_work;", so I just remove
it and use flush_work() to perform on all online drain_work. flush_work()
performs very quickly on initialized but unused work item, thus we don't
need the struct cpumask has_work for performance.

CC: [email protected]
CC: Chris Metcalf <[email protected]>
CC: Mel Gorman <[email protected]>
CC: Tejun Heo <[email protected]>
CC: Christoph Lameter <[email protected]>
CC: Frederic Weisbecker <[email protected]>
Signed-off-by: Lai Jiangshan <[email protected]>
---
mm/swap.c | 11 ++++-------
1 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/mm/swap.c b/mm/swap.c
index 9e8e347..bb524ca 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -833,27 +833,24 @@ static DEFINE_PER_CPU(struct work_struct, lru_add_drain_work);
void lru_add_drain_all(void)
{
static DEFINE_MUTEX(lock);
- static struct cpumask has_work;
int cpu;

mutex_lock(&lock);
get_online_cpus();
- cpumask_clear(&has_work);

for_each_online_cpu(cpu) {
struct work_struct *work = &per_cpu(lru_add_drain_work, cpu);

+ INIT_WORK(work, lru_add_drain_per_cpu);
+
if (pagevec_count(&per_cpu(lru_add_pvec, cpu)) ||
pagevec_count(&per_cpu(lru_rotate_pvecs, cpu)) ||
pagevec_count(&per_cpu(lru_deactivate_pvecs, cpu)) ||
- need_activate_page_drain(cpu)) {
- INIT_WORK(work, lru_add_drain_per_cpu);
+ need_activate_page_drain(cpu))
schedule_work_on(cpu, work);
- cpumask_set_cpu(cpu, &has_work);
- }
}

- for_each_cpu(cpu, &has_work)
+ for_each_online_cpu(cpu)
flush_work(&per_cpu(lru_add_drain_work, cpu));

put_online_cpus();
--
1.7.4.4


2014-07-31 11:51:41

by Michal Hocko

[permalink] [raw]
Subject: Re: [PATCH] swap: remove the struct cpumask has_work

On Thu 31-07-14 11:30:19, Lai Jiangshan wrote:
> It is suggested that cpumask_var_t and alloc_cpumask_var() should be used
> instead of struct cpumask. But I don't want to add this complicity nor
> leave this unwelcome "static struct cpumask has_work;", so I just remove
> it and use flush_work() to perform on all online drain_work. flush_work()
> performs very quickly on initialized but unused work item, thus we don't
> need the struct cpumask has_work for performance.

Why? Just because there is general recommendation for using
cpumask_var_t rather than cpumask?

In this particular case cpumask shouldn't matter much as it is static.
Your code will work as well, but I do not see any strong reason to
change it just to get rid of cpumask which is not on stack.

> CC: [email protected]
> CC: Chris Metcalf <[email protected]>
> CC: Mel Gorman <[email protected]>
> CC: Tejun Heo <[email protected]>
> CC: Christoph Lameter <[email protected]>
> CC: Frederic Weisbecker <[email protected]>
> Signed-off-by: Lai Jiangshan <[email protected]>
> ---
> mm/swap.c | 11 ++++-------
> 1 files changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/mm/swap.c b/mm/swap.c
> index 9e8e347..bb524ca 100644
> --- a/mm/swap.c
> +++ b/mm/swap.c
> @@ -833,27 +833,24 @@ static DEFINE_PER_CPU(struct work_struct, lru_add_drain_work);
> void lru_add_drain_all(void)
> {
> static DEFINE_MUTEX(lock);
> - static struct cpumask has_work;
> int cpu;
>
> mutex_lock(&lock);
> get_online_cpus();
> - cpumask_clear(&has_work);
>
> for_each_online_cpu(cpu) {
> struct work_struct *work = &per_cpu(lru_add_drain_work, cpu);
>
> + INIT_WORK(work, lru_add_drain_per_cpu);
> +
> if (pagevec_count(&per_cpu(lru_add_pvec, cpu)) ||
> pagevec_count(&per_cpu(lru_rotate_pvecs, cpu)) ||
> pagevec_count(&per_cpu(lru_deactivate_pvecs, cpu)) ||
> - need_activate_page_drain(cpu)) {
> - INIT_WORK(work, lru_add_drain_per_cpu);
> + need_activate_page_drain(cpu))
> schedule_work_on(cpu, work);
> - cpumask_set_cpu(cpu, &has_work);
> - }
> }
>
> - for_each_cpu(cpu, &has_work)
> + for_each_online_cpu(cpu)
> flush_work(&per_cpu(lru_add_drain_work, cpu));
>
> put_online_cpus();
> --
> 1.7.4.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

--
Michal Hocko
SUSE Labs

2014-07-31 16:09:21

by Chris Metcalf

[permalink] [raw]
Subject: Re: [PATCH] swap: remove the struct cpumask has_work

On 7/31/2014 7:51 AM, Michal Hocko wrote:
> On Thu 31-07-14 11:30:19, Lai Jiangshan wrote:
>> It is suggested that cpumask_var_t and alloc_cpumask_var() should be used
>> instead of struct cpumask. But I don't want to add this complicity nor
>> leave this unwelcome "static struct cpumask has_work;", so I just remove
>> it and use flush_work() to perform on all online drain_work. flush_work()
>> performs very quickly on initialized but unused work item, thus we don't
>> need the struct cpumask has_work for performance.
> Why? Just because there is general recommendation for using
> cpumask_var_t rather than cpumask?
>
> In this particular case cpumask shouldn't matter much as it is static.
> Your code will work as well, but I do not see any strong reason to
> change it just to get rid of cpumask which is not on stack.

The code uses for_each_cpu with a cpumask to avoid waking cpus that don't
need to do work. This is important for the nohz_full type functionality,
power efficiency, etc. So, nack for this change.

--
Chris Metcalf, Tilera Corp.
http://www.tilera.com

2014-08-01 01:37:45

by Lai Jiangshan

[permalink] [raw]
Subject: Re: [PATCH] swap: remove the struct cpumask has_work

On 08/01/2014 12:09 AM, Chris Metcalf wrote:
> On 7/31/2014 7:51 AM, Michal Hocko wrote:
>> On Thu 31-07-14 11:30:19, Lai Jiangshan wrote:
>>> It is suggested that cpumask_var_t and alloc_cpumask_var() should be used
>>> instead of struct cpumask. But I don't want to add this complicity nor
>>> leave this unwelcome "static struct cpumask has_work;", so I just remove
>>> it and use flush_work() to perform on all online drain_work. flush_work()
>>> performs very quickly on initialized but unused work item, thus we don't
>>> need the struct cpumask has_work for performance.
>> Why? Just because there is general recommendation for using
>> cpumask_var_t rather than cpumask?
>>
>> In this particular case cpumask shouldn't matter much as it is static.
>> Your code will work as well, but I do not see any strong reason to
>> change it just to get rid of cpumask which is not on stack.
>
> The code uses for_each_cpu with a cpumask to avoid waking cpus that don't
> need to do work. This is important for the nohz_full type functionality,
> power efficiency, etc. So, nack for this change.
>

flush_work() on initialized but unused work item just disables irq and
fetches work->data to test and restores irq and return.

the struct cpumask has_work is just premature optimization.