Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1204149pxj; Wed, 19 May 2021 00:20:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyV0Jruir2QQT/RJQyZgqviYVkgTRSCrILS1Ee0S8U1CdgcGru/yWCSpgKmdHILcB+jtOKA X-Received: by 2002:a5e:9b06:: with SMTP id j6mr8292630iok.117.1621408829573; Wed, 19 May 2021 00:20:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621408829; cv=none; d=google.com; s=arc-20160816; b=DSUMm3WvjckWdw/0nsLrQZsWdRGyvdkDQgcGEqX5DS+nheBnl+j27H2HQtehgKvTTN 9gkEZqwfiVs2eOEEmbO8kisF7sbnrgvbqUtitPX/y2LwW/lCZIxlaT+zFRaxDsJfpVE+ 1suCDMEYWES/QVUSab7/qhkNotQ2FSccsgIVYxGRuTUbHjfpXmJMwnDqNTYbDkzTrGHZ KtrU6EAl2CkbDjGiuXgeEACELKWEEB7yPR+1qSRc7cEmFngenASECAGNsUtnw2eoEQ7z fUBJfNmCWdJXA+fmqWVHAkipybhepndWEK+nXY7bpb5Vas9Wpdz1kfrhe/T1FZv9yFdZ IEug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=B3Y8K28Bk2cHjlmHVhWfZJK+jWG4xRdwr+oMbl8ZdQQ=; b=x0cbSeKmsUG5Y/iVIf56i7jy+47/3zhZEpH4VcOCk2pLFNr5dwgJprMgEjGIVPgxUd JS53gUVmi0zGjM7ZbKxk76E+oQWrxNLsswRUjLp9pun0E8PJa+TrKdLub9N4Ig1xfybu jIeUIBt1kcBUX5Ev62znCJgJrUXJC1fsOrXmNoUBye2Q7q+EeVXNTLWP6XvafcdSPpEu 0CaXGnNAAoEvojOD97kkILzWyrOkUuNeB3SATmkL3aQwelU2tKx+omnfiPNAPxwUVvvf cYk1qeEa+GZ+F9wrk3+JZVNAg/H/5j8t2mMFLCcxmIPkvRA5f5rkP1bTwnUdIlZKOuoX QYdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LlXudOpB; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i17si3391207iog.70.2021.05.19.00.20.09; Wed, 19 May 2021 00:20:29 -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=@gmail.com header.s=20161025 header.b=LlXudOpB; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240899AbhERBV5 (ORCPT + 99 others); Mon, 17 May 2021 21:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243151AbhERBVv (ORCPT ); Mon, 17 May 2021 21:21:51 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C74BC061573; Mon, 17 May 2021 18:20:34 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id 69so4163298plc.5; Mon, 17 May 2021 18:20:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=B3Y8K28Bk2cHjlmHVhWfZJK+jWG4xRdwr+oMbl8ZdQQ=; b=LlXudOpBBjO0YpuaL67deWpsqGTktYcv0rBm+LPYRFPIwulTRMIH5DmV5F9UNFkVD4 obZKugAeROE7jDI1cN2LE9ZHmhJgQGFvZ0DAYcUQ0kaW6IyyT3ncYHifSUfpl+XdkHp+ NUvjV8gDeEtMGO7aeXUAT+0vSqMdZG0bRqiq3o522zNsHi6OVxnWUcD2VS175FjbChml I4Xva0tj2o0FVAVEsR3o8ZKj2esqJd3BMQLitdgUTyGqX4XIOmJMkJfSC1fiYjsR72N9 6EZ7BCowwi6QxdEQfmHET3J2CBlaShL/8kGF/I/QzN0z+Yi0HFO/PAnwGTCWJPd0tCg+ W3Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=B3Y8K28Bk2cHjlmHVhWfZJK+jWG4xRdwr+oMbl8ZdQQ=; b=crRHDrRo36SN8wk93bGr0AhNM+xBNhUv6/vM4gjkMjpCcmO8iVq674mGUv8NnJly94 fkw++nsnaCc9Bw571ViWuUPZyGxLdYRHlJIgsPmwO55t3acCov/ZM+IyCR6Tr2SO85k0 LwweiVpfg97wVcAqFjZePjX+L7BX8ta0JQokrpEY1qIu1TBwWC2+RDvy4JuKpURCLcD7 CvI9gui85sxoFShfJXeK4WxolBHp/9/RVJOjCZb8gRwpIv1+eprH7cIfR4YUrr+o72ot qfyn38XiE3VRxKF2Gpjt7WuoruumVyyC3BL5aVNcTHlORHcTU9D0aVJyipUgz/BnFy3P 6DZg== X-Gm-Message-State: AOAM531SA0TParVEA1ervmj7vxKaQxxAibinIBQj+uUfR9R6eGHsUkh2 bhdYK35Bc+BjB8ejS+2Gkw+QsqUr9epMoA== X-Received: by 2002:a17:90b:3706:: with SMTP id mg6mr2182256pjb.90.1621300833737; Mon, 17 May 2021 18:20:33 -0700 (PDT) Received: from jianchwadeMacBook-Pro.local ([103.112.79.203]) by smtp.gmail.com with ESMTPSA id u10sm11534497pfl.123.2021.05.17.18.20.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 May 2021 18:20:33 -0700 (PDT) Subject: Re: [PATCH] ext4: get discard out of jbd2 commit kthread To: "Theodore Y. Ts'o" Cc: Andreas Dilger , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org References: <53146e54-af36-0c32-cad8-433460461237@gmail.com> From: Wang Jianchao Message-ID: Date: Tue, 18 May 2021 09:19:13 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On 2021/5/18 4:52 AM, Theodore Y. Ts'o wrote: > On Mon, May 17, 2021 at 11:57:09AM +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 moves the discard out of jbd2 kthread context and do it >> in kworker. And drain the kwork when cannot get space in mb buddy. >> This is done out of jbd2 handle and won't block the commit process. >> After that, we could use blk-wbt or other method to throttle the >> discard and needn't to worry it block the jbd2 commit kthread any >> more. > > Wouldn't be much simpler to do something like this? > > if (discard_bio) { > - submit_bio_wait(discard_bio); > - bio_put(discard_bio); > + submit_bio(discard_bio); > } > > > We're throwing away the return value from submit_bio_wait(), so > there's no real need to wait for I/O to complete so we can fetch the > I/O status. > > That way we don't need to move all of this to a kworker context. The submit_bio also needs to be out of jbd2 commit kthread as it may be blocked due to blk-wbt or no enough request tag. ;) Best Regards Jianchao > > - Ted >