Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp556856rdb; Fri, 5 Jan 2024 22:26:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMZCXJXpbTXDlyW+xTBQE9q1FEAcWw0yMCs2wQ2NOZ8isst0Nbqmpg6TEVZzOsmhpGX+SL X-Received: by 2002:a05:6808:f8c:b0:3bd:20fd:7937 with SMTP id o12-20020a0568080f8c00b003bd20fd7937mr224788oiw.61.1704522395668; Fri, 05 Jan 2024 22:26:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704522395; cv=none; d=google.com; s=arc-20160816; b=aaOSIV0xCPefXvqoS+SH0BG/HN3Nq+uZivE242TRvQnLnSIE2Uml3AjI02ywNPzoj0 6hKZHlKBHg4lmoJOMCDb4ke03T1YkEbFiJCNkCMv4KuJI55n0UUYzxjXUZY65dq2OYA9 MiMIpoir0N131qSCg2HtKotbxJ8XtLgohmFp46TGPMJ5zrVe4NU30UlSPhYZtV0Kh+gU haHznEEIFQ+n3bXdQoJhZj+Oc2ROmpZHbaT5KPbXTOpikNNbU3jCSYax/g831mHw5+4j H6qyW/EVoTgMKcvY9lcORMlNbZ/6AmUvEc2sFm5jB/It+1CFYS99l1cZn8MVq9HL5p4J v1qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-language:content-transfer-encoding:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=thJI1LQKJCaviWpzh/g2txv9qiMXHIGjsify+SZ7L0c=; fh=7LFmtV6kOAwLmDa6rdP0AkhWJAzERDTaaj9TT8cpuDM=; b=SSC58I3I86K80oHncFroa2/1/yJFpWmAZ2Z0ek/HrQmT4Vckv8lVK03tWPqlzpKosH i3z7qwoWCIVnvyFcyyqh55w/cSszOORWWY6r8yW1UaDPvVfFkcu6Wl2Trk5veGi9wy/Q sBCwiVGcB8leYNCgnaQ/QU1QtadM5rkqrEv106I/3BZAEeYKO+FjNdvknMHuY3MShQPK sXukAuV4dmytDUfyeNFP5kuIkaJRnd7CyOTm/ZQJzqfpLamLXcqxnGgJPUpKAylpGbCo X22DD1q+AYtVQGE4tqdXlq6jJwFYBI91JJmOe5Z3GIdjvPpwLKBB1MRuDYF8UxqMWD68 /FTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18515-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18515-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j4-20020aa79284000000b006d996c55d33si2492150pfa.389.2024.01.05.22.26.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 22:26:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18515-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18515-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18515-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7A75DB2308A for ; Sat, 6 Jan 2024 06:26:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E7490440D; Sat, 6 Jan 2024 06:26:17 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 183FC1FB9; Sat, 6 Jan 2024 06:26:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4T6VhH1pt4z4f3l2g; Sat, 6 Jan 2024 14:26:07 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 9B5101A0979; Sat, 6 Jan 2024 14:26:10 +0800 (CST) Received: from [10.174.176.117] (unknown [10.174.176.117]) by APP1 (Coremail) with SMTP id cCh0CgDHlg978phlm+ILAA--.18165S2; Sat, 06 Jan 2024 14:26:07 +0800 (CST) Subject: Re: [PATCH v2] virtiofs: use GFP_NOFS when enqueuing request through kworker To: Vivek Goyal , Matthew Wilcox Cc: linux-fsdevel@vger.kernel.org, Miklos Szeredi , Stefan Hajnoczi , linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, houtao1@huawei.com References: <20240105105305.4052672-1-houtao@huaweicloud.com> From: Hou Tao Message-ID: <9c193ad9-801d-a3d3-faf6-3a655a6fa209@huaweicloud.com> Date: Sat, 6 Jan 2024 14:26:03 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-CM-TRANSID:cCh0CgDHlg978phlm+ILAA--.18165S2 X-Coremail-Antispam: 1UD129KBjvJXoWxXrWxXrW5Ww1xXFyDCw4UJwb_yoW5CF48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 08:57:55PM +0000, Matthew Wilcox wrote: >> On Fri, Jan 05, 2024 at 03:41:48PM -0500, Vivek Goyal wrote: >>> On Fri, Jan 05, 2024 at 08:21:00PM +0000, Matthew Wilcox wrote: >>>> On Fri, Jan 05, 2024 at 03:17:19PM -0500, Vivek Goyal wrote: >>>>> On Fri, Jan 05, 2024 at 06:53:05PM +0800, Hou Tao wrote: >>>>>> From: Hou Tao >>>>>> >>>>>> When invoking virtio_fs_enqueue_req() through kworker, both the >>>>>> allocation of the sg array and the bounce buffer still use GFP_ATOMIC. >>>>>> Considering the size of both the sg array and the bounce buffer may be >>>>>> greater than PAGE_SIZE, use GFP_NOFS instead of GFP_ATOMIC to lower the >>>>>> possibility of memory allocation failure. >>>>>> >>>>> What's the practical benefit of this patch. Looks like if memory >>>>> allocation fails, we keep retrying at interval of 1ms and don't >>>>> return error to user space. Motivation for GFP_NOFS comes another fix proposed for virtiofs [1] in which when trying to insert a big kernel module kept in a cache-disabled virtiofs, the length of fuse args will be large (e.g., 10MB), and the memory allocation in copy_args_to_argbuf() will fail forever. The proposed fix tries to fix the problem by limit the length of data kept in fuse arg, but because the limitation is still large (256KB in that patch), so I think using GFP_NOFS will also be helpful for such memory allocation. [1]: https://lore.kernel.org/linux-fsdevel/20240103105929.1902658-1-houtao@huaweicloud.com/ >>>> You don't deplete the atomic reserves unnecessarily? >>> Sounds reasonable. >>> >>> With GFP_NOFS specificed, can we still get -ENOMEM? Or this will block >>> indefinitely till memory can be allocated. >> If you need the "loop indefinitely" behaviour, that's >> GFP_NOFS | __GFP_NOFAIL. If you're actually doing something yourself >> which can free up memory, this is a bad choice. If you're just sleeping >> and retrying, you might as well have the MM do that for you. Even with GFP_NOFS, I think -ENOMEM is still possible, so the retry logic is still necessary. > I probably don't want to wait indefinitely. There might be some cases > where I might want to return error to user space. For example, if > virtiofs device has been hot-unplugged, then there is no point in > waiting indefinitely for memory allocation. Even if memory was allocated, > soon we will return error to user space with -ENOTCONN. > > We are currently not doing that check after memory allocation failure but > we probably could as an optimization. Yes. It seems virtio_fs_enqueue_req() only checks fsvq->connected before writing sg list to virtual queue, so if the virtio device is hot-unplugged and the free memory is low, it may do unnecessary retry. Even worse, it may hang. I volunteer to post a patch to check the connected status after memory allocation failed if you are OK with that. > > So this patch looks good to me as it is. Thanks Hou Tao. > > Reviewed-by: Vivek Goyal > > Thanks > Vivek