Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1329290lqj; Mon, 3 Jun 2024 19:17:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUII7gfvzEzS+X64+i3yutwGIuLdOpAam8rxoxXZGcx5FXIbdUitWR/qdpdRSQDP2rJ8SOLbmkxGiux7nkuUaOyJFnP39MOlqKKpGb1JQ== X-Google-Smtp-Source: AGHT+IGOjc5z5zZSVp5Mr99wEpLx8MfqVMbyuC3iqi/nLqXrbYrRXmEEOJP/dDb9AHSK/bVTPIfx X-Received: by 2002:a05:6a21:99a0:b0:1a7:9476:6cb9 with SMTP id adf61e73a8af0-1b26f205182mr12158844637.32.1717467469193; Mon, 03 Jun 2024 19:17:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717467469; cv=pass; d=google.com; s=arc-20160816; b=uy8SXi/A1iDvh7BoayHc0f0o1yGDLKT+MXPZdKZNcoUiPXvo/ChsyrRjsT33zsNwof 2vuEJa/9gOD6Oh9qttVV+Re6MoZPgnhmyJSZQ5chnacED/Sldr+TxEgtVkU1beNA/NCQ NlnAMLUi52pWNhQe2hWEYn1TvAAJLZknFRWyjdwy+hkZiLK1DxnW8zihsDAQaMwGNGr6 ItZRzQOyJE4F3zxit0aINsK4kl3zh2bVcYU0x1l251mrDeQQxuZE8aKlRkMpJicyVb3S s0H3Q3m3o5/tWITcI10u3xAICQAW6BlHjKm3UnRfFub+SOmPV/q+EG6RBQOAD5Plvw9K ebGg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=Qe5hOBNaCqLZm/rRI4XccAdFKiV/c/Rsd9mYPA/Q9+4=; fh=3usbR7QZpG35gh72IbXjKwqKygaVHr3K75aZ6wxw5MU=; b=qWkawBA1DMuBTPHsJpQJHPnOszH+P3ViRsPvf3h37J19e8dsqUKobhWAfbIugzTJYl 6SCweZ1oRgkWsUXVGBlubjN9weSe/NSz0VTdBGFzOBw9Ne3PrC1VJv2WofLvaPhKis1D oBGdwNSE0iEQJMTZK+UMIviCpI2lNqhwUMcqJwnv1/H+DkjKv2xy6hBSnlGh7LMzEbbl vTAgxwH/j7vsUzAqfYyoWkGakBlRhtRMvWp8XsXj2PDPXY57lWg36S3K+C/T4OWZi76Z pd+iaRjj7FijV0FxVKpM/yLD3NaRLBKwKTrpRtKYK+ooqW1oxuBnIglQXPOeTuMkN3Yf 4fZQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=KYk0RwQB; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-199940-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199940-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-70242d59049si349584b3a.356.2024.06.03.19.17.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 19:17:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199940-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=KYk0RwQB; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-199940-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199940-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com 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 9B428B263C8 for ; Tue, 4 Jun 2024 01:59:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A3D713D88C; Tue, 4 Jun 2024 01:57:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="KYk0RwQB" Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (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 248CD137924; Tue, 4 Jun 2024 01:57:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717466229; cv=none; b=Y9iQS8Wmt8Hl1lXHvDFOz1j9BIyO7C79hZgtENJPMW54swk2zNNiBVm9NLTNk/Ylz8HprMmV1Io0qaoL1ovtmaZbArououWEGYN8uCOsD2EQZK8P49+d6iosdlO0p2+VxP8TLFGBl4M7Aq1kzVaoncj/guw4W9rBW2Q7Ah44uZc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717466229; c=relaxed/simple; bh=vAHxqC5p21VJM3W0tqZX2heKAMVPYr0MbjkwYfHJtjg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=MH+Wh2kvKEB/GTnnza880hSjdDk3mnopl278DiLM6OsNti6k33d8BeDFwOTFoiFTFE4bPYHnL8+qUG2NW/HJTucZNYt8uhXyosBqXd0vq0Lrb+tRk7HMH/E9wOhc+wyN2fBuZKhpDGKJZqN5/lsgimo5EJwOVPp93C8a/ugmaLw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=KYk0RwQB; arc=none smtp.client-ip=115.124.30.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1717466223; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=Qe5hOBNaCqLZm/rRI4XccAdFKiV/c/Rsd9mYPA/Q9+4=; b=KYk0RwQBbcDcuNn16o9LuVna9X2GOCX0hAmMEqkXATC1hUwWV+ErGwPBOKzmfnEdZhsuEsywBx6sXkr5kFA+sg4eyH0St+eEgNjzinQnRJPBQQnMVX3SgLFuoHT2Smq3wIKU7y/Y5aVSVmVsl8HeFjuJTo5jZ+5kDueEo3IKt/Q= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067112;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0W7p7gKf_1717466222; Received: from 30.221.146.134(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0W7p7gKf_1717466222) by smtp.aliyun-inc.com; Tue, 04 Jun 2024 09:57:03 +0800 Message-ID: Date: Tue, 4 Jun 2024 09:57:01 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [HELP] FUSE writeback performance bottleneck To: Miklos Szeredi , Bernd Schubert Cc: "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , lege.wang@jaguarmicro.com References: <495d2400-1d96-4924-99d3-8b2952e05fc3@linux.alibaba.com> <67771830-977f-4fca-9d0b-0126abf120a5@fastmail.fm> Content-Language: en-US From: Jingbo Xu In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Bernd and Miklos, On 6/3/24 11:19 PM, Miklos Szeredi wrote: > On Mon, 3 Jun 2024 at 16:43, Bernd Schubert wrote: >> >> >> >> On 6/3/24 08:17, Jingbo Xu wrote: >>> Hi, Miklos, >>> >>> We spotted a performance bottleneck for FUSE writeback in which the >>> writeback kworker has consumed nearly 100% CPU, among which 40% CPU is >>> used for copy_page(). >>> >>> fuse_writepages_fill >>> alloc tmp_page >>> copy_highpage >>> >>> This is because of FUSE writeback design (see commit 3be5a52b30aa >>> ("fuse: support writable mmap")), which newly allocates a temp page for >>> each dirty page to be written back, copy content of dirty page to temp >>> page, and then write back the temp page instead. This special design is >>> intentional to avoid potential deadlocked due to buggy or even malicious >>> fuse user daemon. >> >> I also noticed that and I admin that I don't understand it yet. The commit says >> >> >> The basic problem is that there can be no guarantee about the time in which >> the userspace filesystem will complete a write. It may be buggy or even >> malicious, and fail to complete WRITE requests. We don't want unrelated parts >> of the system to grind to a halt in such cases. >> >> >> >> Timing - NFS/cifs/etc have the same issue? Even a local file system has no guarantees >> how fast storage is? > > I don't have the details but it boils down to the fact that the > allocation context provided by GFP_NOFS (PF_MEMALLOC_NOFS) cannot be > used by the unprivileged userspace server (and even if it could, > there's no guarantee, that it would). > > When this mechanism was introduced, the deadlock was a real > possibility. I'm not sure that it can still happen, but proving that > it cannot might be difficult. IIUC, there are two sources that may cause deadlock: 1) the fuse server needs memory allocation when processing FUSE_WRITE requests, which in turn triggers direct memory reclaim, and FUSE writeback then - deadlock here 2) a process that trigfgers direct memory reclaim or calls sync(2) may hang there forever, if the fuse server is buggyly or malicious and thus hang there when processing FUSE_WRITE requests Thus the temp page design was introduced to avoid the above potential issues. I think case 1 may be fixed (if any), but I don't know how case 2 can be avoided as any one could run a fuse server in unprivileged mode. Or if case 2 really matters? Please correct me if I miss something. -- Thanks, Jingbo