From patchwork Sat Jan 29 07:15:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 12729403 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9A70C433F5 for ; Sat, 29 Jan 2022 07:16:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349266AbiA2HQN (ORCPT ); Sat, 29 Jan 2022 02:16:13 -0500 Received: from www262.sakura.ne.jp ([202.181.97.72]:56848 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241663AbiA2HQM (ORCPT ); Sat, 29 Jan 2022 02:16:12 -0500 Received: from fsav411.sakura.ne.jp (fsav411.sakura.ne.jp [133.242.250.110]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 20T7FX6b082124; Sat, 29 Jan 2022 16:15:33 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav411.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav411.sakura.ne.jp); Sat, 29 Jan 2022 16:15:33 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav411.sakura.ne.jp) Received: from localhost.localdomain (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 20T7FSNs082068 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 29 Jan 2022 16:15:33 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) From: Tetsuo Handa To: Jens Axboe , Christoph Hellwig , Jan Kara , Ming Lei Cc: linux-block@vger.kernel.org, Tetsuo Handa Subject: [PATCH 7/7] loop: use WQ_MEM_RECLAIM flag Date: Sat, 29 Jan 2022 16:15:00 +0900 Message-Id: <20220129071500.3566-8-penguin-kernel@I-love.SAKURA.ne.jp> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20220129071500.3566-1-penguin-kernel@I-love.SAKURA.ne.jp> References: <20220129071500.3566-1-penguin-kernel@I-love.SAKURA.ne.jp> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Allocating kworker threads on demand has a risk of OOM deadlock. Make sure that each loop device has at least one execution context. Cc: Jan Kara Cc: Christoph Hellwig Signed-off-by: Tetsuo Handa --- drivers/block/loop.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index b45198f2d76b..a2f0397d29e5 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1003,11 +1003,20 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, !file->f_op->write_iter) lo->lo_flags |= LO_FLAGS_READ_ONLY; + /* + * Allocate a WQ for this loop device. We can't use a global WQ because + * an I/O request will hung when number of active work hits concurrency + * limit due to stacked loop devices. Also, specify WQ_MEM_RECLAIM in + * order to guarantee that loop_process_work() can start processing an + * I/O request even under memory pressure. As a result, this allocation + * sounds a sort of resource wasting prepared for the worst condition. + * We hope that people utilize ioctl(LOOP_CTL_GET_FREE) in order to + * create only minimal number of loop devices. + */ if (!lo->workqueue) - lo->workqueue = alloc_workqueue("loop%d", - WQ_UNBOUND | WQ_FREEZABLE, - 0, - lo->lo_number); + lo->workqueue = alloc_workqueue("loop%d", WQ_MEM_RECLAIM | + WQ_UNBOUND | WQ_FREEZABLE, + 0, lo->lo_number); if (!lo->workqueue) { error = -ENOMEM; goto out_unlock;