From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39D62C2BA19 for ; Sat, 11 Apr 2020 23:41:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 11C4A206A1 for ; Sat, 11 Apr 2020 23:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586648515; bh=bvnh3ch4uxfy6wxazv3eDsoddKH4FDlJrlXId622Luc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=UvYc+WxOSqLJ4oEEQcjXKPAGuJxSNhJpbdepAd0uzspcYrtcE1hfc8rMipksmfcot eiWWL4LexMCUZIj78IaGFCVs29ijcP6a9EFlXxDjx1HnVNSfNlhBxSoAZeAdexJWBv wcTvoU+gUyRm8PC6U+G6RcOz1Htjg//ErdGr+Av8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728682AbgDKXlt (ORCPT ); Sat, 11 Apr 2020 19:41:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:42416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728521AbgDKXGu (ORCPT ); Sat, 11 Apr 2020 19:06:50 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3BBDE20708; Sat, 11 Apr 2020 23:06:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586646409; bh=bvnh3ch4uxfy6wxazv3eDsoddKH4FDlJrlXId622Luc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZzRanDLDOQXS17A1rkqLQJBQDK3NBsCgm4Vip03UlLacDj7OuyAUtGDV3RCHuL1H +sXlpWFJyXo4H8Qe4FIMwAIjTf7TO6/XEkOwc/RPFQRSNvBCFSXyARQ1R1+EPMKMUZ mE12DhA0H1RaS+Of3YyWaqj9+iZ1c16MNE9aq9DA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jan Kara , Theodore Ts'o , Sasha Levin , linux-ext4@vger.kernel.org Subject: [PATCH AUTOSEL 5.6 145/149] ext4: avoid ENOSPC when avoiding to reuse recently deleted inodes Date: Sat, 11 Apr 2020 19:03:42 -0400 Message-Id: <20200411230347.22371-145-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200411230347.22371-1-sashal@kernel.org> References: <20200411230347.22371-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Jan Kara [ Upstream commit d05466b27b19af8e148376590ed54d289b607f0a ] When ext4 is running on a filesystem without a journal, it tries not to reuse recently deleted inodes to provide better chances for filesystem recovery in case of crash. However this logic forbids reuse of freed inodes for up to 5 minutes and especially for filesystems with smaller number of inodes can lead to ENOSPC errors returned when allocating new inodes. Fix the problem by allowing to reuse recently deleted inode if there's no other inode free in the scanned range. Signed-off-by: Jan Kara Link: https://lore.kernel.org/r/20200318121317.31941-1-jack@suse.cz Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/ialloc.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index f95ee99091e4c..9652a0eadd1ce 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -712,21 +712,34 @@ static int recently_deleted(struct super_block *sb, ext4_group_t group, int ino) static int find_inode_bit(struct super_block *sb, ext4_group_t group, struct buffer_head *bitmap, unsigned long *ino) { + bool check_recently_deleted = EXT4_SB(sb)->s_journal == NULL; + unsigned long recently_deleted_ino = EXT4_INODES_PER_GROUP(sb); + next: *ino = ext4_find_next_zero_bit((unsigned long *) bitmap->b_data, EXT4_INODES_PER_GROUP(sb), *ino); if (*ino >= EXT4_INODES_PER_GROUP(sb)) - return 0; + goto not_found; - if ((EXT4_SB(sb)->s_journal == NULL) && - recently_deleted(sb, group, *ino)) { + if (check_recently_deleted && recently_deleted(sb, group, *ino)) { + recently_deleted_ino = *ino; *ino = *ino + 1; if (*ino < EXT4_INODES_PER_GROUP(sb)) goto next; - return 0; + goto not_found; } - + return 1; +not_found: + if (recently_deleted_ino >= EXT4_INODES_PER_GROUP(sb)) + return 0; + /* + * Not reusing recently deleted inodes is mostly a preference. We don't + * want to report ENOSPC or skew allocation patterns because of that. + * So return even recently deleted inode if we could find better in the + * given range. + */ + *ino = recently_deleted_ino; return 1; } -- 2.20.1