From: Wanpeng Li <liwanp@linux.vnet.ibm.com>
To: Konrad Rzeszutek Wilk <konrad@kernel.org>
Cc: dan.magenheimer@oracle.com, konrad.wilk@oracle.com,
sjenning@linux.vnet.ibm.com, gregkh@linuxfoundation.org,
akpm@linux-foundation.org, ngupta@vflare.org,
rcj@linux.vnet.ibm.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org,
Minchan Kim <minchan@kernel.org>,
Konrad Rzeszutek Wilk <konrad@darnok.org>
Subject: Re: [PATCH 13/15] frontswap: Get rid of swap_lock dependency
Date: Sun, 3 Feb 2013 16:43:37 +0800 [thread overview]
Message-ID: <20130203084337.GA28710@hacker.(null)> (raw)
In-Reply-To: <1359750184-23408-14-git-send-email-konrad.wilk@oracle.com>
Hi Minchan and Konrad,
On Fri, Feb 01, 2013 at 03:23:02PM -0500, Konrad Rzeszutek Wilk wrote:
>From: Minchan Kim <minchan@kernel.org>
>
>Frontswap initialization routine depends on swap_lock, which want
>to be atomic about frontswap's first appearance.
>IOW, frontswap is not present and will fail all calls OR frontswap is
>fully functional but if new swap_info_struct isn't registered
>by enable_swap_info, swap subsystem doesn't start I/O so there is no
>race
>between init procedure and page I/O working on frontswap.
>
>So let's remove unncessary swap_lock dependency.
>
>Cc: Dan Magenheimer <dan.magenheimer@oracle.com>
>Signed-off-by: Minchan Kim <minchan@kernel.org>
>[v1: Rebased on my branch, reworked to work with backends loading late]
>[v2: Added a check for !map]
>Signed-off-by: Konrad Rzeszutek Wilk <konrad@darnok.org>
>
>squash
>---
> include/linux/frontswap.h | 6 +++---
> mm/frontswap.c | 12 +++++++++---
> mm/swapfile.c | 7 ++++++-
> 3 files changed, 18 insertions(+), 7 deletions(-)
>
>diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
>index 612c176..3d72f14 100644
>--- a/include/linux/frontswap.h
>+++ b/include/linux/frontswap.h
>@@ -20,7 +20,7 @@ extern void frontswap_writethrough(bool);
> #define FRONTSWAP_HAS_EXCLUSIVE_GETS
> extern void frontswap_tmem_exclusive_gets(bool);
>
>-extern void __frontswap_init(unsigned type);
>+extern void __frontswap_init(unsigned type, unsigned long *map);
> extern int __frontswap_store(struct page *page);
> extern int __frontswap_load(struct page *page);
> extern void __frontswap_invalidate_page(unsigned, pgoff_t);
>@@ -122,9 +122,9 @@ static inline void frontswap_invalidate_area(unsigned type)
> __frontswap_invalidate_area(type);
> }
>
>-static inline void frontswap_init(unsigned type)
>+static inline void frontswap_init(unsigned type, unsigned long *map)
> {
>- __frontswap_init(type);
>+ __frontswap_init(type, map);
> }
>
> #endif /* _LINUX_FRONTSWAP_H */
>diff --git a/mm/frontswap.c b/mm/frontswap.c
>index ebf4c18..8254a6a 100644
>--- a/mm/frontswap.c
>+++ b/mm/frontswap.c
>@@ -127,8 +127,13 @@ struct frontswap_ops *frontswap_register_ops(struct frontswap_ops *ops)
> int i;
>
> for (i = 0; i < MAX_SWAPFILES; i++) {
>- if (test_and_clear_bit(i, need_init))
>+ if (test_and_clear_bit(i, need_init)) {
>+ struct swap_info_struct *sis = swap_info[i];
>+ /* enable_swap_info _should_ have set it! */
>+ if (!sis->frontswap_map)
>+ return ERR_PTR(-EINVAL);
> ops->init(i);
>+ }
> }
> /*
> * We MUST have frontswap_ops set _after_ the frontswap_init's
>@@ -166,14 +171,15 @@ EXPORT_SYMBOL(frontswap_tmem_exclusive_gets);
> *
> * Can be called without any backend driver is registered.
> */
>-void __frontswap_init(unsigned type)
>+void __frontswap_init(unsigned type, unsigned long *map)
> {
> struct swap_info_struct *sis = swap_info[type];
>
> if (static_key_false(&frontswap_key)) {
> BUG_ON(sis == NULL);
>- if (sis->frontswap_map == NULL)
>+ if (!map)
> return;
>+ frontswap_map_set(sis, map);
> frontswap_ops->init(type);
> }
> else {
>diff --git a/mm/swapfile.c b/mm/swapfile.c
>index e97a0e5..c1c3a62 100644
>--- a/mm/swapfile.c
>+++ b/mm/swapfile.c
>@@ -1454,6 +1454,10 @@ static void _enable_swap_info(struct swap_info_struct *p, int prio,
> else
> p->prio = --least_priority;
> p->swap_map = swap_map;
>+ /*
>+ * This is required for frontswap to handle backends loading
>+ * after the swap has been activated.
>+ */
> frontswap_map_set(p, frontswap_map);
Why set frontswap_map twice?
> p->flags |= SWP_WRITEOK;
> nr_swap_pages += p->pages;
>@@ -1477,9 +1481,9 @@ static void enable_swap_info(struct swap_info_struct *p, int prio,
> unsigned char *swap_map,
> unsigned long *frontswap_map)
> {
>+ frontswap_init(p->type, frontswap_map);
> spin_lock(&swap_lock);
> _enable_swap_info(p, prio, swap_map, frontswap_map);
>- frontswap_init(p->type);
> spin_unlock(&swap_lock);
> }
>
>@@ -1589,6 +1593,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
> p->swap_map = NULL;
> p->flags = 0;
> frontswap_invalidate_area(type);
>+ frontswap_map_set(p, NULL);
This will lead to memory leak, the memory will not be freed since
vfree(frontswap_map_get(p)); will miss it. :(
> spin_unlock(&swap_lock);
> mutex_unlock(&swapon_mutex);
> vfree(swap_map);
>--
>1.7.11.7
>
>--
>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>
--
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>
next prev parent reply other threads:[~2013-02-03 8:43 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-01 20:22 [PATCH v2] Make frontswap+cleancache and its friend be modularized Konrad Rzeszutek Wilk
2013-02-01 20:22 ` Konrad Rzeszutek Wilk
2013-02-01 20:22 ` [PATCH 01/15] mm: cleancache: lazy initialization to allow tmem backends to build/run as modules Konrad Rzeszutek Wilk
2013-02-01 20:22 ` Konrad Rzeszutek Wilk
2013-02-03 8:06 ` Ric Mason
2013-02-03 8:06 ` Ric Mason
2013-02-01 20:22 ` [PATCH 02/15] mm: frontswap: " Konrad Rzeszutek Wilk
2013-02-01 20:22 ` Konrad Rzeszutek Wilk
2013-02-03 7:07 ` Ric Mason
2013-02-03 7:07 ` Ric Mason
2013-02-04 5:53 ` Bob Liu
2013-02-04 5:53 ` Bob Liu
2013-02-05 0:23 ` Ric Mason
2013-02-05 0:23 ` Ric Mason
2013-02-01 20:22 ` [PATCH 03/15] frontswap: Make frontswap_init use a pointer for the ops Konrad Rzeszutek Wilk
2013-02-01 20:22 ` Konrad Rzeszutek Wilk
2013-02-01 20:22 ` [PATCH 04/15] cleancache: Make cleancache_init " Konrad Rzeszutek Wilk
2013-02-01 20:22 ` Konrad Rzeszutek Wilk
2013-02-01 20:22 ` [PATCH 05/15] staging: zcache: enable ramster to be built/loaded as a module Konrad Rzeszutek Wilk
2013-02-01 20:22 ` Konrad Rzeszutek Wilk
2013-02-01 20:22 ` [PATCH 06/15] staging: zcache: enable zcache " Konrad Rzeszutek Wilk
2013-02-01 20:22 ` Konrad Rzeszutek Wilk
2013-02-01 20:22 ` [PATCH 07/15] xen: tmem: enable Xen tmem shim " Konrad Rzeszutek Wilk
2013-02-01 20:22 ` Konrad Rzeszutek Wilk
2013-02-01 20:22 ` [PATCH 08/15] xen/tmem: Remove the subsys call Konrad Rzeszutek Wilk
2013-02-01 20:22 ` Konrad Rzeszutek Wilk
2013-02-01 20:22 ` [PATCH 09/15] frontswap: Remove the check for frontswap_enabled Konrad Rzeszutek Wilk
2013-02-01 20:22 ` Konrad Rzeszutek Wilk
2013-02-01 20:22 ` [PATCH 10/15] frontswap: Use static_key instead of frontswap_enabled and frontswap_ops Konrad Rzeszutek Wilk
2013-02-01 20:22 ` Konrad Rzeszutek Wilk
2013-02-01 20:23 ` [PATCH 11/15] cleancache: Remove the check for cleancache_enabled Konrad Rzeszutek Wilk
2013-02-01 20:23 ` Konrad Rzeszutek Wilk
2013-02-01 20:23 ` [PATCH 12/15] cleancache: Use static_key instead of cleancache_ops and cleancache_enabled Konrad Rzeszutek Wilk
2013-02-01 20:23 ` Konrad Rzeszutek Wilk
2013-02-01 20:23 ` [PATCH 13/15] frontswap: Get rid of swap_lock dependency Konrad Rzeszutek Wilk
2013-02-01 20:23 ` Konrad Rzeszutek Wilk
2013-02-03 8:43 ` Wanpeng Li
2013-02-03 8:43 ` Wanpeng Li [this message]
2013-02-03 8:43 ` Wanpeng Li
2013-02-01 20:23 ` [PATCH 14/15] zcache/tmem: Better error checking on frontswap_register_ops return value Konrad Rzeszutek Wilk
2013-02-01 20:23 ` Konrad Rzeszutek Wilk
2013-02-01 20:23 ` [PATCH 15/15] xen/tmem: Add missing %s in the printk statement Konrad Rzeszutek Wilk
2013-02-01 20:23 ` Konrad Rzeszutek Wilk
2013-02-03 8:52 ` [PATCH v2] Make frontswap+cleancache and its friend be modularized Ric Mason
2013-02-03 8:52 ` Ric Mason
2013-02-04 15:14 ` Seth Jennings
2013-02-04 15:14 ` Seth Jennings
2013-02-05 0:21 ` Ric Mason
2013-02-05 0:21 ` Ric Mason
2013-02-05 0:38 ` Konrad Rzeszutek Wilk
2013-02-05 0:38 ` Konrad Rzeszutek Wilk
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='20130203084337.GA28710@hacker.(null)' \
--to=liwanp@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=dan.magenheimer@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=konrad.wilk@oracle.com \
--cc=konrad@darnok.org \
--cc=konrad@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=ngupta@vflare.org \
--cc=rcj@linux.vnet.ibm.com \
--cc=sjenning@linux.vnet.ibm.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.