From patchwork Sat Sep 11 09:00:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 1526696 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4H660Y5Nbqz9sXk for ; Sat, 11 Sep 2021 18:51:09 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235458AbhIKIwP (ORCPT ); Sat, 11 Sep 2021 04:52:15 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:9419 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235402AbhIKIwO (ORCPT ); Sat, 11 Sep 2021 04:52:14 -0400 Received: from dggeme754-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H65vK4Tmlz8ySD; Sat, 11 Sep 2021 16:46:37 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggeme754-chm.china.huawei.com (10.3.19.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Sat, 11 Sep 2021 16:51:00 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next v2 1/6] ext4: init seq with random value in kmmpd Date: Sat, 11 Sep 2021 17:00:54 +0800 Message-ID: <20210911090059.1876456-2-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210911090059.1876456-1-yebin10@huawei.com> References: <20210911090059.1876456-1-yebin10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggeme754-chm.china.huawei.com (10.3.19.100) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org If two host has the same nodename, and seq start from 0, May cause the detection mechanism to fail. So init seq with random value to accelerate conflict detection. Signed-off-by: Ye Bin --- fs/ext4/mmp.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index cebea4270817..12af6dc8457b 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -122,6 +122,21 @@ void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp, (int)sizeof(mmp->mmp_bdevname), mmp->mmp_bdevname); } +/* + * Get a random new sequence number but make sure it is not greater than + * EXT4_MMP_SEQ_MAX. + */ +static unsigned int mmp_new_seq(void) +{ + u32 new_seq; + + do { + new_seq = prandom_u32(); + } while (new_seq > EXT4_MMP_SEQ_MAX); + + return new_seq; +} + /* * kmmpd will update the MMP sequence every s_mmp_update_interval seconds */ @@ -132,7 +147,7 @@ static int kmmpd(void *data) struct buffer_head *bh = EXT4_SB(sb)->s_mmp_bh; struct mmp_struct *mmp; ext4_fsblk_t mmp_block; - u32 seq = 0; + u32 seq = mmp_new_seq(); unsigned long failed_writes = 0; int mmp_update_interval = le16_to_cpu(es->s_mmp_update_interval); unsigned mmp_check_interval; @@ -258,21 +273,6 @@ void ext4_stop_mmpd(struct ext4_sb_info *sbi) } } -/* - * Get a random new sequence number but make sure it is not greater than - * EXT4_MMP_SEQ_MAX. - */ -static unsigned int mmp_new_seq(void) -{ - u32 new_seq; - - do { - new_seq = prandom_u32(); - } while (new_seq > EXT4_MMP_SEQ_MAX); - - return new_seq; -} - /* * Protect the filesystem from being mounted more than once. */ From patchwork Sat Sep 11 09:00:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 1526697 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4H660Z0THwz9sf8 for ; Sat, 11 Sep 2021 18:51:10 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235474AbhIKIwR (ORCPT ); Sat, 11 Sep 2021 04:52:17 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:16189 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235407AbhIKIwP (ORCPT ); Sat, 11 Sep 2021 04:52:15 -0400 Received: from dggeme754-chm.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4H65zK69W3z1DFxg; Sat, 11 Sep 2021 16:50:05 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggeme754-chm.china.huawei.com (10.3.19.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Sat, 11 Sep 2021 16:51:00 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next v2 2/6] ext4: introduce last_check_time record previous check time Date: Sat, 11 Sep 2021 17:00:55 +0800 Message-ID: <20210911090059.1876456-3-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210911090059.1876456-1-yebin10@huawei.com> References: <20210911090059.1876456-1-yebin10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggeme754-chm.china.huawei.com (10.3.19.100) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org kmmpd: ... diff = jiffies - last_update_time; if (diff > mmp_check_interval * HZ) { ... As "mmp_check_interval = 2 * mmp_update_interval", 'diff' always little than 'mmp_update_interval', so there will never trigger detection. Introduce last_check_time record previous check time. Signed-off-by: Ye Bin --- fs/ext4/mmp.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index 12af6dc8457b..c781b09a78c9 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -152,6 +152,7 @@ static int kmmpd(void *data) int mmp_update_interval = le16_to_cpu(es->s_mmp_update_interval); unsigned mmp_check_interval; unsigned long last_update_time; + unsigned long last_check_time; unsigned long diff; int retval = 0; @@ -170,6 +171,7 @@ static int kmmpd(void *data) memcpy(mmp->mmp_nodename, init_utsname()->nodename, sizeof(mmp->mmp_nodename)); + last_check_time = jiffies; while (!kthread_should_stop() && !sb_rdonly(sb)) { if (!ext4_has_feature_mmp(sb)) { @@ -198,17 +200,18 @@ static int kmmpd(void *data) } diff = jiffies - last_update_time; - if (diff < mmp_update_interval * HZ) + if (diff < mmp_update_interval * HZ) { schedule_timeout_interruptible(mmp_update_interval * HZ - diff); + diff = jiffies - last_update_time; + } /* * We need to make sure that more than mmp_check_interval - * seconds have not passed since writing. If that has happened - * we need to check if the MMP block is as we left it. + * seconds have not passed since check. If that has happened + * we need to check if the MMP block is as we write it. */ - diff = jiffies - last_update_time; - if (diff > mmp_check_interval * HZ) { + if (jiffies - last_check_time > mmp_check_interval * HZ) { struct buffer_head *bh_check = NULL; struct mmp_struct *mmp_check; @@ -234,6 +237,7 @@ static int kmmpd(void *data) goto wait_to_exit; } put_bh(bh_check); + last_check_time = jiffies; } /* From patchwork Sat Sep 11 09:00:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 1526699 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4H660b0j5Nz9sf8 for ; Sat, 11 Sep 2021 18:51:11 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235488AbhIKIwS (ORCPT ); Sat, 11 Sep 2021 04:52:18 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:16190 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235408AbhIKIwP (ORCPT ); Sat, 11 Sep 2021 04:52:15 -0400 Received: from dggeme754-chm.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4H65zL1ykLz1DGjS; Sat, 11 Sep 2021 16:50:06 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggeme754-chm.china.huawei.com (10.3.19.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Sat, 11 Sep 2021 16:51:01 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next v2 3/6] ext4: compare to local seq and nodename when check conflict Date: Sat, 11 Sep 2021 17:00:56 +0800 Message-ID: <20210911090059.1876456-4-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210911090059.1876456-1-yebin10@huawei.com> References: <20210911090059.1876456-1-yebin10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggeme754-chm.china.huawei.com (10.3.19.100) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org As mmp and check_mmp is point to the same data, so there will never detect conflict. To solve this issue just compare to local data. Signed-off-by: Ye Bin --- fs/ext4/mmp.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index c781b09a78c9..4433fe7e9e86 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -154,6 +154,7 @@ static int kmmpd(void *data) unsigned long last_update_time; unsigned long last_check_time; unsigned long diff; + char nodename[64]; int retval = 0; mmp_block = le64_to_cpu(es->s_mmp_block); @@ -169,8 +170,8 @@ static int kmmpd(void *data) BUILD_BUG_ON(sizeof(mmp->mmp_bdevname) < BDEVNAME_SIZE); bdevname(bh->b_bdev, mmp->mmp_bdevname); - memcpy(mmp->mmp_nodename, init_utsname()->nodename, - sizeof(mmp->mmp_nodename)); + memcpy(nodename, init_utsname()->nodename, sizeof(nodename)); + memcpy(mmp->mmp_nodename, nodename, sizeof(mmp->mmp_nodename)); last_check_time = jiffies; while (!kthread_should_stop() && !sb_rdonly(sb)) { @@ -224,8 +225,8 @@ static int kmmpd(void *data) } mmp_check = (struct mmp_struct *)(bh_check->b_data); - if (mmp->mmp_seq != mmp_check->mmp_seq || - memcmp(mmp->mmp_nodename, mmp_check->mmp_nodename, + if (seq != mmp_check->mmp_seq || + memcmp(nodename, mmp_check->mmp_nodename, sizeof(mmp->mmp_nodename))) { dump_mmp_msg(sb, mmp_check, "Error while updating MMP info. " From patchwork Sat Sep 11 09:00:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 1526700 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4H660b6zqDz9sf8 for ; Sat, 11 Sep 2021 18:51:11 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235501AbhIKIwT (ORCPT ); Sat, 11 Sep 2021 04:52:19 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:16191 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235439AbhIKIwP (ORCPT ); Sat, 11 Sep 2021 04:52:15 -0400 Received: from dggeme754-chm.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4H65zL4vNNz1DGps; Sat, 11 Sep 2021 16:50:06 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggeme754-chm.china.huawei.com (10.3.19.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Sat, 11 Sep 2021 16:51:01 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next v2 4/6] ext4: avoid to re-read mmp check data get from page cache Date: Sat, 11 Sep 2021 17:00:57 +0800 Message-ID: <20210911090059.1876456-5-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210911090059.1876456-1-yebin10@huawei.com> References: <20210911090059.1876456-1-yebin10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggeme754-chm.china.huawei.com (10.3.19.100) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org As call read_mmp_block pass bh_check which value is NULL, then call sb_getblk to get buffer_head. But mmp_block's buffer_head is already exist which also is uptodate. Lead to compare the same data. Signed-off-by: Ye Bin --- fs/ext4/mmp.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index 4433fe7e9e86..007bde3c12b8 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -213,10 +213,7 @@ static int kmmpd(void *data) * we need to check if the MMP block is as we write it. */ if (jiffies - last_check_time > mmp_check_interval * HZ) { - struct buffer_head *bh_check = NULL; - struct mmp_struct *mmp_check; - - retval = read_mmp_block(sb, &bh_check, mmp_block); + retval = read_mmp_block(sb, &bh, mmp_block); if (retval) { ext4_error_err(sb, -retval, "error reading MMP data: %d", @@ -224,20 +221,18 @@ static int kmmpd(void *data) goto wait_to_exit; } - mmp_check = (struct mmp_struct *)(bh_check->b_data); - if (seq != mmp_check->mmp_seq || - memcmp(nodename, mmp_check->mmp_nodename, - sizeof(mmp->mmp_nodename))) { - dump_mmp_msg(sb, mmp_check, + mmp = (struct mmp_struct *)(bh->b_data); + if (seq != le32_to_cpu(mmp->mmp_seq) || + memcmp(nodename, mmp->mmp_nodename, + sizeof(nodename))) { + dump_mmp_msg(sb, mmp, "Error while updating MMP info. " "The filesystem seems to have been" " multiply mounted."); ext4_error_err(sb, EBUSY, "abort"); - put_bh(bh_check); retval = -EBUSY; goto wait_to_exit; } - put_bh(bh_check); last_check_time = jiffies; } From patchwork Sat Sep 11 09:00:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 1526698 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4H660Z35nYz9sjJ for ; Sat, 11 Sep 2021 18:51:10 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235481AbhIKIwS (ORCPT ); Sat, 11 Sep 2021 04:52:18 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:9420 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235459AbhIKIwQ (ORCPT ); Sat, 11 Sep 2021 04:52:16 -0400 Received: from dggeme754-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H65vM1sYnz8yRd; Sat, 11 Sep 2021 16:46:39 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggeme754-chm.china.huawei.com (10.3.19.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Sat, 11 Sep 2021 16:51:01 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next v2 5/6] ext4: avoid to double free s_mmp_bh Date: Sat, 11 Sep 2021 17:00:58 +0800 Message-ID: <20210911090059.1876456-6-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210911090059.1876456-1-yebin10@huawei.com> References: <20210911090059.1876456-1-yebin10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggeme754-chm.china.huawei.com (10.3.19.100) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org If call read_mmp_block failed then s_mmp_bh will be freed in read_mmp_block. Kmmpd wait to be killed, ext4_stop_mmpd stop kmmpd and also release s_mmp_bh. To avoid double free, just set EXT4_SB(sb)->s_mmp_bh with NULL. Signed-off-by: Ye Bin --- fs/ext4/mmp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index 007bde3c12b8..a0d47a906faa 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -218,6 +218,7 @@ static int kmmpd(void *data) ext4_error_err(sb, -retval, "error reading MMP data: %d", retval); + EXT4_SB(sb)->s_mmp_bh = NULL; goto wait_to_exit; } From patchwork Sat Sep 11 09:00:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 1526701 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4H660d3lrTz9ssD for ; Sat, 11 Sep 2021 18:51:13 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235520AbhIKIwW (ORCPT ); Sat, 11 Sep 2021 04:52:22 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:19028 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235470AbhIKIwQ (ORCPT ); Sat, 11 Sep 2021 04:52:16 -0400 Received: from dggeme754-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H65vl5ZrQzbmFv; Sat, 11 Sep 2021 16:46:59 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggeme754-chm.china.huawei.com (10.3.19.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Sat, 11 Sep 2021 16:51:02 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next v2 6/6] ext4: fix possible store wrong check interval value in disk when umount Date: Sat, 11 Sep 2021 17:00:59 +0800 Message-ID: <20210911090059.1876456-7-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210911090059.1876456-1-yebin10@huawei.com> References: <20210911090059.1876456-1-yebin10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggeme754-chm.china.huawei.com (10.3.19.100) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Test follow steps: 1. mkfs.ext4 /dev/sda -O mmp 2. mount /dev/sda /mnt 3. wait for about 1 minute 4. umount mnt 5. debugfs /dev/sda 6. dump_mmp 7. fsck.ext4 /dev/sda I found 'check_interval' is range in [5, 10]. And sometime run fsck print "MMP interval is 10 seconds and total wait time is 42 seconds. Please wait...". kmmpd: ... if (diff < mmp_update_interval * HZ) schedule_timeout_interruptible(mmp_update_interval * HZ - diff); diff = jiffies - last_update_time; ... mmp_check_interval = max(min(EXT4_MMP_CHECK_MULT * diff / HZ, EXT4_MMP_MAX_CHECK_INTERVAL), EXT4_MMP_MIN_CHECK_INTERVAL); mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval); ... We will call ext4_stop_mmpd to stop kmmpd kthread when umount, and schedule_timeout_interruptible will be interrupted, so 'diff' maybe little than mmp_update_interval. Then mmp_check_interval will range in [EXT4_MMP_MAX_CHECK_INTERVAL, EXT4_MMP_CHECK_MULT * diff / HZ]. To solve this issue, if 'diff' little then mmp_update_interval * HZ just break loop, don't update check interval. Signed-off-by: Ye Bin --- fs/ext4/mmp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index a0d47a906faa..f39e1fa0c6db 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -205,6 +205,14 @@ static int kmmpd(void *data) schedule_timeout_interruptible(mmp_update_interval * HZ - diff); diff = jiffies - last_update_time; + /* If 'diff' little 'than mmp_update_interval * HZ', it + * means someone call ext4_stop_mmpd to stop kmmpd + * kthread. We don't need to update mmp_check_interval + * any more, as 'diff' is not exact value. + */ + if (unlikely(diff < mmp_update_interval * HZ && + kthread_should_stop())) + break; } /*