Skip to content

Commit 0b96da6

Browse files
Coly Liaxboe
authored andcommitted
bcache: ignore pending signals when creating gc and allocator thread
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 <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent b74e58c commit 0b96da6

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

drivers/md/bcache/alloc.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include <linux/blkdev.h>
6868
#include <linux/kthread.h>
6969
#include <linux/random.h>
70+
#include <linux/sched/signal.h>
7071
#include <trace/events/bcache.h>
7172

7273
#define MAX_OPEN_BUCKETS 128
@@ -733,8 +734,21 @@ int bch_open_buckets_alloc(struct cache_set *c)
733734

734735
int bch_cache_allocator_start(struct cache *ca)
735736
{
736-
struct task_struct *k = kthread_run(bch_allocator_thread,
737-
ca, "bcache_allocator");
737+
struct task_struct *k;
738+
739+
/*
740+
* In case previous btree check operation occupies too many
741+
* system memory for bcache btree node cache, and the
742+
* registering process is selected by OOM killer. Here just
743+
* ignore the SIGKILL sent by OOM killer if there is, to
744+
* avoid kthread_run() being failed by pending signals. The
745+
* bcache registering process will exit after the registration
746+
* done.
747+
*/
748+
if (signal_pending(current))
749+
flush_signals(current);
750+
751+
k = kthread_run(bch_allocator_thread, ca, "bcache_allocator");
738752
if (IS_ERR(k))
739753
return PTR_ERR(k);
740754

drivers/md/bcache/btree.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/random.h>
3535
#include <linux/rcupdate.h>
3636
#include <linux/sched/clock.h>
37+
#include <linux/sched/signal.h>
3738
#include <linux/rculist.h>
3839
#include <linux/delay.h>
3940
#include <trace/events/bcache.h>
@@ -1913,6 +1914,18 @@ static int bch_gc_thread(void *arg)
19131914

19141915
int bch_gc_thread_start(struct cache_set *c)
19151916
{
1917+
/*
1918+
* In case previous btree check operation occupies too many
1919+
* system memory for bcache btree node cache, and the
1920+
* registering process is selected by OOM killer. Here just
1921+
* ignore the SIGKILL sent by OOM killer if there is, to
1922+
* avoid kthread_run() being failed by pending signals. The
1923+
* bcache registering process will exit after the registration
1924+
* done.
1925+
*/
1926+
if (signal_pending(current))
1927+
flush_signals(current);
1928+
19161929
c->gc_thread = kthread_run(bch_gc_thread, c, "bcache_gc");
19171930
return PTR_ERR_OR_ZERO(c->gc_thread);
19181931
}

0 commit comments

Comments
 (0)