Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1386910

[PATCH] mm/zpool: use workqueue for zpool_destroy

From Dan Streetman <ddstreet@ieee.org>
Newsgroups linux.kernel
Subject [PATCH] mm/zpool: use workqueue for zpool_destroy
Date 2016-04-25 23:30 +0200
Message-ID <rrWeS-49v-17@gated-at.bofh.it> (permalink)
References <riSWS-36I-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] mm/zpool: use workqueue for zpool_destroy Dan Streetman <ddstreet@ieee.org> - 2016-04-25 23:30 +0200
  Re: [PATCH] mm/zpool: use workqueue for zpool_destroy Andrew Morton <akpm@linux-foundation.org> - 2016-04-25 23:50 +0200
  Re: [PATCH] mm/zpool: use workqueue for zpool_destroy Yu Zhao <yuzhao@google.com> - 2016-04-26 00:20 +0200
    Re: [PATCH] mm/zpool: use workqueue for zpool_destroy Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-04-26 03:00 +0200
    Re: [PATCH] mm/zpool: use workqueue for zpool_destroy Dan Streetman <ddstreet@ieee.org> - 2016-04-26 13:10 +0200
  [PATCH] mm/zswap: use workqueue to destroy pool Dan Streetman <ddstreet@ieee.org> - 2016-04-26 23:20 +0200
    Re: [PATCH] mm/zswap: use workqueue to destroy pool Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-04-27 03:00 +0200
      Re: [PATCH] mm/zswap: use workqueue to destroy pool Dan Streetman <ddstreet@ieee.org> - 2016-04-27 19:20 +0200
        Re: [PATCH] mm/zswap: use workqueue to destroy pool Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-04-28 03:40 +0200
          Re: [PATCH] mm/zswap: use workqueue to destroy pool Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-04-28 06:10 +0200
          Re: [PATCH] mm/zswap: use workqueue to destroy pool Dan Streetman <ddstreet@ieee.org> - 2016-04-28 10:30 +0200
        [PATCH] mm/zswap: provide unique zpool name Dan Streetman <ddstreet@ieee.org> - 2016-04-28 11:20 +0200

csiph-web