Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1452937pxb; Thu, 24 Mar 2022 21:27:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWakcpU0hGwQxZsLXq9+DBw9LpKpwNfBbiDyECpTTgZ+V4QxYfiXJlNwdwaLkitTnCBG94 X-Received: by 2002:a17:907:96ab:b0:6e0:ed5:7c22 with SMTP id hd43-20020a17090796ab00b006e00ed57c22mr9454712ejc.467.1648182439980; Thu, 24 Mar 2022 21:27:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648182439; cv=none; d=google.com; s=arc-20160816; b=Ayp3YqtjXrzDvWtchjZeropuNyX2opFgsAAUwqr3UeeBoHJ0kxnZ3wXyCT4g7dx0F/ JXbMoWngvDn2yqfsNEhSfjjc7JOa6AJlX3D0bLKzngeKPitJJMNbHmFV8uAT/ZshjOde fjxUqX5al71MirJXL6A72VZ+E97+DCPx2uLSjxDRAQPUC6FZ2VkWJR82QE5oU903bC2b NifXOrrToQgZ6bWPOqtLJ8f+/5wcg4hb4vJ8hu02WXPZ1khNEGsL3wkQiq+nPG8Cf6Zc Xwjm6ZvjlBxBUm4lgRU60XlgEYbGgRi+Z6oO0rfqgf/WF12gi3Cgh/XFVZ8n9+6nKS4A dlcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Q428jPB3LI7YHZ1TPk4eUv6mjfb7Ccik6IuwbzunlN8=; b=AxsiaLpGleIvxFWp3ot9HIjYxpU7UmNQ91XLc6Dc5GqDeV+MoxyBiz5s6jrtkFP/Yv 0YzV1xHkQ8sk4kku/HIPq1nQ7fjPaLKVauJCn1RcscPv5FHKgHfsayXf4kKXVzN7XB/P lNyyOjiB1gBez07xAin4BJsvliPlSR7fdRS4mFCjLq9GQMv9LuGXGeqvfae/blqZCuwu 8LxBNdT3Zintc6dQRI5fxDX5PnX77KwJwWJrM22CAXnGAJhI4C0med6Vpkke3rmCSv88 Gcx3ZbIykycK4ZGJ2NbAN5i3NfRxufrcnvnDSnNpkxLdDRwaYVEHOAdNGhrGt68AZyFG JzGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=qk78RGmu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c1-20020a170906924100b006df76385e5bsi1303434ejx.763.2022.03.24.21.26.50; Thu, 24 Mar 2022 21:27:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=qk78RGmu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235691AbiCWLXP (ORCPT + 99 others); Wed, 23 Mar 2022 07:23:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243866AbiCWLW4 (ORCPT ); Wed, 23 Mar 2022 07:22:56 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AFA37893C for ; Wed, 23 Mar 2022 04:21:26 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id bi12so2174323ejb.3 for ; Wed, 23 Mar 2022 04:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Q428jPB3LI7YHZ1TPk4eUv6mjfb7Ccik6IuwbzunlN8=; b=qk78RGmu57m+WoTO9wCDpvaz8ymit5RglIS5kWuFOL3VPbzAb56W2jFcujjmoJ/UGs 3EMPCUm15+UV7uYDmswOYIvQIRmiOmXioXyrRkhAZgoLMXbJ+zsL9cKQLdgUtLWFtVkT Z3S+uVKDof7qiuUWrur20pLRxaVjPJzXAaT9Emz+jj9qoCBPt4uM9eUeb0J27HVnDGdm aPrDDx/gd+JHrEaI5SEKc48yhCncdM2nrlC5X/9w4AU/s8nHQ0fGcvwlLyX0/6ayhbNl T6vs+W+6SaJZP90z0JVLIAefcdVL2wcfO6TlH6LbtjOol8X4VugVItB/ReHWiQtK6JrY hVxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Q428jPB3LI7YHZ1TPk4eUv6mjfb7Ccik6IuwbzunlN8=; b=WFM7XRbKB3fGaWa2Zk+Z1jD/U+SwGy8SC+XEGqZqVxXze9KjVYFlVaZaHJXfzYTOZ9 DJEDQifVddR3MiD8cT5Zn1wSseX0dMk8ETnzzR2S1M8/ZXuraRTSMrGFUFT2Qqqm/e0E mYOH+GuJ00ccbbT5QrmADEKLSCA0fsSkAHSxiGxHCFh5/kaFiqv61WX/ZcEnLjleUN/W bv/M4ESGvE2rOCOQaCYvht6X0xl/jP0lt18Mbxr6MqfEkiIwu9mGtSeZf5NbMoOHdy+W dr/ZqHukByQNaJIrodrGJrAhmoPw1UQQXJ0V80RmSJCzFxazeyLB3072mkKLs05G1MoL rKog== X-Gm-Message-State: AOAM532GBooFbghwJzF5skBtwbJ/HnJIh0InBLGeKuVF/Z2D2pFvO2vy dMECYqixGDto0v0xMbU0jCLFZ5hr2E0i0KCku/MI X-Received: by 2002:a17:907:6e09:b0:6e0:6bd1:ab5a with SMTP id sd9-20020a1709076e0900b006e06bd1ab5amr1173845ejc.622.1648034484978; Wed, 23 Mar 2022 04:21:24 -0700 (PDT) MIME-Version: 1.0 References: <20211227091241.103-1-xieyongji@bytedance.com> In-Reply-To: From: Yongji Xie Date: Wed, 23 Mar 2022 19:21:25 +0800 Message-ID: Subject: Re: [PATCH v2] nbd: Don't use workqueue to handle recv work To: Josef Bacik Cc: Jens Axboe , Bart Van Assche , linux-block@vger.kernel.org, nbd@other.debian.org, linux-kernel Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 23, 2022 at 4:11 AM Josef Bacik wrote: > > On Mon, Dec 27, 2021 at 05:12:41PM +0800, Xie Yongji wrote: > > The rescuer thread might take over the works queued on > > the workqueue when the worker thread creation timed out. > > If this happens, we have no chance to create multiple > > recv threads which causes I/O hung on this nbd device. > > > > To fix it, we can not simply remove the WQ_MEM_RECLAIM > > flag since the recv work is in the memory reclaim path. > > So this patch tries to create kthreads directly to > > handle the recv work instead of using workqueue. > > > > I still don't understand why we can't drop WQ_MEM_RECLAIM. IIRC your argument > is that we need it because a reconnect could happen under memory pressure and we > need to be able to queue work for that. However your code makes it so we're > just doing a kthread_create(), which isn't coming out of some emergency pool, so > it's just as likely to fail as a !WQ_MEM_RECLAIM workqueue. Thanks, > I think the key point is the context in which the work thread is created. It's the context of the nbd process if using kthread_create() to create a workthread (might do some allocation). Then we can benefit from the PR_SET_IO_FLUSHER flag, so memory reclaim would never hit the page cache on the nbd device. But using queue_work() to create a workthread, the actual thread creation happens in the context of the work thread rather than the nbd process, so we can't rely on the PR_SET_IO_FLUSHER flag to avoid deadlock. Thanks, Yongji