On Wed, Jan 18, 2017 at 01:45:55PM +0100, Michal Hocko wrote:
> On Tue 17-01-17 13:42:35, Tim Chen wrote:
> [...]
> > Logic wise, We do allow pre-emption as per cpu ptr cache->slots is
> > protected by the mutex cache->alloc_lock.  We switch the
> > inappropriately used this_cpu_ptr to raw_cpu_ptr for per cpu ptr
> > access of cache->slots.
> 
> OK, that looks better. I would still appreciate something like the
> following folded in
> diff --git a/include/linux/swap_slots.h b/include/linux/swap_slots.h
> index fb907346c5c6..0afe748453a7 100644
> --- a/include/linux/swap_slots.h
> +++ b/include/linux/swap_slots.h
> @@ -11,6 +11,7 @@
>  
>  struct swap_slots_cache {
>       bool            lock_initialized;
> +     /* protects slots, nr, cur */
>       struct mutex    alloc_lock;
>       swp_entry_t     *slots;
>       int             nr;
> 

I've included here a patch for the comments.

Thanks.

Tim

--->8---
From: Tim Chen <[email protected]>
Date: Wed, 18 Jan 2017 09:52:28 -0800
Subject: [PATCH] mm/swap: Add comments on locks in swap_slots.h
To: Andrew Morton <[email protected]>
Cc: Ying Huang <[email protected]>, [email protected], 
[email protected], [email protected], [email protected], 
[email protected], Hugh Dickins <[email protected]>, Shaohua Li 
<[email protected]>, Minchan Kim <[email protected]>, Rik van Riel 
<[email protected]>, Andrea Arcangeli <[email protected]>, Kirill A . Shutemov 
<[email protected]>, Vladimir Davydov <[email protected]>, 
Johannes Weiner <[email protected]>, Michal Hocko <[email protected]>, Hillf 
Danton <[email protected]>, Christian Borntraeger 
<[email protected]>, Jonathan Corbet <[email protected]>

Explains what each lock protects in swap_slots_cache structure.

Signed-off-by: Tim Chen <[email protected]>
---
 include/linux/swap_slots.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/swap_slots.h b/include/linux/swap_slots.h
index fb90734..6ef92d1 100644
--- a/include/linux/swap_slots.h
+++ b/include/linux/swap_slots.h
@@ -11,11 +11,11 @@
 
 struct swap_slots_cache {
        bool            lock_initialized;
-       struct mutex    alloc_lock;
+       struct mutex    alloc_lock; /* protects slots, nr, cur */
        swp_entry_t     *slots;
        int             nr;
        int             cur;
-       spinlock_t      free_lock;
+       spinlock_t      free_lock;  /* protects slots_ret, n_ret */
        swp_entry_t     *slots_ret;
        int             n_ret;
 };
-- 
2.5.5

Attachment: signature.asc
Description: PGP signature

Reply via email to