From: Dan Streetman <ddstreet@ieee.org> To: Yu Zhao <yuzhao@google.com>, Andrew Morton <akpm@linux-foundation.org>, Seth Jennings <sjenning@redhat.com> Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>, Minchan Kim <minchan@kernel.org>, Nitin Gupta <ngupta@vflare.org>, Linux-MM <linux-mm@kvack.org>, Sergey Senozhatsky <sergey.senozhatsky@gmail.com>, linux-kernel <linux-kernel@vger.kernel.org>, Dan Streetman <ddstreet@ieee.org>, Dan Streetman <dan.streetman@canonical.com> Subject: [PATCH] mm/zpool: use workqueue for zpool_destroy Date: Mon, 25 Apr 2016 17:20:10 -0400 [thread overview] Message-ID: <1461619210-10057-1-git-send-email-ddstreet@ieee.org> (raw) In-Reply-To: <CALZtONCDqBjL9TFmUEwuHaNU3n55k0VwbYWqW-9dODuNWyzkLQ@mail.gmail.com> Add a work_struct to struct zpool, and change zpool_destroy_pool to defer calling the pool implementation destroy. The zsmalloc pool destroy function, which is one of the zpool implementations, may sleep during destruction of the pool. However zswap, which uses zpool, may call zpool_destroy_pool from atomic context. So we need to defer the call to the zpool implementation to destroy the pool. This is essentially the same as Yu Zhao's proposed patch to zsmalloc, but moved to zpool. Reported-by: Yu Zhao <yuzhao@google.com> Signed-off-by: Dan Streetman <ddstreet@ieee.org> Cc: Dan Streetman <dan.streetman@canonical.com> --- mm/zpool.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mm/zpool.c b/mm/zpool.c index fd3ff71..ea12069 100644 --- a/mm/zpool.c +++ b/mm/zpool.c @@ -23,6 +23,7 @@ struct zpool { const struct zpool_ops *ops; struct list_head list; + struct work_struct work; }; static LIST_HEAD(drivers_head); @@ -197,6 +198,15 @@ struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t gfp, return zpool; } +static void zpool_destroy_pool_work(struct work_struct *work) +{ + struct zpool *zpool = container_of(work, struct zpool, work); + + zpool->driver->destroy(zpool->pool); + zpool_put_driver(zpool->driver); + kfree(zpool); +} + /** * zpool_destroy_pool() - Destroy a zpool * @pool The zpool to destroy. @@ -204,7 +214,8 @@ struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t gfp, * Implementations must guarantee this to be thread-safe, * however only when destroying different pools. The same * pool should only be destroyed once, and should not be used - * after it is destroyed. + * after it is destroyed. This defers calling the implementation + * to a workqueue, so the implementation may sleep. * * This destroys an existing zpool. The zpool should not be in use. */ @@ -215,9 +226,8 @@ void zpool_destroy_pool(struct zpool *zpool) spin_lock(&pools_lock); list_del(&zpool->list); spin_unlock(&pools_lock); - zpool->driver->destroy(zpool->pool); - zpool_put_driver(zpool->driver); - kfree(zpool); + INIT_WORK(&zpool->work, zpool_destroy_pool_work); + schedule_work(&zpool->work); } /** -- 2.7.4
WARNING: multiple messages have this Message-ID (diff)
From: Dan Streetman <ddstreet@ieee.org> To: Yu Zhao <yuzhao@google.com>, Andrew Morton <akpm@linux-foundation.org>, Seth Jennings <sjenning@redhat.com> Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>, Minchan Kim <minchan@kernel.org>, Nitin Gupta <ngupta@vflare.org>, Linux-MM <linux-mm@kvack.org>, Sergey Senozhatsky <sergey.senozhatsky@gmail.com>, linux-kernel <linux-kernel@vger.kernel.org>, Dan Streetman <ddstreet@ieee.org>, Dan Streetman <dan.streetman@canonical.com> Subject: [PATCH] mm/zpool: use workqueue for zpool_destroy Date: Mon, 25 Apr 2016 17:20:10 -0400 [thread overview] Message-ID: <1461619210-10057-1-git-send-email-ddstreet@ieee.org> (raw) In-Reply-To: <CALZtONCDqBjL9TFmUEwuHaNU3n55k0VwbYWqW-9dODuNWyzkLQ@mail.gmail.com> Add a work_struct to struct zpool, and change zpool_destroy_pool to defer calling the pool implementation destroy. The zsmalloc pool destroy function, which is one of the zpool implementations, may sleep during destruction of the pool. However zswap, which uses zpool, may call zpool_destroy_pool from atomic context. So we need to defer the call to the zpool implementation to destroy the pool. This is essentially the same as Yu Zhao's proposed patch to zsmalloc, but moved to zpool. Reported-by: Yu Zhao <yuzhao@google.com> Signed-off-by: Dan Streetman <ddstreet@ieee.org> Cc: Dan Streetman <dan.streetman@canonical.com> --- mm/zpool.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mm/zpool.c b/mm/zpool.c index fd3ff71..ea12069 100644 --- a/mm/zpool.c +++ b/mm/zpool.c @@ -23,6 +23,7 @@ struct zpool { const struct zpool_ops *ops; struct list_head list; + struct work_struct work; }; static LIST_HEAD(drivers_head); @@ -197,6 +198,15 @@ struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t gfp, return zpool; } +static void zpool_destroy_pool_work(struct work_struct *work) +{ + struct zpool *zpool = container_of(work, struct zpool, work); + + zpool->driver->destroy(zpool->pool); + zpool_put_driver(zpool->driver); + kfree(zpool); +} + /** * zpool_destroy_pool() - Destroy a zpool * @pool The zpool to destroy. @@ -204,7 +214,8 @@ struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t gfp, * Implementations must guarantee this to be thread-safe, * however only when destroying different pools. The same * pool should only be destroyed once, and should not be used - * after it is destroyed. + * after it is destroyed. This defers calling the implementation + * to a workqueue, so the implementation may sleep. * * This destroys an existing zpool. The zpool should not be in use. */ @@ -215,9 +226,8 @@ void zpool_destroy_pool(struct zpool *zpool) spin_lock(&pools_lock); list_del(&zpool->list); spin_unlock(&pools_lock); - zpool->driver->destroy(zpool->pool); - zpool_put_driver(zpool->driver); - kfree(zpool); + INIT_WORK(&zpool->work, zpool_destroy_pool_work); + schedule_work(&zpool->work); } /** -- 2.7.4 -- 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:[~2016-04-25 21:22 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-03-29 22:02 [PATCH] zsmalloc: use workqueue to destroy pool in zpool callback Yu Zhao 2016-03-30 0:54 ` Sergey Senozhatsky [not found] ` <20160329235950.GA19927@bbox> 2016-03-31 8:46 ` Sergey Senozhatsky 2016-03-31 8:46 ` Sergey Senozhatsky 2016-03-31 21:46 ` Yu Zhao 2016-03-31 21:46 ` Yu Zhao 2016-03-31 22:05 ` Dan Streetman 2016-03-31 22:05 ` Dan Streetman 2016-04-25 21:20 ` Dan Streetman [this message] 2016-04-25 21:20 ` [PATCH] mm/zpool: use workqueue for zpool_destroy Dan Streetman 2016-04-25 21:46 ` Andrew Morton 2016-04-25 21:46 ` Andrew Morton 2016-04-25 22:18 ` Yu Zhao 2016-04-25 22:18 ` Yu Zhao 2016-04-26 0:59 ` Sergey Senozhatsky 2016-04-26 0:59 ` Sergey Senozhatsky 2016-04-26 11:07 ` Dan Streetman 2016-04-26 11:07 ` Dan Streetman 2016-04-26 21:08 ` [PATCH] mm/zswap: use workqueue to destroy pool Dan Streetman 2016-04-26 21:08 ` Dan Streetman 2016-04-27 0:58 ` Sergey Senozhatsky 2016-04-27 0:58 ` Sergey Senozhatsky 2016-04-27 17:19 ` Dan Streetman 2016-04-27 17:19 ` Dan Streetman 2016-04-28 1:40 ` Sergey Senozhatsky 2016-04-28 1:40 ` Sergey Senozhatsky 2016-04-28 4:09 ` Sergey Senozhatsky 2016-04-28 4:09 ` Sergey Senozhatsky 2016-04-28 8:21 ` Dan Streetman 2016-04-28 8:21 ` Dan Streetman 2016-04-28 9:13 ` [PATCH] mm/zswap: provide unique zpool name Dan Streetman 2016-04-28 9:13 ` Dan Streetman 2016-04-28 22:16 ` Andrew Morton 2016-04-28 22:16 ` Andrew Morton 2016-04-29 0:25 ` Sergey Senozhatsky 2016-04-29 0:25 ` Sergey Senozhatsky 2016-04-29 0:25 ` [PATCH] mm/zswap: use workqueue to destroy pool Sergey Senozhatsky 2016-04-29 0:25 ` Sergey Senozhatsky
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=1461619210-10057-1-git-send-email-ddstreet@ieee.org \ --to=ddstreet@ieee.org \ --cc=akpm@linux-foundation.org \ --cc=dan.streetman@canonical.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=minchan@kernel.org \ --cc=ngupta@vflare.org \ --cc=sergey.senozhatsky.work@gmail.com \ --cc=sergey.senozhatsky@gmail.com \ --cc=sjenning@redhat.com \ --cc=yuzhao@google.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: linkBe 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.