Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4256912pxj; Mon, 21 Jun 2021 17:56:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJoJf4y79YBUnrxt7l6D/bRk9dUK8OjQ0n1eo1c40u6u24ik1RQrDUANSMrwqKXLWnDloF X-Received: by 2002:a92:d601:: with SMTP id w1mr719719ilm.1.1624323362930; Mon, 21 Jun 2021 17:56:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624323362; cv=none; d=google.com; s=arc-20160816; b=RD5E+9uryQ/5qpPa+0cqHdWWpDId49Ibytm/OEN66yAzdY3O9yYdCooJpHtlUzgnZK urTL5BUZps5BqMJn6aq0+jJe+Ip2uYI3gGz8YgofQDFE7eChtnCtR9IZUauT7Hvi3ydj 7d9OytWS4EgP4FG+LeDNAJIRQNvd60WM03eD+5CjmfSMrwHe5MNRxDcyEp7j6l5coGxN Ov0p3EH5wqY59zfvVCnJq1xyNvluFhFq7UD7mVYHFSMKsTMA4480wRmJ8z0lwTKeGn9l Y5vZQXyGimz65sjuRCJ0a4OOQ5rhrDVn3H1x8YgihVGZuqgUQBLOuDHm2rzvT6uaBFzJ yKKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=xpqQD/uU3ejT/3OZLcI9rvtXSr/O76UqcmLAQ1OQrBY=; b=b7z4aKwVURJjKzVJ/XUfkvH1iXXbSBJnjj9vq12tyjmJo3NwbOyAvIG91u7B+IJaTf 0bmWxyK0GLqMktvNVVJz33BV58MBiFlAiiwdVKdIdBpThPEcfBF4c4LoKuvpw92+txxf JyUY1k0K+bEpc+CgyAt9LjfbqRLDYqk5rumahalHhuWIj1jCKm82tCrlQGXODnzQF2q5 naQCgqHnvuD+QrTqUL66uVHclbuTmUVQpJHft/kAsj+ztuzqK9IpErma4G9lURvtby7q SiA3UfxUBZDOdScfAf9DeSQ3hs+MyKWLDdR1kUV4XSxN6Mz+QanuQwnrktdmaRiXqm+5 97mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joshtriplett.org header.s=fm1 header.b=iYQbFqr9; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=Z7sIZbhv; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e7si13812744ilq.68.2021.06.21.17.55.50; Mon, 21 Jun 2021 17:56:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@joshtriplett.org header.s=fm1 header.b=iYQbFqr9; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=Z7sIZbhv; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231132AbhFVA56 (ORCPT + 99 others); Mon, 21 Jun 2021 20:57:58 -0400 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:38533 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230175AbhFVA55 (ORCPT ); Mon, 21 Jun 2021 20:57:57 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id 74D8358095D; Mon, 21 Jun 2021 20:55:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 21 Jun 2021 20:55:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= joshtriplett.org; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:in-reply-to; s=fm1; bh=xpq QD/uU3ejT/3OZLcI9rvtXSr/O76UqcmLAQ1OQrBY=; b=iYQbFqr9pvB1OP1oqpU 98n6GxRau6AUpj5jKVgnkB+5U1gVpzwO1k/51bOHme4mZ+1PmSKJ6msi9Z09a6uW YB5iXNsCgvz3nQfgnfjaEweAyovRikk3aDRkoTQSp2DhthKWegTTCQI2GvIu2AQ5 ejD+tsYiFUHuOMLavzYxfArNiQQWkfkIh5TZTRtkcv3vXg/W5WdSPHujLVB82m+V fiO1EFSZd+z9RSmC7XsyIZrmtYM11IGANlBLG9MaGONCKCoqzkPMk1WrCC08eLkF HDyK7sl0PmcRaE7NY8t0hg62gYsm7GSFIBx1kQjRraROMAWQHGgfhPO6Woo1x/2w WPA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=xpqQD/ uU3ejT/3OZLcI9rvtXSr/O76UqcmLAQ1OQrBY=; b=Z7sIZbhvpLekDmIRooBJew W+fcNp9v2SC/TLgo1tyezyFKIOjQPyYjS6jE/Ju26ENxF/NtMCv6O+qdgwBYxY4A H9kLXkCeZPeOMy0C9B5Zk7OO5nBViVrXHCu0bvzizAdKnRbB7OljziHRK/yM80ZU lJIWjQY9BbeaBRNeWpQl4+JsUAsLknBRCvAD57EMfmFL3NNIlTjhTCgnXFXiaoI6 ipMIRHNlNhtnAYzz7rNJMzg92zLLdrOsEoAYnBA5gPWyH1QFIZG1UYe4zi9+RlA6 hECrdFUu7pYS/qMphqNfvUw54LnuG+zVp59dCGYXxkQ/VjbdOiZ+CKiBGYI/NC2Q == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeegtddggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeflohhshhcu vfhrihhplhgvthhtuceojhhoshhhsehjohhshhhtrhhiphhlvghtthdrohhrgheqnecugg ftrfgrthhtvghrnhepgeeihfduleeivefgudffjeffheehkeeiieetueevkeelhffgiedv fffhveffleelnecuffhomhgrihhnpehmrghrtgdrihhnfhhonecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepjhhoshhhsehjohhshhhtrhhiphhl vghtthdrohhrgh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 21 Jun 2021 20:55:40 -0400 (EDT) Date: Mon, 21 Jun 2021 17:55:39 -0700 From: Josh Triplett To: Wang Jianchao Cc: Theodore Ts'o , Andreas Dilger , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, lishujin@kuaishou.com Subject: Re: [PATCH V2 7/7] ext4: get discard out of jbd2 commit kthread contex Message-ID: References: <164ffa3b-c4d5-6967-feba-b972995a6dfb@gmail.com> <49382052-6238-f1fb-40d1-b6b801b39ff7@gmail.com> <48e33dea-d15e-f211-0191-e01bd3eb17b3@gmail.com> <67eeb65a-d413-c4f9-c06f-d5dcceca0e4f@gmail.com> <0b7915bc-193a-137b-4e52-8aaef8d6fef3@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Wed, May 26, 2021 at 04:44:06PM +0800, Wang Jianchao wrote: > Right now, discard is issued and waited to be completed in jbd2 > commit kthread context after the logs are committed. When large > amount of files are deleted and discard is flooding, jbd2 commit > kthread can be blocked for long time. Then all of the metadata > operations can be blocked to wait the log space. > > One case is the page fault path with read mm->mmap_sem held, which > wants to update the file time but has to wait for the log space. > When other threads in the task wants to do mmap, then write mmap_sem > is blocked. Finally all of the following read mmap_sem requirements > are blocked, even the ps command which need to read the /proc/pid/ > -cmdline. Our monitor service which needs to read /proc/pid/cmdline > used to be blocked for 5 mins. > > This patch frees the blocks back to buddy after commit and then do > discard in a async kworker context in fstrim fashion, namely, > - mark blocks to be discarded as used if they have not been allocated > - do discard > - mark them free > After this, jbd2 commit kthread won't be blocked any more by discard > and we won't get NOSPC even if the discard is slow or throttled. > > Link: https://marc.info/?l=linux-kernel&m=162143690731901&w=2 > Suggested-by: Theodore Ts'o > Signed-off-by: Wang Jianchao I tested this patch series atop 5.13.0-rc7 (which took a bit of rebasing), and it works quite well. I tested ext4 on dm-crypt on a laptop NVME drive, using this test case: $ mkdir testdir $ time python3 -c 'for i in range(1000000): open(f"testdir/{i}", "wb").write(b"test data")' $ time rm -r testdir I tried this with and without discard enabled. Without this patch, if discard is enabled, the rm takes many minutes, and stalls out the rest of the system. With this patch, the rm takes the same amount of time (~17s) whether discard is enabled or disabled, and the rest of the system continues to function. Tested-by: Josh Triplett