Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp631844pxk; Wed, 16 Sep 2020 12:47:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1bvj2D133oe8ZOko0A01qabN7Fmwbyn8vrDUvWbU1EKbDMTQInzXmB8VpZ/ZlEuOwncLL X-Received: by 2002:a17:906:d8cd:: with SMTP id re13mr26509377ejb.140.1600285654053; Wed, 16 Sep 2020 12:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600285654; cv=none; d=google.com; s=arc-20160816; b=0nRiUtOKhofomMFzQMYsAfZgCUzbEK4ikxSkuUhlkoMVlBK/zFg7k8wlILIHSjsW6K NYEcOhWoWos5m7kLOns7QSznZZhG513QdaoaA6lkgTOyONZdR7Vgfvi2Vub7dIoZe3Zy JhHclb0V7GWcFO4rPYgerv/scBB+GBEpPTADe+giZXsmjx7q23G0H5GZV+antc8ZnHm6 NEoj86zpcHJLNhg8YL48Y2WMyWy3C7C5xhIfc9c6IXz1hKol/w2jSFq7wENnVhWatBHV TlJuiM9r9fKdbl8b7fwEfXBCqJNdQld9IhnOGj3UNI/0nJP8OwfAvX6g3CFzoZLQS9Gj KUag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vRyRMGr2lWn/u4zygt3CF6hAXOvE9SynZnIyZgtz8n0=; b=BT3ykXuj/iqYClTuyaSeVcZHwkhtWSQ7BHcJRTp0adBi1Ax8MdkD2hTpOP52zhe0Ms k+HSJVFEIGxn/AFmgpW/2Xo4zIJgOdOWTPMTsGlLaIWz1zI96Gydsm9NjsabZRqmp2fB JUjrZHYSw5KKlKfu6Vn+V0uffmgfWNbx/uKMUDGTRyZwPZoXuXRztyXPi1szO3QmrpiB 4b4vZPZ5faZNy+gSjO5Vsa0V8bd6Vr+bzdDnEx1XtxEalO8Ddrx1F2Yv9Yh+zKBw+3Xi cmsb1fGrXmWHmk+2xG1J0QtWSjlNoe1XcJT3yrLzgoHGzCXaBAhEKZXnuzdHNCiC09Lg ElmQ== ARC-Authentication-Results: i=1; mx.google.com; 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 d14si12025350edp.136.2020.09.16.12.47.03; Wed, 16 Sep 2020 12:47:34 -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; 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 S1727610AbgIPTog (ORCPT + 99 others); Wed, 16 Sep 2020 15:44:36 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:12795 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727653AbgIPToc (ORCPT ); Wed, 16 Sep 2020 15:44:32 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 120A5A12D752EA1615A3; Wed, 16 Sep 2020 19:37:52 +0800 (CST) Received: from huawei.com (10.175.127.227) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Wed, 16 Sep 2020 19:37:46 +0800 From: Ye Bin To: , , , , , CC: Ye Bin Subject: [PATCH v5 1/2] ext4: Discard preallocations before releasing group lock Date: Wed, 16 Sep 2020 19:38:58 +0800 Message-ID: <20200916113859.1556397-2-yebin10@huawei.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200916113859.1556397-1-yebin10@huawei.com> References: <20200916113859.1556397-1-yebin10@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-CFilter-Loop: Reflected Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Jan Kara ext4_mb_discard_group_preallocations() can be releasing group lock with preallocations accumulated on its local list. Thus although discard_pa_seq was incremented and concurrent allocating processes will be retrying allocations, it can happen that premature ENOSPC error is returned because blocks used for preallocations are not available for reuse yet. Make sure we always free locally accumulated preallocations before releasing group lock. Fixes: 07b5b8e1ac40 ("ext4: mballoc: introduce pcpu seqcnt for freeing PA to improve ENOSPC handling") Signed-off-by: Jan Kara Signed-off-by: Ye Bin Reviewed-by: Ritesh Harjani --- fs/ext4/mballoc.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 132c118d12e1..f736819a381b 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4215,22 +4215,6 @@ ext4_mb_discard_group_preallocations(struct super_block *sb, list_add(&pa->u.pa_tmp_list, &list); } - /* if we still need more blocks and some PAs were used, try again */ - if (free < needed && busy) { - busy = 0; - ext4_unlock_group(sb, group); - cond_resched(); - goto repeat; - } - - /* found anything to free? */ - if (list_empty(&list)) { - BUG_ON(free != 0); - mb_debug(sb, "Someone else may have freed PA for this group %u\n", - group); - goto out; - } - /* now free all selected PAs */ list_for_each_entry_safe(pa, tmp, &list, u.pa_tmp_list) { @@ -4248,7 +4232,17 @@ ext4_mb_discard_group_preallocations(struct super_block *sb, call_rcu(&(pa)->u.pa_rcu, ext4_mb_pa_callback); } -out: + /* if we still need more blocks and some PAs were used, try again */ + if (free < needed && busy) { + ext4_unlock_group(sb, group); + cond_resched(); + busy = 0; + /* Make sure we increment discard_pa_seq again */ + needed -= free; + free = 0; + goto repeat; + } + ext4_unlock_group(sb, group); ext4_mb_unload_buddy(&e4b); put_bh(bitmap_bh); -- 2.25.4