Linux-ext4 Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] ext4: Avoid ENOSPC when avoiding to reuse recently deleted inodes
@ 2020-03-18 12:13 Jan Kara
  2020-03-26 14:55 ` [PATCH] ext4: avoid " Theodore Y. Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kara @ 2020-03-18 12:13 UTC (permalink / raw)
  To: Ted Tso; +Cc: linux-ext4, Jan Kara

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 <jack@suse.cz>
---
 fs/ext4/ialloc.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

This patch is ramping down the enforcement of recently_deleted() logic rather
significantly. I believe it is fine since IMO it is better to reuse deleted
inode than to disrupt allocation patterns but there's also another option to
disable the recently_deleted() logic only if there's no free inode found in the
whole fs. I can switch to that if people think that it is OK for
recently_deleted() logic to push inode allocations to different group or so.

diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index f95ee99091e4..74f0fe145370 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.16.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ext4: avoid ENOSPC when avoiding to reuse recently deleted inodes
  2020-03-18 12:13 [PATCH] ext4: Avoid ENOSPC when avoiding to reuse recently deleted inodes Jan Kara
@ 2020-03-26 14:55 ` " Theodore Y. Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Y. Ts'o @ 2020-03-26 14:55 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4

On Wed, Mar 18, 2020 at 01:13:17PM +0100, Jan Kara wrote:
> 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 <jack@suse.cz>

Thanks, applied with a minor whitespace fixup.

		       	     		- Ted

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-18 12:13 [PATCH] ext4: Avoid ENOSPC when avoiding to reuse recently deleted inodes Jan Kara
2020-03-26 14:55 ` [PATCH] ext4: avoid " Theodore Y. Ts'o

Linux-ext4 Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-ext4/0 linux-ext4/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-ext4 linux-ext4/ https://lore.kernel.org/linux-ext4 \
		linux-ext4@vger.kernel.org
	public-inbox-index linux-ext4

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-ext4


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git