From: "Huang\, Ying" <ying.huang@intel.com>
To: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Ying Huang <ying.huang@intel.com>,
Wenwei Tao <wenwei.tww@alibaba-inc.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Minchan Kim <minchan@kernel.org>, Rik van Riel <riel@redhat.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Hillf Danton <hillf.zj@alibaba-inc.com>
Subject: Re: [PATCH 2/2] mm/swap: Remove lock_initialized flag from swap_slots_cache
Date: Mon, 24 Jul 2017 10:15:29 +0800 [thread overview]
Message-ID: <878tjeh96m.fsf@yhuang-dev.intel.com> (raw)
In-Reply-To: <867d1fb070644e6d5f0ac7780f63e75259b82cc3.1500677066.git.tim.c.chen@linux.intel.com> (Tim Chen's message of "Fri, 21 Jul 2017 15:45:01 -0700")
Hi, Tim,
Tim Chen <tim.c.chen@linux.intel.com> writes:
> We will only reach the lock initialization code
> in alloc_swap_slot_cache when the cpu's swap_slots_cache's slots
> have not been allocated and swap_slots_cache has not been initialized
> previously. So the lock_initialized check is redundant and unnecessary.
> Remove lock_initialized flag from swap_slots_cache to save memory.
Is there a race condition with CPU offline/online when preempt is enabled?
CPU A CPU B
----- -----
get_swap_page()
get cache[B], cache[B]->slots != NULL
preempted and moved to CPU A
be offlined
be onlined
alloc_swap_slot_cache()
mutex_lock(cache[B]->alloc_lock)
mutex_init(cache[B]->alloc_lock) !!!
The cache[B]->alloc_lock will be reinitialized when it is still held.
Best Regards,
Huang, Ying
> Reported-by: Wenwei Tao <wenwei.tww@alibaba-inc.com>
> Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
> ---
> include/linux/swap_slots.h | 1 -
> mm/swap_slots.c | 9 ++++-----
> 2 files changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/swap_slots.h b/include/linux/swap_slots.h
> index 6ef92d1..a75c30b 100644
> --- a/include/linux/swap_slots.h
> +++ b/include/linux/swap_slots.h
> @@ -10,7 +10,6 @@
> #define THRESHOLD_DEACTIVATE_SWAP_SLOTS_CACHE (2*SWAP_SLOTS_CACHE_SIZE)
>
> struct swap_slots_cache {
> - bool lock_initialized;
> struct mutex alloc_lock; /* protects slots, nr, cur */
> swp_entry_t *slots;
> int nr;
> diff --git a/mm/swap_slots.c b/mm/swap_slots.c
> index 4c5457c..c039e6c 100644
> --- a/mm/swap_slots.c
> +++ b/mm/swap_slots.c
> @@ -140,11 +140,10 @@ static int alloc_swap_slot_cache(unsigned int cpu)
> if (cache->slots || cache->slots_ret)
> /* cache already allocated */
> goto out;
> - if (!cache->lock_initialized) {
> - mutex_init(&cache->alloc_lock);
> - spin_lock_init(&cache->free_lock);
> - cache->lock_initialized = true;
> - }
> +
> + mutex_init(&cache->alloc_lock);
> + spin_lock_init(&cache->free_lock);
> +
> cache->nr = 0;
> cache->cur = 0;
> cache->n_ret = 0;
--
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>
WARNING: multiple messages have this Message-ID (diff)
From: "Huang\, Ying" <ying.huang@intel.com>
To: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Ying Huang <ying.huang@intel.com>,
Wenwei Tao <wenwei.tww@alibaba-inc.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>, Minchan Kim <minchan@kernel.org>,
"Rik van Riel" <riel@redhat.com>,
Andrea Arcangeli <aarcange@redhat.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Hillf Danton <hillf.zj@alibaba-inc.com>
Subject: Re: [PATCH 2/2] mm/swap: Remove lock_initialized flag from swap_slots_cache
Date: Mon, 24 Jul 2017 10:15:29 +0800 [thread overview]
Message-ID: <878tjeh96m.fsf@yhuang-dev.intel.com> (raw)
In-Reply-To: <867d1fb070644e6d5f0ac7780f63e75259b82cc3.1500677066.git.tim.c.chen@linux.intel.com> (Tim Chen's message of "Fri, 21 Jul 2017 15:45:01 -0700")
Hi, Tim,
Tim Chen <tim.c.chen@linux.intel.com> writes:
> We will only reach the lock initialization code
> in alloc_swap_slot_cache when the cpu's swap_slots_cache's slots
> have not been allocated and swap_slots_cache has not been initialized
> previously. So the lock_initialized check is redundant and unnecessary.
> Remove lock_initialized flag from swap_slots_cache to save memory.
Is there a race condition with CPU offline/online when preempt is enabled?
CPU A CPU B
----- -----
get_swap_page()
get cache[B], cache[B]->slots != NULL
preempted and moved to CPU A
be offlined
be onlined
alloc_swap_slot_cache()
mutex_lock(cache[B]->alloc_lock)
mutex_init(cache[B]->alloc_lock) !!!
The cache[B]->alloc_lock will be reinitialized when it is still held.
Best Regards,
Huang, Ying
> Reported-by: Wenwei Tao <wenwei.tww@alibaba-inc.com>
> Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
> ---
> include/linux/swap_slots.h | 1 -
> mm/swap_slots.c | 9 ++++-----
> 2 files changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/swap_slots.h b/include/linux/swap_slots.h
> index 6ef92d1..a75c30b 100644
> --- a/include/linux/swap_slots.h
> +++ b/include/linux/swap_slots.h
> @@ -10,7 +10,6 @@
> #define THRESHOLD_DEACTIVATE_SWAP_SLOTS_CACHE (2*SWAP_SLOTS_CACHE_SIZE)
>
> struct swap_slots_cache {
> - bool lock_initialized;
> struct mutex alloc_lock; /* protects slots, nr, cur */
> swp_entry_t *slots;
> int nr;
> diff --git a/mm/swap_slots.c b/mm/swap_slots.c
> index 4c5457c..c039e6c 100644
> --- a/mm/swap_slots.c
> +++ b/mm/swap_slots.c
> @@ -140,11 +140,10 @@ static int alloc_swap_slot_cache(unsigned int cpu)
> if (cache->slots || cache->slots_ret)
> /* cache already allocated */
> goto out;
> - if (!cache->lock_initialized) {
> - mutex_init(&cache->alloc_lock);
> - spin_lock_init(&cache->free_lock);
> - cache->lock_initialized = true;
> - }
> +
> + mutex_init(&cache->alloc_lock);
> + spin_lock_init(&cache->free_lock);
> +
> cache->nr = 0;
> cache->cur = 0;
> cache->n_ret = 0;
next prev parent reply other threads:[~2017-07-24 2:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-21 22:45 [PATCH 1/2] mm/swap: Fix race conditions in swap_slots cache init Tim Chen
2017-07-21 22:45 ` Tim Chen
2017-07-21 22:45 ` [PATCH 2/2] mm/swap: Remove lock_initialized flag from swap_slots_cache Tim Chen
2017-07-21 22:45 ` Tim Chen
2017-07-24 2:15 ` Huang, Ying [this message]
2017-07-24 2:15 ` Huang, Ying
2017-07-24 16:54 ` Tim Chen
2017-07-24 16:54 ` Tim Chen
2017-10-03 22:27 ` [PATCH 1/2] mm/swap: Fix race conditions in swap_slots cache init Andrew Morton
2017-10-03 22:27 ` Andrew Morton
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=878tjeh96m.fsf@yhuang-dev.intel.com \
--to=ying.huang@intel.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=hillf.zj@alibaba-inc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=minchan@kernel.org \
--cc=riel@redhat.com \
--cc=tim.c.chen@linux.intel.com \
--cc=wenwei.tww@alibaba-inc.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 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.