Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1706346lqe; Mon, 8 Apr 2024 18:48:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVXgR4bKVZsMM4HsggTU2gHsLqIvcIqqVwdJtZKEBRA3ysSiAKM2IRjjexlConQPi8iDWYUp+m82kVY9S7iq89wC2bAV9x68YB4Mt7geg== X-Google-Smtp-Source: AGHT+IEYuZ7A0/FsmWph+CI/IcTeVqyNntYGisy1Lmr1TY1TxRS2aoWoSkJuNUifG+ClbLWYEyCd X-Received: by 2002:ad4:5c6b:0:b0:69b:a42:5c85 with SMTP id i11-20020ad45c6b000000b0069b0a425c85mr9066523qvh.30.1712627317428; Mon, 08 Apr 2024 18:48:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712627317; cv=pass; d=google.com; s=arc-20160816; b=Xfhh6ic5Aq0T94/u+oDgdf2GV/+a7jjXeZEG4uhFuJJ3bTo1Lii1/4BMKGFCQ3/jvm dD8dMdw9SHfhq7CUwHMVhZle50Dm+cGTqU688HqyGlilafLxMP6bXrGmsmtQ1TnXk64p Xc7jBP5HhNq7VidDFeSjBe8TUYIroXw+Krptn3xFIJ0Sv/7yNaObZZ0ChZKGvJAoijt5 TflnD3+5mQu/m+YNHHXgzvzV6YuewE3rGpjjb+2L8ax72UUzOueYo321tYAjS52hPbxt ALNH6KQry1xeonhTyJJy0gy8nHec320UJkz2HYm5fQa2a8VZzSyhH44AicsOx3H98nhQ mZ1A== ARC-Message-Signature: i=2; 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=lRfcaVutx+iLaik+0ijMJHKuAnVwCrcMyXNgGgNDpNY=; fh=B13uBUlllhB0ECr4ySwpmH9VYu8F1CJh8upY3m083ls=; b=ke0a/uGbTuKQi0Cel3MGaa+gppWDPjtiORn4eRPptO6t1ymNuV0Pe3XplqNTlOcvg8 krT3B7EWI3ZRPTgeHbSLpgPAMy7ADos6X5fqqBzeR0xI7C+XvIYvT/mDxF2VFO3hrqbb zYMJ2OErTvKJmmYMvUOzvJkpjughmQplHZnwsBPCVUWcmtCglOBDcbjVcfcu1cwnp7CQ Vmn7sbNWPQUD5+Ydg+ILE8YS5FnlPKc39e9BTsJ6MsAK+e5+r8iYc8rVLrum3i5CuIvy Ma77R9fom1qE5qTeKFQgJOMW30A7FBMxEyQJNMXATvZb4AlSmMQeVHWm4xIq5SVJh0LJ sA2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-136101-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136101-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id qd20-20020ad44814000000b00696b323a01asi9383414qvb.604.2024.04.08.18.48.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 18:48:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136101-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-136101-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136101-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 200D41C213AA for ; Tue, 9 Apr 2024 01:48:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61CD54EB51; Tue, 9 Apr 2024 01:48:28 +0000 (UTC) Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (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 0D4934E1BE; Tue, 9 Apr 2024 01:48:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712627307; cv=none; b=Z6wBeJubztPrwvFobNelA95x0/552vjtUln8fzqk1E49Pkx4jVeKFa9CicGUxkpXBwnwnD49e+kE4Lp3Armf+t7onDfRXdeQG3i+a2oj5THFunfe20sLdec1+sGg3xKw7Qbuoe3pvVf4SOyPm4XVN2TIKPOSo90Iijhljh8Gt8g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712627307; c=relaxed/simple; bh=9HFrFIth3R0zd7PPhTEec3H/FKVeAX/QIKtgfQNhbE4=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=bjZ5IgaPA9QgK2Y+EtLW+rORSEY2Jp3gYgfu5Qh0q8qEjbljvI55h4vs62vj4sjyeOVr75/IYqtW3ajcTGptsL+vLfyXuhwC386FiyHvH14FQOCZaX55YEq2vcDgY3lESBAeLyL1hJWA9/MoZreIyblskWPFqz6PVo8ZUs3Oqb0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VD8496jQNz4f3jkL; Tue, 9 Apr 2024 09:48:09 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.252]) by mail.maildlp.com (Postfix) with ESMTP id 524C81A0BD5; Tue, 9 Apr 2024 09:48:14 +0800 (CST) Received: from [10.174.176.117] (unknown [10.174.176.117]) by APP3 (Coremail) with SMTP id _Ch0CgA3955YnhRmd5ZhJQ--.9921S2; Tue, 09 Apr 2024 09:48:12 +0800 (CST) Subject: Re: [PATCH v2 0/6] virtiofs: fix the warning for ITER_KVEC dio To: "Michael S. Tsirkin" Cc: linux-fsdevel@vger.kernel.org, Miklos Szeredi , Vivek Goyal , Stefan Hajnoczi , Bernd Schubert , Matthew Wilcox , Benjamin Coddington , linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, houtao1@huawei.com References: <20240228144126.2864064-1-houtao@huaweicloud.com> <20240408034514-mutt-send-email-mst@kernel.org> From: Hou Tao Message-ID: <413bd868-a16b-f024-0098-3c70f7808d3c@huaweicloud.com> Date: Tue, 9 Apr 2024 09:48:08 +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: <20240408034514-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-CM-TRANSID:_Ch0CgA3955YnhRmd5ZhJQ--.9921S2 X-Coremail-Antispam: 1UD129KBjvJXoWxAFW7tw17Jw13WF4DAF43Wrg_yoW5tFyxpr Wftan0grsxXFy7Arnay3Z5Cr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024 at 10:41:20PM +0800, Hou Tao wrote: >> From: Hou Tao >> >> Hi, >> >> The patch set aims to fix the warning related to an abnormal size >> parameter of kmalloc() in virtiofs. The warning occurred when attempting >> to insert a 10MB sized kernel module kept in a virtiofs with cache >> disabled. As analyzed in patch #1, the root cause is that the length of >> the read buffer is no limited, and the read buffer is passed directly to >> virtiofs through out_args[0].value. Therefore patch #1 limits the >> length of the read buffer passed to virtiofs by using max_pages. However >> it is not enough, because now the maximal value of max_pages is 256. >> Consequently, when reading a 10MB-sized kernel module, the length of the >> bounce buffer in virtiofs will be 40 + (256 * 4096), and kmalloc will >> try to allocate 2MB from memory subsystem. The request for 2MB of >> physically contiguous memory significantly stress the memory subsystem >> and may fail indefinitely on hosts with fragmented memory. To address >> this, patch #2~#5 use scattered pages in a bio_vec to replace the >> kmalloc-allocated bounce buffer when the length of the bounce buffer for >> KVEC_ITER dio is larger than PAGE_SIZE. The final issue with the >> allocation of the bounce buffer and sg array in virtiofs is that >> GFP_ATOMIC is used even when the allocation occurs in a kworker context. >> Therefore the last patch uses GFP_NOFS for the allocation of both sg >> array and bounce buffer when initiated by the kworker. For more details, >> please check the individual patches. >> >> As usual, comments are always welcome. >> >> Change Log: > Bernd should I just merge the patchset as is? > It seems to fix a real problem and no one has the > time to work on a better fix .... WDYT? Sorry for the long delay. I am just start to prepare for v3. In v3, I plan to avoid the unnecessary memory copy between fuse args and bio_vec. Will post it before next week. > > >> v2: >> * limit the length of ITER_KVEC dio by max_pages instead of the >> newly-introduced max_nopage_rw. Using max_pages make the ITER_KVEC >> dio being consistent with other rw operations. >> * replace kmalloc-allocated bounce buffer by using a bounce buffer >> backed by scattered pages when the length of the bounce buffer for >> KVEC_ITER dio is larger than PAG_SIZE, so even on hosts with >> fragmented memory, the KVEC_ITER dio can be handled normally by >> virtiofs. (Bernd Schubert) >> * merge the GFP_NOFS patch [1] into this patch-set and use >> memalloc_nofs_{save|restore}+GFP_KERNEL instead of GFP_NOFS >> (Benjamin Coddington) >> >> v1: https://lore.kernel.org/linux-fsdevel/20240103105929.1902658-1-houtao@huaweicloud.com/ >> >> [1]: https://lore.kernel.org/linux-fsdevel/20240105105305.4052672-1-houtao@huaweicloud.com/ >> >> Hou Tao (6): >> fuse: limit the length of ITER_KVEC dio by max_pages >> virtiofs: move alloc/free of argbuf into separated helpers >> virtiofs: factor out more common methods for argbuf >> virtiofs: support bounce buffer backed by scattered pages >> virtiofs: use scattered bounce buffer for ITER_KVEC dio >> virtiofs: use GFP_NOFS when enqueuing request through kworker >> >> fs/fuse/file.c | 12 +- >> fs/fuse/virtio_fs.c | 336 +++++++++++++++++++++++++++++++++++++------- >> 2 files changed, 296 insertions(+), 52 deletions(-) >> >> -- >> 2.29.2