bcache: ignore pending signals when creating gc and allocator thread
authorColy Li <colyli@suse.de>
Thu, 13 Feb 2020 14:12:05 +0000 (22:12 +0800)
committerJens Axboe <axboe@kernel.dk>
Thu, 13 Feb 2020 15:53:49 +0000 (08:53 -0700)
When run a cache set, all the bcache btree node of this cache set will
be checked by bch_btree_check(). If the bcache btree is very large,
iterating all the btree nodes will occupy too much system memory and
the bcache registering process might be selected and killed by system
OOM killer. kthread_run() will fail if current process has pending
signal, therefore the kthread creating in run_cache_set() for gc and
allocator kernel threads are very probably failed for a very large
bcache btree.

Indeed such OOM is safe and the registering process will exit after
the registration done. Therefore this patch flushes pending signals
during the cache set start up, specificly in bch_cache_allocator_start()
and bch_gc_thread_start(), to make sure run_cache_set() won't fail for
large cahced data set.

Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/alloc.c
drivers/md/bcache/btree.c

index a1df0d9..8bc1faf 100644 (file)
@@ -67,6 +67,7 @@
 #include <linux/blkdev.h>
 #include <linux/kthread.h>
 #include <linux/random.h>
+#include <linux/sched/signal.h>
 #include <trace/events/bcache.h>
 
 #define MAX_OPEN_BUCKETS 128
@@ -733,8 +734,21 @@ int bch_open_buckets_alloc(struct cache_set *c)
 
 int bch_cache_allocator_start(struct cache *ca)
 {
-       struct task_struct *k = kthread_run(bch_allocator_thread,
-                                           ca, "bcache_allocator");
+       struct task_struct *k;
+
+       /*
+        * In case previous btree check operation occupies too many
+        * system memory for bcache btree node cache, and the
+        * registering process is selected by OOM killer. Here just
+        * ignore the SIGKILL sent by OOM killer if there is, to
+        * avoid kthread_run() being failed by pending signals. The
+        * bcache registering process will exit after the registration
+        * done.
+        */
+       if (signal_pending(current))
+               flush_signals(current);
+
+       k = kthread_run(bch_allocator_thread, ca, "bcache_allocator");
        if (IS_ERR(k))
                return PTR_ERR(k);
 
index fa872df..b12186c 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/random.h>
 #include <linux/rcupdate.h>
 #include <linux/sched/clock.h>
+#include <linux/sched/signal.h>
 #include <linux/rculist.h>
 #include <linux/delay.h>
 #include <trace/events/bcache.h>
@@ -1913,6 +1914,18 @@ static int bch_gc_thread(void *arg)
 
 int bch_gc_thread_start(struct cache_set *c)
 {
+       /*
+        * In case previous btree check operation occupies too many
+        * system memory for bcache btree node cache, and the
+        * registering process is selected by OOM killer. Here just
+        * ignore the SIGKILL sent by OOM killer if there is, to
+        * avoid kthread_run() being failed by pending signals. The
+        * bcache registering process will exit after the registration
+        * done.
+        */
+       if (signal_pending(current))
+               flush_signals(current);
+
        c->gc_thread = kthread_run(bch_gc_thread, c, "bcache_gc");
        return PTR_ERR_OR_ZERO(c->gc_thread);
 }