Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3653265ybf; Tue, 3 Mar 2020 09:51:21 -0800 (PST) X-Google-Smtp-Source: ADFU+vsm1PXleGEeO2JFwyAwsUp3xkmcwdfQTz+Adtlpxgw3odBRoQ4KVqx5J1fSuOf+prqQxQcN X-Received: by 2002:a05:6830:16c8:: with SMTP id l8mr4178386otr.2.1583257881097; Tue, 03 Mar 2020 09:51:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583257881; cv=none; d=google.com; s=arc-20160816; b=Z96A7PjKZt7cK8gB8xCG/IR9pr3a+vUn5MBGcQGSJnJgR0I1lJI7JkDkApriKu0xUW p4OWgkHpTYftkKJUUKFZa+ROWNrZPpTrXaTgw5qRFzmedXuquNB1CGBvZHIA+fpi3w+u g0/+M6DGQWQFYZYF8XcV/X7y11RxJfVfYqhmlzB8sgJqkcGbaqOG/Onb2bxhyPTn6Av/ qMN2Ovyd7o3HQYXLUQYaa+0tHAkoSe1k92yXrJsJb9cbM1FBMj0ku2waHdZJdvJivJuZ l4KB5bQi5cGezrCWirPvIMNvJf/pH/SzjdSv7ycyZzTHOwlKRccqeRBhK/tiIQWgDdio tUdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=idc6DiHVXHdOC4ovWyO7TOopBczdEpfyYE777tVpkMg=; b=pIuQKVqov/iT8+5/1ZOOLbb0LVVZx7zGzu8L030NYWAOGfvnZwn83jRISOyTnR23P7 IlBE6SGl8hvs6vZBWfj6iWqljkKgDWe41Ta+Oi6q/Z3usOegEFjGQxL1UMxDOS4EJT3q yHMLC+J0E3OkL3pye6yDpDr5JdVvQqwck5ucZqR1ZW/aJmUmHLq8GRPcDyppb6+yxm3v ZEzD8vQeZIl8BPhKiI3dJCCsbnluMyhTOtoUi08pQpexIr1/eSePTrfh/ce8Ow9a1QPX z5ufaVvQAq2bp3wcCNXJNCooduvrwGXkHTeShwLAMLnfP9F7mniC8z7Rm0t9esVg6Jce B5pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pAERLSMB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n17si5146737otr.177.2020.03.03.09.51.09; Tue, 03 Mar 2020 09:51:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pAERLSMB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730562AbgCCRsz (ORCPT + 99 others); Tue, 3 Mar 2020 12:48:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:56086 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730739AbgCCRsx (ORCPT ); Tue, 3 Mar 2020 12:48:53 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4D75320870; Tue, 3 Mar 2020 17:48:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583257731; bh=TkxtcHX/hfDE6kKJ2CzjP9PIAziqcd/Z3aylXr8hs0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pAERLSMB8IWK4004wCDzjTYS5/M5Unut06eyyXEhRyuAC9MKdZIwO3inJ1zOeFugO xB+Uo8rqmXnzdqv48zrz7tSOYnXohWhc2IL8R0rGOP9xYpe8RR4coEezA4XkE74DyR IM09MmCOotPfk8DXEay/RA/XDBtWTQd+EBQngMLw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Coly Li , Jens Axboe , Sasha Levin Subject: [PATCH 5.5 072/176] bcache: ignore pending signals when creating gc and allocator thread Date: Tue, 3 Mar 2020 18:42:16 +0100 Message-Id: <20200303174312.994115258@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303174304.593872177@linuxfoundation.org> References: <20200303174304.593872177@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Coly Li [ Upstream commit 0b96da639a4874311e9b5156405f69ef9fc3bef8 ] 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 Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/bcache/alloc.c | 18 ++++++++++++++++-- drivers/md/bcache/btree.c | 13 +++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c index a1df0d95151c6..8bc1faf71ff2f 100644 --- a/drivers/md/bcache/alloc.c +++ b/drivers/md/bcache/alloc.c @@ -67,6 +67,7 @@ #include #include #include +#include #include #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); diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 14d6c33b0957e..78f0711a25849 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -1917,6 +1918,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); } -- 2.20.1