linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Tim Chen <tim.c.chen@linux.intel.com>,
	tglx@linutronix.de, ying.huang@intel.com, linux-mm@kvack.org,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] mm, swap: don't disable preemption while taking the per-CPU cache
Date: Fri, 23 Jun 2017 14:02:33 +0200	[thread overview]
Message-ID: <20170623120233.GR5308@dhcp22.suse.cz> (raw)
In-Reply-To: <20170623114755.2ebxdysacvgxzott@linutronix.de>

On Fri 23-06-17 13:47:55, Sebastian Andrzej Siewior wrote:
> get_cpu_var() disables preemption and returns the per-CPU version of the
> variable. Disabling preemption is useful to ensure atomic access to the
> variable within the critical section.
> In this case however, after the per-CPU version of the variable is
> obtained the ->free_lock is acquired. For that reason it seems the raw
> accessor could be used. It only seems that ->slots_ret should be
> retested (because with disabled preemption this variable can not be set
> to NULL otherwise).
> This popped up during PREEMPT-RT testing because it tries to take
> spinlocks in a preempt disabled section.

Ohh, because the spinlock can sleep with PREEMPT-RT right? Don't we have
much more places like that? It is perfectly valid to take a spinlock
while the preemption is disabled. E.g. we do take ptl lock inside
kmap_atomic sections which disables preemption on 32b systems.

> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
> On 2017-06-23 12:34:23 [+0200], Michal Hocko wrote:
> > The changelog doesn't explain, why does this change matter. Disabling
> > preemption shortly before taking a spinlock shouldn't make much
> > difference. I suspect you care because of RT, right? In that case spell
> > that in the changelog and explain why it matters.
> 
> yes, it is bad for RT. I added the RT pieces as explanation.
> 
> > Other than hat the patch looks good to me.
> 
> Thank you. +akpm.
> 
>  mm/swap_slots.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/swap_slots.c b/mm/swap_slots.c
> index 58f6c78f1dad..51c304477482 100644
> --- a/mm/swap_slots.c
> +++ b/mm/swap_slots.c
> @@ -272,11 +272,11 @@ int free_swap_slot(swp_entry_t entry)
>  {
>  	struct swap_slots_cache *cache;
>  
> -	cache = &get_cpu_var(swp_slots);
> +	cache = raw_cpu_ptr(&swp_slots);
>  	if (use_swap_slot_cache && cache->slots_ret) {
>  		spin_lock_irq(&cache->free_lock);
>  		/* Swap slots cache may be deactivated before acquiring lock */
> -		if (!use_swap_slot_cache) {
> +		if (!use_swap_slot_cache || !cache->slots_ret) {
>  			spin_unlock_irq(&cache->free_lock);
>  			goto direct_free;
>  		}
> @@ -296,7 +296,6 @@ int free_swap_slot(swp_entry_t entry)
>  direct_free:
>  		swapcache_free_entries(&entry, 1);
>  	}
> -	put_cpu_var(swp_slots);
>  
>  	return 0;
>  }
> -- 
> 2.13.1
> 

-- 
Michal Hocko
SUSE Labs

--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2017-06-23 12:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-23 10:12 [RFC PATCH] " Sebastian Andrzej Siewior
2017-06-23 10:34 ` Michal Hocko
2017-06-23 11:47   ` [PATCH] " Sebastian Andrzej Siewior
2017-06-23 12:02     ` Michal Hocko [this message]
2017-06-23 12:08       ` Sebastian Andrzej Siewior
2017-06-23 12:13         ` Michal Hocko

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=20170623120233.GR5308@dhcp22.suse.cz \
    --to=mhocko@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=bigeasy@linutronix.de \
    --cc=linux-mm@kvack.org \
    --cc=tglx@linutronix.de \
    --cc=tim.c.chen@linux.intel.com \
    --cc=ying.huang@intel.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