Skip to contentSkip to conversation

ext4: add free-space extent based allocator

RFC PATCH New Harshad Shirwadkar 2 participants 13 messages Aug 21, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover ext4: add free-space extent based allocator

ext4: add free-space extent based allocator

This patchset introduces a new multiblock allocator for the Ext4 file system based on an enhanced version of the free space management mechanism originally proposed by Kadekodi S. and Jain S., in their paper, "Taking Linux Filesystems to the Space Age: Space Maps in Ext4" [1].

High Level Design
=================

This allocator maintains the free space information about the file system in per-flexible block group level trees. These trees are constructed from block bitmaps stored on disk. Therefore, this feature does not require any on-disk format change. For every flexible block group, we maintain individual freespace nodes in two trees, one sorted by flex-bg offset and other sorted by length. This gives us two
benefits: i) In the allocation path, our search time complexity is O(Log(Number of freespace regions in the flex-bg)). ii) In free path, in the same time complexity we can merge the adjacent nodes thereby reducing the size of the tree efficiently.

Along with flexible block group level trees, we also introduce a top level meta-tree which consists of individual flex-bg trees. This tree is sorted by length of largest extents found in flex-bgs. The key advantage that this tree gives us is this: During an allocation request, the allocator is now able to consult this tree and directly (in O(Log(Number of Flex BGs)) jump to a flexible block group which _definitely_ has at least one (the largest) extent that can satisfy this request. If no flexible block group exists which can satisfy this request, the allocator can now immediately drop the CR level.

In order to preseve the parallel allocation / free performance, the allocator only *tries* to consult this tree. It does so by calling read_trylock() function and if the meta-tree is busy, the allocator continues its linear search until it is able to grab a read-lock on this tree.

Memory Footprint
================

In a less fragmented file system, the memory footprint of the new allocator is significantly lower than buddy bitmaps. Memory footprint of the freespace tree allocator can be checked by running "cat /sys/fs/ext4/<dev>/frsp_tree_usage". For an almost newly created 100G disk, the total usage is only ~10 KB. However, as the fragmentation level increases, the memory footprint of this allocator may increase. The memory usage of the freespace tree allocator can be controlled using sysfs tunable "mb_frsp_max_mem". Once the memory threshold is reached, the allocator starts evicting the freespace trees in the LRU fashion from memory. However, we don't remove tree's entry from the meta-tree. This allows the allocator to efficiently reconstruct only relevant trees from on-disk bitmaps under high memory pressure. As we show in the evaluation section, freespace tree allocator still manages to outperform buddy allocator in memory crunch situation. The default value of mb_frsp_max_mem is max(memory needed for buddy, maximum memory needed for one tree in the worst case). Accounting for max memory needed for one tree allows us to keep at least one tree in memory even in the worst case. This avoids thrashing.

Caching Tree Metadata
=====================

As noted in our experiments, we find caching tree metadata (the largest available extent in a tree) in the meta-tree significantly boosts allocation performance. However, if the allocator waits for the cache to fill up before starting to serve allocation requests, that may severely degrade allocation performance on large disks. Thus, it is important to tune the tree caching behavior according to the underlying block device. This patchset provides four cache aggression levels. Cache aggression level can be specified as a mount time parameter "frsp_cache_aggression". Here is the meaning of these different levels:

|-------+------------------------------------------------------------------|
| Level | Meaning                                                          |
|-------+------------------------------------------------------------------|
|     0 | Try to avoid caching as much as possible. In this mode           |
|       | the allocator tries hard to serve the request from the already   |
|       | cached trees.                                                    |
|-------+------------------------------------------------------------------|
|     1 | Avoid caching at CR=0. Otherwise, cache trees on every other     |
|       | allocation request. (default)                                    |
|-------+------------------------------------------------------------------|
|     2 | Cache trees on every other allocation request.                   |
|-------+------------------------------------------------------------------|
|     3 | Aggressive caching. In this mode the allocator aggressively      |
|       | caches uncached trees, even if the request can be fulfilled      |
|       | by one of the available trees. Using this mode, the allocator    |
|       | ends up caching trees quickly and thereby is able to make better |
|       | allocation decisions sooner.                                     |
|-------+------------------------------------------------------------------|

Evaluation
==========

This feature did not introduce any regressions in Ext4 XFStests in quick group. We created a _highly_ fragmented 60T disk with over 490K block groups and over 30K flexible block groups. We tested the write performance of the first small write (10MB) and a larger second write (100MB) using both the buddy allocator and freespace tree allocator. We turned memory limit off for the first four free space tree configurations.

First Write Performance
-----------------------

|--------------------------------------+---------+---------+-----------+--------|
| Allocator                            | RAM     | # trees | Perf      | Time   |
|                                      | usage   |  cached |           |        |
|--------------------------------------+---------+---------+-----------+--------|
| Buddy Allocator (v5.7)               | -       |       - | 6.8 KB/s  | 25m51s |
|--------------------------------------+---------+---------+-----------+--------|
| With --prefetch_block_bitmap         | -       |       - | 28.1 KB/s | 6m14s  |
|--------------------------------------+---------+---------+-----------+--------|
| Free space tree allocator at level 0 | 43.5 MB |     201 | 2.6 MB/s  | 0m8s   |
|--------------------------------------+---------+---------+-----------+--------|
| Free space tree allocator at level 1 | 193 MB  |     874 | 1.5 MB/s  | 0m47s  |
|--------------------------------------+---------+---------+-----------+--------|
| Free space tree allocator at level 2 | 3.6 GB  |   16476 | 21.4 KB/s | 8m14s  |
|--------------------------------------+---------+---------+-----------+--------|
| Free space tree allocator at level 3 | 6.8 GB  |   30720 | 9.1 KB/s  | 19m22s |
|--------------------------------------+---------+---------+-----------+--------|
| Free space tree allocator at level 3 | 1023 MB |   30720 | 9.3 KB/s  | 18m53s |
| ( With 1G Limit)                     |         |         |           |        |
|--------------------------------------+---------+---------+-----------+--------|

Second Write Performance
------------------------

|--------------------------------------+---------+---------+-----------+-------|
| Allocator                            | RAM     | # trees | Perf      | Time  |
|                                      | usage   |  cached |           |       |
|--------------------------------------+---------+---------+-----------+-------|
| Buddy Allocator (v5.7)               | -       |       - | 499 KB/s  | 3m30s |
|--------------------------------------+---------+---------+-----------+-------|
| With --prefetch_block_bitmap         | -       |       - | 185 KB/s  | 9m26s |
|--------------------------------------+---------+---------+-----------+-------|
| Free space tree allocator at level 0 | 48.7 MB |     226 | 48.2 MB/s | 6s    |
|--------------------------------------+---------+---------+-----------+-------|
| Free space tree allocator at level 1 | 221 MB  |    1007 | 26.8 MB/s | 8s    |
|--------------------------------------+---------+---------+-----------+-------|
| Free space tree allocator at level 2 | 6.8 GB  |   30720 | 178 KB/s  | 9m54s |
|--------------------------------------+---------+---------+-----------+-------|
| Free space tree allocator at level 3 | 6.8 GB  |   30720 | 79 MB/s   | 5s    |
|--------------------------------------+---------+---------+-----------+-------|
| Free space tree allocator at level 3 | 1023 MB |   30720 | 77.1 MB/s | 7s    |
| ( With 1G Limit)                     |         |         |           |       |
|--------------------------------------+---------+---------+-----------+-------|

Verified that parallel write performance on a newly created disk is not very different for buddy allocator and freespace tree allocator. This patchset is applied on top of block bitmap prefetch patches.

[1] https://www.kernel.org/doc/ols/2010/ols2010-pages-121-132.pdf

Changes Since V1:

- Rebased the patchset on top of ext4 dev branch
- Converted the patches to RFC

Harshad Shirwadkar (8):
ext4: add handling for extended mount options
ext4: rename ext4_mb_load_buddy to ext4_mb_load_allocator
ext4: add prefetching support for freespace trees
ext4: add freespace tree optimizations
ext4: add memory usage tracker for freespace trees
ext4: add LRU eviction for free space trees
ext4: add tracepoints for free space trees
ext4: add freespace trees documentation in code

Yuexin Li (1):
ext4: add freespace tree allocator

 fs/ext4/ext4.h              |  117 +++
 fs/ext4/mballoc.c           | 1541 +++++++++++++++++++++++++++++++++--
 fs/ext4/mballoc.h           |   67 +-
 fs/ext4/resize.c            |    8 +
 fs/ext4/super.c             |   60 +-
 fs/ext4/sysfs.c             |   11 +
 include/trace/events/ext4.h |  112 +++
 7 files changed, 1821 insertions(+), 95 deletions(-)
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
#1 lore raw

RFC PATCH v2 1/9 ext4: add handling for extended mount options

From: Harshad Shirwadkar <[email protected]>

We are running out of mount option bits. Add handling for using s_mount_opt2. This patch was originally submitted as a part of fast commit patch series. Resending it here with this patch series too.

---
 fs/ext4/super.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
fs/ext4/super.c +12 -4
index 13bdddc081e0..656eccf6fc9b 100644
@@ -1738,6 +1738,7 @@ static int clear_qf_name(struct super_block *sb, int qtype)
 #define MOPT_EXT4_ONLY	(MOPT_NO_EXT2 | MOPT_NO_EXT3)
 #define MOPT_STRING	0x0400
 #define MOPT_SKIP	0x0800
+#define MOPT_2		0x1000
 
 static const struct mount_opts {
 	int	token;
@@ -2207,10 +2208,17 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
 			WARN_ON(1);
 			return -1;
 		}
-		if (arg != 0)
-			sbi->s_mount_opt |= m->mount_opt;
-		else
-			sbi->s_mount_opt &= ~m->mount_opt;
+		if (m->flags & MOPT_2) {
+			if (arg != 0)
+				sbi->s_mount_opt2 |= m->mount_opt;
+			else
+				sbi->s_mount_opt2 &= ~m->mount_opt;
+		} else {
+			if (arg != 0)
+				sbi->s_mount_opt |= m->mount_opt;
+			else
+				sbi->s_mount_opt &= ~m->mount_opt;
+		}
 	}
 	return 1;
 }
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
#6 lore raw

RFC PATCH v2 4/9 ext4: add prefetching support for freespace trees

In reply to Harshad Shirwadkar

From: Harshad Shirwadkar <[email protected]>

This patch supports creation of freespace trees for prefetched block bitmaps.

---
 fs/ext4/mballoc.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
fs/ext4/mballoc.c +11 -1
index 4b1c405543f0..168e9708257f 100644
@@ -3137,6 +3137,9 @@ ext4_group_t ext4_mb_prefetch(struct super_block *sb, ext4_group_t group,
 void ext4_mb_prefetch_fini(struct super_block *sb, ext4_group_t group,
 			   unsigned int nr)
 {
+	struct ext4_buddy e4b;
+	int ret;
+
 	while (nr-- > 0) {
 		struct ext4_group_desc *gdp = ext4_get_group_desc(sb, group,
 								  NULL);
@@ -3151,8 +3154,15 @@ void ext4_mb_prefetch_fini(struct super_block *sb, ext4_group_t group,
 		    ext4_free_group_clusters(sb, gdp) > 0 &&
 		    !(ext4_has_group_desc_csum(sb) &&
 		      (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)))) {
-			if (ext4_mb_init_group(sb, group, GFP_NOFS))
+			if (ext4_mb_frsp_on(sb)) {
+				ret = ext4_mb_load_allocator(sb, group, &e4b,
+							     0);
+				if (ret)
+					break;
+				ext4_mb_unload_allocator(&e4b);
+			} else if (ext4_mb_init_group(sb, group, GFP_NOFS)) {
 				break;
+			}
 		}
 	}
 }
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
#2 lore raw

RFC PATCH v2 2/9 ext4: rename ext4_mb_load_buddy to ext4_mb_load_allocator

In reply to Harshad Shirwadkar

From: Harshad Shirwadkar <[email protected]>

This patch renames ext4_mb_load_buddy and ext4_mb_unload_buddy to ext4_mb_load_allocator and ext4_mb_unload_allocator. Also, we add a flag argument to ext4_mb_load_allocator function which is currently unused. This patch helps reduce the size of the following patch "ext4:
add freespace tree allocator" significantly. In the interest of keeping this patchset shorter, I have not renamed ext4_buddy structure and e4b variable names. But have added that as a TODO item.

---
 fs/ext4/mballoc.c | 86 ++++++++++++++++++++++++-----------------------
 1 file changed, 44 insertions(+), 42 deletions(-)
fs/ext4/mballoc.c +44 -42
index 132c118d12e1..48d791304bf1 100644
@@ -29,6 +29,7 @@
  *   - don't normalize tails
  *   - quota
  *   - reservation for superuser
+ *   - rename ext4_buddy to ext4_allocator and e4b variables to allocator
  *
  * TODO v3:
  *   - bitmap read-ahead (proposed by Oleg Drokin aka green)
@@ -92,7 +93,7 @@
  * mapped to the buddy and bitmap information regarding different
  * groups. The buddy information is attached to buddy cache inode so that
  * we can access them through the page cache. The information regarding
- * each group is loaded via ext4_mb_load_buddy.  The information involve
+ * each group is loaded via ext4_mb_load_allocator.  The information involve
  * block bitmap and buddy information. The information are stored in the
  * inode as:
  *
@@ -845,7 +846,7 @@ static void mb_regenerate_buddy(struct ext4_buddy *e4b)
 
 /* The buddy information is attached the buddy cache inode
  * for convenience. The information regarding each group
- * is loaded via ext4_mb_load_buddy. The information involve
+ * is loaded via ext4_mb_load_allocator. The information involve
  * block bitmap and buddy information. The information are
  * stored in the inode as
  *
@@ -1105,7 +1106,7 @@ int ext4_mb_init_group(struct super_block *sb, ext4_group_t group, gfp_t gfp)
 	 * This ensures that we don't reinit the buddy cache
 	 * page which map to the group from which we are already
 	 * allocating. If we are looking at the buddy cache we would
-	 * have taken a reference using ext4_mb_load_buddy and that
+	 * have taken a reference using ext4_mb_load_allocator and that
 	 * would have pinned buddy page to page cache.
 	 * The call to ext4_mb_get_buddy_page_lock will mark the
 	 * page accessed.
@@ -1157,8 +1158,8 @@ int ext4_mb_init_group(struct super_block *sb, ext4_group_t group, gfp_t gfp)
  * calling this routine!
  */
 static noinline_for_stack int
-ext4_mb_load_buddy_gfp(struct super_block *sb, ext4_group_t group,
-		       struct ext4_buddy *e4b, gfp_t gfp)
+ext4_mb_load_allocator_gfp(struct super_block *sb, ext4_group_t group,
+				struct ext4_buddy *e4b, gfp_t gfp, int flags)
 {
 	int blocks_per_page;
 	int block;
@@ -1293,13 +1294,13 @@ ext4_mb_load_buddy_gfp(struct super_block *sb, ext4_group_t group,
 	return ret;
 }
 
-static int ext4_mb_load_buddy(struct super_block *sb, ext4_group_t group,
-			      struct ext4_buddy *e4b)
+static int ext4_mb_load_allocator(struct super_block *sb, ext4_group_t group,
+			      struct ext4_buddy *e4b, int flags)
 {
-	return ext4_mb_load_buddy_gfp(sb, group, e4b, GFP_NOFS);
+	return ext4_mb_load_allocator_gfp(sb, group, e4b, GFP_NOFS, flags);
 }
 
-static void ext4_mb_unload_buddy(struct ext4_buddy *e4b)
+static void ext4_mb_unload_allocator(struct ext4_buddy *e4b)
 {
 	if (e4b->bd_bitmap_page)
 		put_page(e4b->bd_bitmap_page);
@@ -1859,7 +1860,7 @@ int ext4_mb_try_best_found(struct ext4_allocation_context *ac,
 	int err;
 
 	BUG_ON(ex.fe_len <= 0);
-	err = ext4_mb_load_buddy(ac->ac_sb, group, e4b);
+	err = ext4_mb_load_allocator(ac->ac_sb, group, e4b, 0);
 	if (err)
 		return err;
 
@@ -1872,7 +1873,7 @@ int ext4_mb_try_best_found(struct ext4_allocation_context *ac,
 	}
 
 	ext4_unlock_group(ac->ac_sb, group);
-	ext4_mb_unload_buddy(e4b);
+	ext4_mb_unload_allocator(e4b);
 
 	return 0;
 }
@@ -1893,12 +1894,12 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac,
 	if (grp->bb_free == 0)
 		return 0;
 
-	err = ext4_mb_load_buddy(ac->ac_sb, group, e4b);
+	err = ext4_mb_load_allocator(ac->ac_sb, group, e4b, 0);
 	if (err)
 		return err;
 
 	if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info))) {
-		ext4_mb_unload_buddy(e4b);
+		ext4_mb_unload_allocator(e4b);
 		return 0;
 	}
 
@@ -1936,7 +1937,7 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac,
 		ext4_mb_use_best_found(ac, e4b);
 	}
 	ext4_unlock_group(ac->ac_sb, group);
-	ext4_mb_unload_buddy(e4b);
+	ext4_mb_unload_allocator(e4b);
 
 	return 0;
 }
@@ -2417,7 +2418,7 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
 				continue;
 			}
 
-			err = ext4_mb_load_buddy(sb, group, &e4b);
+			err = ext4_mb_load_allocator(sb, group, &e4b, 0);
 			if (err)
 				goto out;
 
@@ -2430,7 +2431,7 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
 			ret = ext4_mb_good_group(ac, group, cr);
 			if (ret == 0) {
 				ext4_unlock_group(sb, group);
-				ext4_mb_unload_buddy(&e4b);
+				ext4_mb_unload_allocator(&e4b);
 				continue;
 			}
 
@@ -2444,7 +2445,7 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
 				ext4_mb_complex_scan_group(ac, &e4b);
 
 			ext4_unlock_group(sb, group);
-			ext4_mb_unload_buddy(&e4b);
+			ext4_mb_unload_allocator(&e4b);
 
 			if (ac->ac_status != AC_STATUS_CONTINUE)
 				break;
@@ -2543,7 +2544,7 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
 	grinfo = ext4_get_group_info(sb, group);
 	/* Load the group info in memory only if not already loaded. */
 	if (unlikely(EXT4_MB_GRP_NEED_INIT(grinfo))) {
-		err = ext4_mb_load_buddy(sb, group, &e4b);
+		err = ext4_mb_load_allocator(sb, group, &e4b, 0);
 		if (err) {
 			seq_printf(seq, "#%-5u: I/O error\n", group);
 			return 0;
@@ -2554,7 +2555,7 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
 	memcpy(&sg, ext4_get_group_info(sb, group), i);
 
 	if (buddy_loaded)
-		ext4_mb_unload_buddy(&e4b);
+		ext4_mb_unload_allocator(&e4b);
 
 	seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg.info.bb_free,
 			sg.info.bb_fragments, sg.info.bb_first_free);
@@ -3049,7 +3050,7 @@ static void ext4_free_data_in_buddy(struct super_block *sb,
 	mb_debug(sb, "gonna free %u blocks in group %u (0x%p):",
 		 entry->efd_count, entry->efd_group, entry);
 
-	err = ext4_mb_load_buddy(sb, entry->efd_group, &e4b);
+	err = ext4_mb_load_allocator(sb, entry->efd_group, &e4b, 0);
 	/* we expect to find existing buddy because it's pinned */
 	BUG_ON(err != 0);
 
@@ -3084,7 +3085,7 @@ static void ext4_free_data_in_buddy(struct super_block *sb,
 	}
 	ext4_unlock_group(sb, entry->efd_group);
 	kmem_cache_free(ext4_free_data_cachep, entry);
-	ext4_mb_unload_buddy(&e4b);
+	ext4_mb_unload_allocator(&e4b);
 
 	mb_debug(sb, "freed %d blocks in %d structures\n", count,
 		 count2);
@@ -3558,12 +3559,13 @@ static void ext4_discard_allocated_blocks(struct ext4_allocation_context *ac)
 	if (pa == NULL) {
 		if (ac->ac_f_ex.fe_len == 0)
 			return;
-		err = ext4_mb_load_buddy(ac->ac_sb, ac->ac_f_ex.fe_group, &e4b);
+		err = ext4_mb_load_allocator(ac->ac_sb, ac->ac_f_ex.fe_group,
+						&e4b, 0);
 		if (err) {
 			/*
 			 * This should never happen since we pin the
 			 * pages in the ext4_allocation_context so
-			 * ext4_mb_load_buddy() should never fail.
+			 * ext4_mb_load_allocator() should never fail.
 			 */
 			WARN(1, "mb_load_buddy failed (%d)", err);
 			return;
@@ -3572,7 +3574,7 @@ static void ext4_discard_allocated_blocks(struct ext4_allocation_context *ac)
 		mb_free_blocks(ac->ac_inode, &e4b, ac->ac_f_ex.fe_start,
 			       ac->ac_f_ex.fe_len);
 		ext4_unlock_group(ac->ac_sb, ac->ac_f_ex.fe_group);
-		ext4_mb_unload_buddy(&e4b);
+		ext4_mb_unload_allocator(&e4b);
 		return;
 	}
 	if (pa->pa_type == MB_INODE_PA)
@@ -4175,7 +4177,7 @@ ext4_mb_discard_group_preallocations(struct super_block *sb,
 		goto out_dbg;
 	}
 
-	err = ext4_mb_load_buddy(sb, group, &e4b);
+	err = ext4_mb_load_allocator(sb, group, &e4b, 0);
 	if (err) {
 		ext4_warning(sb, "Error %d loading buddy information for %u",
 			     err, group);
@@ -4250,7 +4252,7 @@ ext4_mb_discard_group_preallocations(struct super_block *sb,
 
 out:
 	ext4_unlock_group(sb, group);
-	ext4_mb_unload_buddy(&e4b);
+	ext4_mb_unload_allocator(&e4b);
 	put_bh(bitmap_bh);
 out_dbg:
 	mb_debug(sb, "discarded (%d) blocks preallocated for group %u bb_free (%d)\n",
@@ -4347,8 +4349,8 @@ void ext4_discard_preallocations(struct inode *inode, unsigned int needed)
 		BUG_ON(pa->pa_type != MB_INODE_PA);
 		group = ext4_get_group_number(sb, pa->pa_pstart);
 
-		err = ext4_mb_load_buddy_gfp(sb, group, &e4b,
-					     GFP_NOFS|__GFP_NOFAIL);
+		err = ext4_mb_load_allocator_gfp(sb, group, &e4b,
+						GFP_NOFS|__GFP_NOFAIL, 0);
 		if (err) {
 			ext4_error_err(sb, -err, "Error %d loading buddy information for %u",
 				       err, group);
@@ -4360,7 +4362,7 @@ void ext4_discard_preallocations(struct inode *inode, unsigned int needed)
 			err = PTR_ERR(bitmap_bh);
 			ext4_error_err(sb, -err, "Error %d reading block bitmap for %u",
 				       err, group);
-			ext4_mb_unload_buddy(&e4b);
+			ext4_mb_unload_allocator(&e4b);
 			continue;
 		}
 
@@ -4369,7 +4371,7 @@ void ext4_discard_preallocations(struct inode *inode, unsigned int needed)
 		ext4_mb_release_inode_pa(&e4b, bitmap_bh, pa);
 		ext4_unlock_group(sb, group);
 
-		ext4_mb_unload_buddy(&e4b);
+		ext4_mb_unload_allocator(&e4b);
 		put_bh(bitmap_bh);
 
 		list_del(&pa->u.pa_tmp_list);
@@ -4642,8 +4644,8 @@ ext4_mb_discard_lg_preallocations(struct super_block *sb,
 		int err;
 
 		group = ext4_get_group_number(sb, pa->pa_pstart);
-		err = ext4_mb_load_buddy_gfp(sb, group, &e4b,
-					     GFP_NOFS|__GFP_NOFAIL);
+		err = ext4_mb_load_allocator_gfp(sb, group, &e4b,
+						GFP_NOFS|__GFP_NOFAIL, 0);
 		if (err) {
 			ext4_error_err(sb, -err, "Error %d loading buddy information for %u",
 				       err, group);
@@ -4654,7 +4656,7 @@ ext4_mb_discard_lg_preallocations(struct super_block *sb,
 		ext4_mb_release_group_pa(&e4b, pa);
 		ext4_unlock_group(sb, group);
 
-		ext4_mb_unload_buddy(&e4b);
+		ext4_mb_unload_allocator(&e4b);
 		list_del(&pa->u.pa_tmp_list);
 		call_rcu(&(pa)->u.pa_rcu, ext4_mb_pa_callback);
 	}
@@ -5241,8 +5243,8 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
 	trace_ext4_mballoc_free(sb, inode, block_group, bit, count_clusters);
 
 	/* __GFP_NOFAIL: retry infinitely, ignore TIF_MEMDIE and memcg limit. */
-	err = ext4_mb_load_buddy_gfp(sb, block_group, &e4b,
-				     GFP_NOFS|__GFP_NOFAIL);
+	err = ext4_mb_load_allocator_gfp(sb, block_group, &e4b,
+					GFP_NOFS|__GFP_NOFAIL, 0);
 	if (err)
 		goto error_return;
 
@@ -5316,7 +5318,7 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
 				   count_clusters);
 	}
 
-	ext4_mb_unload_buddy(&e4b);
+	ext4_mb_unload_allocator(&e4b);
 
 	/* We dirtied the bitmap block */
 	BUFFER_TRACE(bitmap_bh, "dirtied bitmap block");
@@ -5434,7 +5436,7 @@ int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
 		}
 	}
 
-	err = ext4_mb_load_buddy(sb, block_group, &e4b);
+	err = ext4_mb_load_allocator(sb, block_group, &e4b, 0);
 	if (err)
 		goto error_return;
 
@@ -5462,7 +5464,7 @@ int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
 						  flex_group)->free_clusters);
 	}
 
-	ext4_mb_unload_buddy(&e4b);
+	ext4_mb_unload_allocator(&e4b);
 
 	/* We dirtied the bitmap block */
 	BUFFER_TRACE(bitmap_bh, "dirtied bitmap block");
@@ -5550,7 +5552,7 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
 
 	trace_ext4_trim_all_free(sb, group, start, max);
 
-	ret = ext4_mb_load_buddy(sb, group, &e4b);
+	ret = ext4_mb_load_allocator(sb, group, &e4b, 0);
 	if (ret) {
 		ext4_warning(sb, "Error %d loading buddy information for %u",
 			     ret, group);
@@ -5604,7 +5606,7 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
 	}
 out:
 	ext4_unlock_group(sb, group);
-	ext4_mb_unload_buddy(&e4b);
+	ext4_mb_unload_allocator(&e4b);
 
 	ext4_debug("trimmed %d blocks in the group %d\n",
 		count, group);
@@ -5718,7 +5720,7 @@ ext4_mballoc_query_range(
 	struct ext4_buddy		e4b;
 	int				error;
 
-	error = ext4_mb_load_buddy(sb, group, &e4b);
+	error = ext4_mb_load_allocator(sb, group, &e4b, 0);
 	if (error)
 		return error;
 	bitmap = e4b.bd_bitmap;
@@ -5747,7 +5749,7 @@ ext4_mballoc_query_range(
 
 	ext4_unlock_group(sb, group);
 out_unload:
-	ext4_mb_unload_buddy(&e4b);
+	ext4_mb_unload_allocator(&e4b);
 
 	return error;
 }
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
#3 lore raw

RFC PATCH v2 3/9 ext4: add freespace tree allocator

In reply to Harshad Shirwadkar

From: Yuexin Li <[email protected]>

This patch adds a new freespace tree allocator. The allocator organizes free space regions in a couple of in-memory rbtrees, one sorted by length and the other by offset. We use these per-flex-bg level trees to quickly scan length sorted free space regions and determine the best region for a given request. This feature can be enabled by passing "-o freespace_tree" mount option.

---
 fs/ext4/ext4.h    |  45 +++
 fs/ext4/mballoc.c | 984 ++++++++++++++++++++++++++++++++++++++++++++--
 fs/ext4/mballoc.h |  61 ++-
 fs/ext4/resize.c  |   8 +
 fs/ext4/super.c   |  35 +-
 5 files changed, 1084 insertions(+), 49 deletions(-)
fs/ext4/ext4.h +45 -0
index 523e00d7b392..513c8473f45f 100644
@@ -363,6 +363,7 @@ struct flex_groups {
 	atomic64_t	free_clusters;
 	atomic_t	free_inodes;
 	atomic_t	used_dirs;
+	struct ext4_frsp_tree	*frsp_tree;
 };
 
 #define EXT4_BG_INODE_UNINIT	0x0001 /* Inode table/bitmap not in use */
@@ -1214,6 +1215,12 @@ struct ext4_inode_info {
 #define EXT4_MOUNT2_EXPLICIT_JOURNAL_CHECKSUM	0x00000008 /* User explicitly
 						specified journal checksum */
 
+
+#define EXT4_MOUNT2_FREESPACE_TREE	0x00000020 /* Enable freespace tree
+						    * allocator (turns buddy
+						    * allocator off)
+						    */
+
 #define clear_opt(sb, opt)		EXT4_SB(sb)->s_mount_opt &= \
 						~EXT4_MOUNT_##opt
 #define set_opt(sb, opt)		EXT4_SB(sb)->s_mount_opt |= \
@@ -1419,6 +1426,30 @@ struct ext4_super_block {
 #define ext4_has_strict_mode(sbi) \
 	(sbi->s_encoding_flags & EXT4_ENC_STRICT_MODE_FL)
 
+/*
+ * Freespace tree structure
+ */
+struct ext4_frsp_tree {
+	struct rb_root_cached frsp_offset_root;		/* Root for offset
+							 * sorted tree
+							 */
+	struct rb_root_cached frsp_len_root;		/* Root for Length
+							 * sorted tree
+							 */
+	struct mutex frsp_lock;
+	__u8 frsp_flags;
+	__u32 frsp_max_free_len;			/* Max free extent in
+							 * this flex bg
+							 */
+	__u32 frsp_index;				/* Tree index (flex bg
+							 * number)
+							 */
+};
+
+/* Freespace tree flags */
+
+/* Tree is loaded in memory */
+#define EXT4_MB_FRSP_FLAG_LOADED			0x0001
 /*
  * fourth extended-fs super-block data in memory
  */
@@ -1557,6 +1588,9 @@ struct ext4_sb_info {
 	struct flex_groups * __rcu *s_flex_groups;
 	ext4_group_t s_flex_groups_allocated;
 
+	/* freespace trees stuff */
+	int s_mb_num_frsp_trees;
+
 	/* workqueue for reserved extent conversions (buffered io) */
 	struct workqueue_struct *rsv_conversion_wq;
 
@@ -2676,6 +2710,7 @@ extern int ext4_init_inode_table(struct super_block *sb,
 extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate);
 
 /* mballoc.c */
+extern int ext4_mb_add_frsp_trees(struct super_block *sb, int ngroups);
 extern const struct seq_operations ext4_mb_seq_groups_ops;
 extern long ext4_mb_stats;
 extern long ext4_mb_max_to_scan;
@@ -3100,6 +3135,16 @@ static inline ext4_group_t ext4_flex_group(struct ext4_sb_info *sbi,
 	return block_group >> sbi->s_log_groups_per_flex;
 }
 
+static inline struct ext4_frsp_tree *
+ext4_get_frsp_tree(struct super_block *sb, ext4_group_t flex_bg)
+{
+	struct flex_groups *fg;
+
+	fg = sbi_array_rcu_deref(EXT4_SB(sb), s_flex_groups, flex_bg);
+
+	return fg->frsp_tree;
+}
+
 static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi)
 {
 	return 1 << sbi->s_log_groups_per_flex;
fs/ext4/mballoc.c +958 -26

1,220 lines not on this page · raw message

fs/ext4/mballoc.h +54 -7

95 lines not on this page · raw message

fs/ext4/resize.c +8 -0
index a50b51270ea9..6a0e1fc18e95 100644
@@ -1679,6 +1679,10 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
 	if (err)
 		goto out;
 
+	err = ext4_mb_add_frsp_trees(sb, input->group + 1);
+	if (err)
+		goto out;
+
 	flex_gd.count = 1;
 	flex_gd.groups = input;
 	flex_gd.bg_flags = &bg_flags;
@@ -2051,6 +2055,10 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
 	if (err)
 		goto out;
 
+	err = ext4_mb_add_frsp_trees(sb, n_group + 1);
+	if (err)
+		goto out;
+
 	flex_gd = alloc_flex_gd(flexbg_size);
 	if (flex_gd == NULL) {
 		err = -ENOMEM;
fs/ext4/super.c +19 -16
index 656eccf6fc9b..55ff4e8be976 100644
@@ -1526,7 +1526,7 @@ enum {
 	Opt_dioread_nolock, Opt_dioread_lock,
 	Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
 	Opt_max_dir_size_kb, Opt_nojournal_checksum, Opt_nombcache,
-	Opt_prefetch_block_bitmaps,
+	Opt_prefetch_block_bitmaps, Opt_freespace_tree,
 };
 
 static const match_table_t tokens = {
@@ -1613,6 +1613,7 @@ static const match_table_t tokens = {
 	{Opt_init_itable, "init_itable=%u"},
 	{Opt_init_itable, "init_itable"},
 	{Opt_noinit_itable, "noinit_itable"},
+	{Opt_freespace_tree, "freespace_tree"},
 	{Opt_max_dir_size_kb, "max_dir_size_kb=%u"},
 	{Opt_test_dummy_encryption, "test_dummy_encryption=%s"},
 	{Opt_test_dummy_encryption, "test_dummy_encryption"},
@@ -1839,6 +1840,8 @@ static const struct mount_opts {
 	{Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET},
 	{Opt_prefetch_block_bitmaps, EXT4_MOUNT_PREFETCH_BLOCK_BITMAPS,
 	 MOPT_SET},
+	{Opt_freespace_tree, EXT4_MOUNT2_FREESPACE_TREE,
+	 MOPT_SET | MOPT_2 | MOPT_EXT4_ONLY},
 	{Opt_err, 0, 0}
 };
 
@@ -4745,12 +4748,19 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 		}
 	}
 
+	if (ext4_has_feature_flex_bg(sb))
+		if (!ext4_fill_flex_info(sb)) {
+			ext4_msg(sb, KERN_ERR,
+			       "unable to initialize flex_bg meta info!");
+			goto failed_mount5;
+		}
+
 	ext4_ext_init(sb);
 	err = ext4_mb_init(sb);
 	if (err) {
 		ext4_msg(sb, KERN_ERR, "failed to initialize mballoc (%d)",
 			 err);
-		goto failed_mount5;
+		goto failed_mount6;
 	}
 
 	block = ext4_count_free_clusters(sb);
@@ -4780,14 +4790,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 		goto failed_mount6;
 	}
 
-	if (ext4_has_feature_flex_bg(sb))
-		if (!ext4_fill_flex_info(sb)) {
-			ext4_msg(sb, KERN_ERR,
-			       "unable to initialize "
-			       "flex_bg meta info!");
-			goto failed_mount6;
-		}
-
 	err = ext4_register_li_request(sb, first_not_zeroed);
 	if (err)
 		goto failed_mount6;
@@ -4872,7 +4874,14 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 	ext4_unregister_li_request(sb);
 failed_mount6:
 	ext4_mb_release(sb);
+	percpu_counter_destroy(&sbi->s_freeclusters_counter);
+	percpu_counter_destroy(&sbi->s_freeinodes_counter);
+	percpu_counter_destroy(&sbi->s_dirs_counter);
+	percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
+	percpu_free_rwsem(&sbi->s_writepages_rwsem);
 	rcu_read_lock();
+
+failed_mount5:
 	flex_groups = rcu_dereference(sbi->s_flex_groups);
 	if (flex_groups) {
 		for (i = 0; i < sbi->s_flex_groups_allocated; i++)
@@ -4880,12 +4889,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 		kvfree(flex_groups);
 	}
 	rcu_read_unlock();
-	percpu_counter_destroy(&sbi->s_freeclusters_counter);
-	percpu_counter_destroy(&sbi->s_freeinodes_counter);
-	percpu_counter_destroy(&sbi->s_dirs_counter);
-	percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
-	percpu_free_rwsem(&sbi->s_writepages_rwsem);
-failed_mount5:
 	ext4_ext_release(sb);
 	ext4_release_system_zone(sb);
 failed_mount4a:
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
#7 lore raw

RFC PATCH v2 5/9 ext4: add freespace tree optimizations

In reply to Harshad Shirwadkar

From: Harshad Shirwadkar <[email protected]>

This patch adds an optimization on top of our freespace tree allocator. We add a new meta-tree which contains tree node sorted by length of their largest extent. We use this tree to optimize an allocation request so that it immediately gets a hit or it falls back to next CR level.

---
 fs/ext4/ext4.h    |  17 +++++
 fs/ext4/mballoc.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/ext4/mballoc.h |   1 +
 fs/ext4/super.c   |   9 +++
 4 files changed, 205 insertions(+)
fs/ext4/ext4.h +17 -0
index 513c8473f45f..15e6ce9f1afa 100644
@@ -153,6 +153,8 @@ enum SHIFT_DIRECTION {
 #define EXT4_MB_USE_RESERVED		0x2000
 /* Do strict check for free blocks while retrying block allocation */
 #define EXT4_MB_STRICT_CHECK		0x4000
+/* Disable freespace optimizations on ac */
+#define EXT4_MB_FRSP_NO_OPTIMIZE	0x8000
 
 struct ext4_allocation_request {
 	/* target inode for block we're allocating */
@@ -1444,12 +1446,22 @@ struct ext4_frsp_tree {
 	__u32 frsp_index;				/* Tree index (flex bg
 							 * number)
 							 */
+	struct list_head frsp_list_node;
+	struct rb_node frsp_len_node;
 };
 
 /* Freespace tree flags */
 
 /* Tree is loaded in memory */
 #define EXT4_MB_FRSP_FLAG_LOADED			0x0001
+/* Tree is inserted into meta tree */
+#define EXT4_MB_FRSP_FLAG_CACHED			0x2
+
+/* Freespace tree cache aggression levels */
+#define EXT4_MB_FRSP_MIN_CACHE_AGGRESSION		0x0
+#define EXT4_MB_FRSP_DEFAULT_CACHE_AGGRESSION		0x1
+#define EXT4_MB_FRSP_MAX_CACHE_AGGRESSION		0x3
+
 /*
  * fourth extended-fs super-block data in memory
  */
@@ -1590,6 +1602,11 @@ struct ext4_sb_info {
 
 	/* freespace trees stuff */
 	int s_mb_num_frsp_trees;
+	struct rb_root_cached s_mb_frsp_meta_tree;
+	rwlock_t s_mb_frsp_lock;
+	atomic_t s_mb_num_frsp_trees_cached;
+	struct list_head s_mb_uncached_trees;
+	u32 s_mb_frsp_cache_aggression;
 
 	/* workqueue for reserved extent conversions (buffered io) */
 	struct workqueue_struct *rsv_conversion_wq;
fs/ext4/mballoc.c +178 -0

264 lines not on this page · raw message

fs/ext4/mballoc.h +1 -0
index af61651258a3..1fcdd3e6f7d5 100644
@@ -200,6 +200,7 @@ struct ext4_allocation_context {
 	__u8 ac_criteria;
 	__u8 ac_2order;		/* if request is to allocate 2^N blocks and
 				 * N > 0, the field stores N, otherwise 0 */
+	__u8 ac_num_optimizations;
 	__u8 ac_op;		/* operation, for history only */
 	struct page *ac_bitmap_page;
 	struct page *ac_buddy_page;
fs/ext4/super.c +9 -0
index 55ff4e8be976..6a2d43d81b14 100644
@@ -1527,6 +1527,8 @@ enum {
 	Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
 	Opt_max_dir_size_kb, Opt_nojournal_checksum, Opt_nombcache,
 	Opt_prefetch_block_bitmaps, Opt_freespace_tree,
+	Opt_frsp_cache_aggression,
+
 };
 
 static const match_table_t tokens = {
@@ -1620,6 +1622,7 @@ static const match_table_t tokens = {
 	{Opt_nombcache, "nombcache"},
 	{Opt_nombcache, "no_mbcache"},	/* for backward compatibility */
 	{Opt_prefetch_block_bitmaps, "prefetch_block_bitmaps"},
+	{Opt_frsp_cache_aggression, "frsp_cache_aggression=%u"},
 	{Opt_removed, "check=none"},	/* mount option from ext2/3 */
 	{Opt_removed, "nocheck"},	/* mount option from ext2/3 */
 	{Opt_removed, "reservation"},	/* mount option from ext2/3 */
@@ -1836,6 +1839,7 @@ static const struct mount_opts {
 	{Opt_jqfmt_vfsv0, QFMT_VFS_V0, MOPT_QFMT},
 	{Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT},
 	{Opt_max_dir_size_kb, 0, MOPT_GTE0},
+	{Opt_frsp_cache_aggression, 0, MOPT_GTE0},
 	{Opt_test_dummy_encryption, 0, MOPT_STRING},
 	{Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET},
 	{Opt_prefetch_block_bitmaps, EXT4_MOUNT_PREFETCH_BLOCK_BITMAPS,
@@ -2043,6 +2047,10 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
 		sbi->s_li_wait_mult = arg;
 	} else if (token == Opt_max_dir_size_kb) {
 		sbi->s_max_dir_size_kb = arg;
+	} else if (token == Opt_frsp_cache_aggression) {
+		sbi->s_mb_frsp_cache_aggression =
+			min(EXT4_MB_FRSP_MAX_CACHE_AGGRESSION,
+				max(EXT4_MB_FRSP_MIN_CACHE_AGGRESSION, arg));
 	} else if (token == Opt_stripe) {
 		sbi->s_stripe = arg;
 	} else if (token == Opt_resuid) {
@@ -3962,6 +3970,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 	sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ;
 	sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;
 	sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;
+	sbi->s_mb_frsp_cache_aggression = EXT4_MB_FRSP_DEFAULT_CACHE_AGGRESSION;
 
 	if ((def_mount_opts & EXT4_DEFM_NOBARRIER) == 0)
 		set_opt(sb, BARRIER);
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
#9 lore raw

RFC PATCH v2 6/9 ext4: add memory usage tracker for freespace trees

In reply to Harshad Shirwadkar

From: Harshad Shirwadkar <[email protected]>

Freespace trees can occupy a lot of memory with as the fragmentation increases. This patch adds a sysfs file to monitor the memory usage of the freespace tree allocator. Also, added a sysfs config to control maximum memory that the allocator can use. If the allocator exceeds this threshold, file system enters "FRSP_MEM_CRUNCH" state. The next patch in the series performs LRU eviction when this state is reached.

---
 fs/ext4/ext4.h    |  8 ++++++++
 fs/ext4/mballoc.c | 20 ++++++++++++++++++++
 fs/ext4/mballoc.h |  4 ++++
 fs/ext4/sysfs.c   | 11 +++++++++++
 4 files changed, 43 insertions(+)
fs/ext4/ext4.h +8 -0
index 15e6ce9f1afa..93bf2fe35cf1 100644
@@ -1223,6 +1223,12 @@ struct ext4_inode_info {
 						    * allocator off)
 						    */
 
+#define EXT4_MOUNT2_FRSP_MEM_CRUNCH	0x00000040 /*
+						    * Freespace tree allocator
+						    * is in a tight memory
+						    * situation.
+						    */
+
 #define clear_opt(sb, opt)		EXT4_SB(sb)->s_mount_opt &= \
 						~EXT4_MOUNT_##opt
 #define set_opt(sb, opt)		EXT4_SB(sb)->s_mount_opt |= \
@@ -1607,6 +1613,8 @@ struct ext4_sb_info {
 	atomic_t s_mb_num_frsp_trees_cached;
 	struct list_head s_mb_uncached_trees;
 	u32 s_mb_frsp_cache_aggression;
+	atomic_t s_mb_num_fragments;
+	u32 s_mb_frsp_mem_limit;
 
 	/* workqueue for reserved extent conversions (buffered io) */
 	struct workqueue_struct *rsv_conversion_wq;
fs/ext4/mballoc.c +20 -0
index 1da63afdbb3d..b28b7fb0506e 100644
@@ -869,6 +869,7 @@ void ext4_mb_frsp_print_tree_len(struct super_block *sb,
 static struct ext4_frsp_node *ext4_mb_frsp_alloc_node(struct super_block *sb)
 {
 	struct ext4_frsp_node *node;
+	struct ext4_sb_info *sbi = EXT4_SB(sb);
 
 	node = kmem_cache_alloc(ext4_freespace_node_cachep, GFP_NOFS);
 	if (!node)
@@ -877,13 +878,31 @@ static struct ext4_frsp_node *ext4_mb_frsp_alloc_node(struct super_block *sb)
 	RB_CLEAR_NODE(&node->frsp_node);
 	RB_CLEAR_NODE(&node->frsp_len_node);
 
+	atomic_inc(&sbi->s_mb_num_fragments);
+
+	if (sbi->s_mb_frsp_mem_limit &&
+		atomic_read(&sbi->s_mb_num_fragments) >
+		EXT4_FRSP_MEM_LIMIT_TO_NUM_NODES(sb))
+		set_opt2(sb, FRSP_MEM_CRUNCH);
+	else
+		clear_opt2(sb, FRSP_MEM_CRUNCH);
+
+
 	return node;
 }
 
 static void ext4_mb_frsp_free_node(struct super_block *sb,
 		struct ext4_frsp_node *node)
 {
+	struct ext4_sb_info *sbi = EXT4_SB(sb);
+
 	kmem_cache_free(ext4_freespace_node_cachep, node);
+	atomic_dec(&sbi->s_mb_num_fragments);
+
+	if (!sbi->s_mb_frsp_mem_limit ||
+		atomic_read(&sbi->s_mb_num_fragments) <
+		EXT4_FRSP_MEM_LIMIT_TO_NUM_NODES(sb))
+		clear_opt2(sb, FRSP_MEM_CRUNCH);
 }
 
 /* Evict a tree from memory */
@@ -1607,6 +1626,7 @@ int ext4_mb_init_freespace_trees(struct super_block *sb)
 	}
 	rwlock_init(&sbi->s_mb_frsp_lock);
 	atomic_set(&sbi->s_mb_num_frsp_trees_cached, 0);
+	atomic_set(&sbi->s_mb_num_fragments, 0);
 
 	return 0;
 }
fs/ext4/mballoc.h +4 -0
index 1fcdd3e6f7d5..6cfb228e4da2 100644
@@ -92,6 +92,10 @@ struct ext4_frsp_node {
 	struct rb_node frsp_node;
 	struct rb_node frsp_len_node;
 };
+
+#define EXT4_FRSP_MEM_LIMIT_TO_NUM_NODES(__sb)				\
+	((sbi->s_mb_frsp_mem_limit / sizeof(struct ext4_frsp_node)))
+
 struct ext4_free_data {
 	/* this links the free block information from sb_info */
 	struct list_head		efd_list;
fs/ext4/sysfs.c +11 -0
index bfabb799fa45..19301b10944b 100644
@@ -8,6 +8,7 @@
  *
  */
 
+#include "mballoc.h"
 #include <linux/time.h>
 #include <linux/fs.h>
 #include <linux/seq_file.h>
@@ -24,6 +25,7 @@ typedef enum {
 	attr_session_write_kbytes,
 	attr_lifetime_write_kbytes,
 	attr_reserved_clusters,
+	attr_frsp_tree_usage,
 	attr_inode_readahead,
 	attr_trigger_test_error,
 	attr_first_error_time,
@@ -208,6 +210,7 @@ EXT4_ATTR_FUNC(delayed_allocation_blocks, 0444);
 EXT4_ATTR_FUNC(session_write_kbytes, 0444);
 EXT4_ATTR_FUNC(lifetime_write_kbytes, 0444);
 EXT4_ATTR_FUNC(reserved_clusters, 0644);
+EXT4_ATTR_FUNC(frsp_tree_usage, 0444);
 
 EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, inode_readahead,
 		 ext4_sb_info, s_inode_readahead_blks);
@@ -248,6 +251,7 @@ EXT4_ATTR(last_error_time, 0444, last_error_time);
 EXT4_ATTR(journal_task, 0444, journal_task);
 EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch);
 EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit);
+EXT4_RW_ATTR_SBI_UI(mb_frsp_max_mem, s_mb_frsp_mem_limit);
 
 static unsigned int old_bump_val = 128;
 EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val);
@@ -257,6 +261,7 @@ static struct attribute *ext4_attrs[] = {
 	ATTR_LIST(session_write_kbytes),
 	ATTR_LIST(lifetime_write_kbytes),
 	ATTR_LIST(reserved_clusters),
+	ATTR_LIST(frsp_tree_usage),
 	ATTR_LIST(inode_readahead_blks),
 	ATTR_LIST(inode_goal),
 	ATTR_LIST(mb_stats),
@@ -296,6 +301,7 @@ static struct attribute *ext4_attrs[] = {
 #endif
 	ATTR_LIST(mb_prefetch),
 	ATTR_LIST(mb_prefetch_limit),
+	ATTR_LIST(mb_frsp_max_mem),
 	NULL,
 };
 ATTRIBUTE_GROUPS(ext4);
@@ -378,6 +384,11 @@ static ssize_t ext4_attr_show(struct kobject *kobj,
 		return snprintf(buf, PAGE_SIZE, "%llu\n",
 				(unsigned long long)
 				atomic64_read(&sbi->s_resv_clusters));
+	case attr_frsp_tree_usage:
+		return snprintf(buf, PAGE_SIZE, "%llu\n",
+				(unsigned long long)
+				atomic_read(&sbi->s_mb_num_fragments) *
+				sizeof(struct ext4_frsp_node));
 	case attr_inode_readahead:
 	case attr_pointer_ui:
 		if (!ptr)
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
#10 lore raw

RFC PATCH v2 7/9 ext4: add LRU eviction for free space trees

In reply to Harshad Shirwadkar

From: Harshad Shirwadkar <[email protected]>

This patch adds LRU eviction policy for freespace trees. In order to avoid contention on one LRU lock, the LRU scheme is implemented as two lists - an active list and an inactive list. Trees in active list aren't moved inside the list thereby avoiding the need of a lock. Trees in inactive list become active only if they are accessed twice in a short interval thereby avoiding outliers to enter the active list.

---
 fs/ext4/ext4.h    |  46 +++++++++++++
 fs/ext4/mballoc.c | 164 ++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 197 insertions(+), 13 deletions(-)
fs/ext4/ext4.h +46 -0
index 93bf2fe35cf1..64d0dbbcd517 100644
@@ -1454,6 +1454,10 @@ struct ext4_frsp_tree {
 							 */
 	struct list_head frsp_list_node;
 	struct rb_node frsp_len_node;
+	atomic_t frsp_fragments;
+	struct list_head frsp_lru_active_node;
+	unsigned long frsp_last_access;
+	atomic_t frsp_ref;
 };
 
 /* Freespace tree flags */
@@ -1468,6 +1472,47 @@ struct ext4_frsp_tree {
 #define EXT4_MB_FRSP_DEFAULT_CACHE_AGGRESSION		0x1
 #define EXT4_MB_FRSP_MAX_CACHE_AGGRESSION		0x3
 
+/* LRU management for free space trees */
+struct ext4_mb_frsp_lru {
+	rwlock_t frsp_lru_lock;
+	atomic_t frsp_active_fragments;		/* Current #of fragments in
+						 * the active queue
+						 */
+	u32 frsp_max_active_fragments;
+	/*
+	 * List of active trees. Trees at tail are oldest trees in active set.
+	 */
+	struct list_head frsp_lru_active;
+	/*
+	 * List of inactive trees but loaded trees.
+	 */
+	struct list_head frsp_lru_inactive;
+	struct super_block *frsp_lru_sb;
+};
+
+/*
+ * Minimum memory needed for our allocator. The pathological worst case for
+ * freespace trees is when every other block is allocated. In this case,
+ * the allocator will end up storing an extent node of length 1 for each free
+ * block. We need to make sure that the minimum memory available for the
+ * allocator is as much memory needed for 1 worst-case tree. This ensures that
+ * we can at-least keep 1 tree in memory. This way we avoid thrashing.
+ */
+#define EXT4_MB_FRSP_MEM_MIN(sb)					\
+	((sizeof(struct ext4_frsp_node) * ext4_flex_bg_size(EXT4_SB(sb))) \
+		* (EXT4_BLOCKS_PER_GROUP(sb) / 2))
+
+/* Half of the total memory available is allowed for active list */
+#define EXT4_MB_FRSP_MAX_ACTIVE_FRAGMENTS(sb)				\
+	((EXT4_SB(sb)->s_mb_frsp_mem_limit /				\
+		(2 * sizeof(struct ext4_frsp_node))))
+
+/*
+ * Maximum number of jiffies allowed between two successive hits on a freespace
+ * tree before we move it to the "active" queue.
+ */
+#define EXT4_MB_FRSP_ACTIVE_THRESHOLD_JIFFIES		100
+
 /*
  * fourth extended-fs super-block data in memory
  */
@@ -1615,6 +1660,7 @@ struct ext4_sb_info {
 	u32 s_mb_frsp_cache_aggression;
 	atomic_t s_mb_num_fragments;
 	u32 s_mb_frsp_mem_limit;
+	struct ext4_mb_frsp_lru s_mb_frsp_lru;
 
 	/* workqueue for reserved extent conversions (buffered io) */
 	struct workqueue_struct *rsv_conversion_wq;
fs/ext4/mballoc.c +151 -13

284 lines not on this page · raw message

Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
#11 lore raw

RFC PATCH v2 8/9 ext4: add tracepoints for free space trees

In reply to Harshad Shirwadkar

From: Harshad Shirwadkar <[email protected]>

This patch adds a few trace points to track the flow of allocation requests with free space trees.

---
 fs/ext4/ext4.h              |   1 +
 fs/ext4/mballoc.c           |   9 +++
 fs/ext4/mballoc.h           |   3 +-
 include/trace/events/ext4.h | 112 ++++++++++++++++++++++++++++++++++++
 4 files changed, 124 insertions(+), 1 deletion(-)
fs/ext4/ext4.h +1 -0
index 64d0dbbcd517..22850763c5a8 100644
@@ -1661,6 +1661,7 @@ struct ext4_sb_info {
 	atomic_t s_mb_num_fragments;
 	u32 s_mb_frsp_mem_limit;
 	struct ext4_mb_frsp_lru s_mb_frsp_lru;
+	atomic_t s_mb_ac_id;
 
 	/* workqueue for reserved extent conversions (buffered io) */
 	struct workqueue_struct *rsv_conversion_wq;
fs/ext4/mballoc.c +9 -0
index aea0eb8d28da..eb99e2fb9a68 100644
@@ -945,6 +945,7 @@ void ext4_mb_frsp_free_tree(struct super_block *sb, struct ext4_frsp_tree *tree)
 	tree->frsp_len_root = RB_ROOT_CACHED;
 out:
 	mutex_unlock(&tree->frsp_lock);
+	trace_ext4_mb_frsp_free_tree(sb, tree->frsp_index);
 }
 
 /*
@@ -1476,6 +1477,7 @@ int ext4_mb_frsp_optimize(struct ext4_allocation_context *ac, int *tree_idx)
 	mb_debug(ac->ac_sb,
 		"Optimizer suggestion: found = %d, tree = %d, len = %d, cr = %d\n",
 		found, *tree_idx, better_len, ac->ac_criteria);
+	trace_ext4_mb_frsp_optimize(ac, found, cache_more_trees, *tree_idx);
 	return ret;
 }
 
@@ -1546,6 +1548,11 @@ ext4_mb_tree_allocator(struct ext4_allocation_context *ac)
 		ac->ac_groups_scanned++;
 		tree_idx = (j % sbi->s_mb_num_frsp_trees);
 
+		trace_ext4_mb_tree_allocator(ac, tree_idx,
+				sbi->s_mb_num_frsp_trees,
+				atomic_read(&sbi->s_mb_num_frsp_trees_cached),
+				atomic_read(&sbi->s_mb_num_fragments) *
+				sizeof(struct ext4_frsp_node));
 		ret = ext4_mb_load_allocator(sb,
 				tree_idx * ext4_flex_bg_size(sbi), &e4b, 0);
 		if (ret)
@@ -1655,6 +1662,7 @@ int ext4_mb_init_freespace_trees(struct super_block *sb)
 	if (sbi->s_mb_frsp_mem_limit < EXT4_MB_FRSP_MEM_MIN(sb))
 		sbi->s_mb_frsp_mem_limit = EXT4_MB_FRSP_MEM_MIN(sb);
 	atomic_set(&sbi->s_mb_frsp_lru.frsp_active_fragments, 0);
+	atomic_set(&sbi->s_mb_ac_id, 0);
 
 	return 0;
 }
@@ -5794,6 +5802,7 @@ ext4_mb_initialize_context(struct ext4_allocation_context *ac,
 	ext4_get_group_no_and_offset(sb, goal, &group, &block);
 
 	/* set up allocation goals */
+	ac->ac_id = atomic_inc_return(&sbi->s_mb_ac_id);
 	ac->ac_b_ex.fe_logical = EXT4_LBLK_CMASK(sbi, ar->logical);
 	ac->ac_status = AC_STATUS_CONTINUE;
 	ac->ac_sb = sb;
fs/ext4/mballoc.h +2 -1
index 6cfb228e4da2..e734c05572b6 100644
@@ -171,7 +171,6 @@ struct ext4_tree_extent {
 };
 
 struct ext4_allocation_context {
-	__u32	ac_id;
 	struct inode *ac_inode;
 	struct super_block *ac_sb;
 
@@ -206,6 +205,8 @@ struct ext4_allocation_context {
 				 * N > 0, the field stores N, otherwise 0 */
 	__u8 ac_num_optimizations;
 	__u8 ac_op;		/* operation, for history only */
+	__u8 ac_id;		/* allocation ID for tracking purpose */
+
 	struct page *ac_bitmap_page;
 	struct page *ac_buddy_page;
 	struct ext4_prealloc_space *ac_pa;
include/trace/events/ext4.h +112 -0

118 lines not on this page · raw message

Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
#12 lore raw

RFC PATCH v2 9/9 ext4: add freespace trees documentation in code

In reply to Harshad Shirwadkar

From: Harshad Shirwadkar <[email protected]>

This patch adds a comment in mballoc.c describing the design and flow of free-space trees.

---
 fs/ext4/mballoc.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)
fs/ext4/mballoc.c +116 -0
index eb99e2fb9a68..b5d55a52daff 100644
@@ -330,6 +330,122 @@
  *        object
  *
  */
+
+/*
+ * The freespace tree allocator
+ * -----------------------------
+ *
+ * High Level Design
+ * =================
+ * This allocator maintains the free space information about the file system in
+ * per-flexible block group level trees. For every flexible block group, we
+ * maintain individual freespace nodes in two trees, one sorted by flex-bg
+ * offset and other sorted by length. This gives us two benefits: i) In
+ * allocation path, our search time complexity is O(Log(Number of freespace
+ * regions in the flex-bg)). ii) In free path, in the same time complexity we
+ * can merge the adjacent nodes thereby reducing the size of the tree
+ * efficiently.
+ *
+ * Along with flexible block group level trees, we also introduce a top level
+ * meta-tree which consists of individual trees. This tree is sorted by length
+ * of largest extents found in flex-bgs. The key advantage that this tree gives
+ * us is this: During an allocation request, the allocator is now able to
+ * consult this tree and directly (in O(Log(Number of Flex BGs)) jump to a
+ * flexible block group which definitely has at least one (the largest) extent
+ * that can satisfy this request. If no flexible block group exists which can
+ * satisfy this request, the allocator can now immediately drop the CR level.
+ *
+ * In order to preseve the parallel allocation / free performance, the allocator
+ * only *tries* to consult this tree. It does so by calling read_trylock()
+ * function and if the meta-tree is busy, the allocator continues its linear
+ * search until it is able to grab a read-lock on this tree.
+ *
+ * Memory Footprint
+ * ================
+ *
+ * In a less fragmented file system, the memory footprint of the new allocator
+ * is significantly lower than buddy bitmaps. However, as the fragmentation
+ * level increases, the memory footprint of this allocator increases
+ * significantly. The memory usage of the freespace tree allocator can be
+ * controlled using sysfs tunable /sys/fs/ext4/<dev>/mb_frsp_max_mem. The
+ * default value of this is max(memory needed for buddy, maximum memory needed
+ * for one tree in the worst case). Accounting for max memory needed for one
+ * tree allows us to keep at least one tree in memory even in the worst
+ * case. This avoids thrashing. Once the memory threshold is reached, the
+ * allocator starts evicting trees from memory in LRU fashion. However, we don't
+ * remove tree's entry from the meta-tree. This allows the allocator to
+ * efficiently reconstruct only relevant trees from on-disk bitmaps. In our
+ * evaluations, we found that freespace tree allocator still manages to
+ * outperform buddy allocator in memory crunch situation.
+ *
+ * LRU
+ * ===
+ *
+ * We maintain two lists - an active list and an inactive list of trees. Trees
+ * in active list stay in it until evicted. In order to reduce contention on the
+ * active list lock, once a tree is in active list it is not moved inside the
+ * list. Also, a tree moves from inactive list to active list only if it is
+ * accessed twice in a EXT4_MB_FRSP_ACTIVE_THRESHOLD_JIFFIES window.
+ *
+ *
+ * Caching Tree Metadata
+ * =====================
+ * As noted in our experiments, we find caching tree metadata (the largest
+ * available extent in a tree) in the meta-tree significantly boosts allocation
+ * performance. However, if the allocator waits for the cache to fill up before
+ * starting to serve allocation requests, that may severely degrade allocation
+ * performance on large disks. Thus, it is important to tune the tree caching
+ * behavior according to the underlying block device. This patchset provides
+ * four cache aggression levels. Cache aggression level can be specified as a
+ * mount time parametere "frsp_cache_aggression". Here is the meaning of these
+ * different levels:
+ *
+ * Cache Aggression 0: Try to serve request only cached trees
+ * Cache Aggression 1 (Default): Try to serve request from only cached trees
+ *	at CR 0. At all other CRs, try to use an uncached tree for every
+ *	alternate request.
+ * Cache Aggression 2: Try to use an uncached tree for every alternate request
+ *	at all CR levels.
+ * Cache Aggression 3: Try to use uncached trees for every request.
+ *
+ * Moreover, if file system is mounted with "prefetch_block_bitmaps", tree
+ * caching starts at mount time.
+ *
+ * Locking Order
+ * =============
+ *
+ * - Tree lock
+ * - Meta tree lock (sbi->s_mb_frsp_lock)
+ * - LRU lock
+ *
+ * Critical sections of meta-tree lock and LRU locks are kept as small as
+ * possible and you shouldn't need to take meta-tree lock and lru-lock
+ * simultaneously.
+ *
+ * High Level Algorithm
+ * ====================
+ * - Consult meta-tree asking which flex-bg should the allocator look at
+ *   - One of the following things can happen
+ *     - Meta tree may find a suitable flex-bg for the request
+ *        - In this case we start searching in that tree
+ *     - Meta tree may realize that there's no suitable flex-bg
+ *        - In this case we increase CR and restart
+ *     - Based on the caching mode, meta tree may redirect us to an
+ *       uncached tree
+ *     - Meta tree is busy
+ *       - In this case, we dont wait for meta-tree to become available,
+ *         instead, we continue our search linearly.
+ * - Pick a tree (either based on what meta-tree told us or linearly from the
+ *   last one)
+ * - Manage LRU structure (ext4_mb_frsp_maintain_lru())
+ *   - Move tree to active list if needed
+ *   - Move trees from active list to inactive lists if needed
+ * - Perform search by length and pick matching extents.
+ * - Repeat until best found
+ * - Perform memory-crunch check and evict trees in LRU fashion if needed
+ *   (ext4_mb_unload_allocator()))
+ */
+
 static struct kmem_cache *ext4_pspace_cachep;
 static struct kmem_cache *ext4_ac_cachep;
 static struct kmem_cache *ext4_free_data_cachep;
Signature · 1 line
2.28.0.297.g1956fa8f8d-goog
#4 lore raw

Re: [RFC PATCH v2 3/9] ext4: add freespace tree allocator

In reply to Harshad Shirwadkar
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Harshad,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on ext4/dev]
[also build test ERROR on next-20200820]
[cannot apply to tip/perf/core v5.9-rc1]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Harshad-Shirwadkar/ext4-add-free-space-extent-based-allocator/20200821-095647
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: nds32-defconfig (attached as .config)
compiler: nds32le-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=nds32

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

nds32le-linux-ld: fs/ext4/mballoc.o: in function `ext4_mb_frsp_free_blocks':

>> mballoc.c:(.text+0x2b2e): undefined reference to `__umoddi3'
>> nds32le-linux-ld: mballoc.c:(.text+0x2b32): undefined reference to `__umoddi3'

nds32le-linux-ld: fs/ext4/mballoc.o: in function `ext4_mb_frsp_bb_to_tree':
mballoc.c:(.text+0x2c36): undefined reference to `__umoddi3'
nds32le-linux-ld: mballoc.c:(.text+0x2c3a): undefined reference to `__umoddi3'
nds32le-linux-ld: fs/ext4/mballoc.o: in function `mb_mark_used':
mballoc.c:(.text+0x54d4): undefined reference to `__umoddi3'
nds32le-linux-ld: fs/ext4/mballoc.o:mballoc.c:(.text+0x54d8): more undefined references to `__umoddi3' follow

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#5 lore raw

Re: [RFC PATCH v2 3/9] ext4: add freespace tree allocator

In reply to Harshad Shirwadkar
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Harshad,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on ext4/dev]
[also build test ERROR on next-20200820]
[cannot apply to tip/perf/core tytso-fscrypt/master v5.9-rc1] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Harshad-Shirwadkar/ext4-add-free-space-extent-based-allocator/20200821-095647
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: i386-randconfig-s001-20200820 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.2-191-g10164920-dirty
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386 

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

ld: fs/ext4/mballoc.o: in function `ext4_blkno_to_flex_offset':

>> fs/ext4/mballoc.c:407: undefined reference to `__umoddi3'
>> ld: fs/ext4/mballoc.c:407: undefined reference to `__umoddi3'
>> ld: fs/ext4/mballoc.c:407: undefined reference to `__umoddi3'
>> ld: fs/ext4/mballoc.c:407: undefined reference to `__umoddi3'
>> ld: fs/ext4/mballoc.c:407: undefined reference to `__umoddi3'

ld: fs/ext4/mballoc.o:fs/ext4/mballoc.c:407: more undefined references to `__umoddi3' follow

# https://github.com/0day-ci/linux/commit/db488bc7c0ef14f7ea22209b8faaddaffcfabbd5
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Harshad-Shirwadkar/ext4-add-free-space-extent-based-allocator/20200821-095647 git checkout db488bc7c0ef14f7ea22209b8faaddaffcfabbd5
vim +407 fs/ext4/mballoc.c

403
404 static inline int ext4_blkno_to_flex_offset(struct super_block *sb,
405 ext4_fsblk_t blkno)
406 {

 > 407		return blkno % (ext4_flex_bg_size(EXT4_SB(sb)) *

408 EXT4_SB(sb)->s_blocks_per_group);
409 }
410

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#8 lore raw

Re: [RFC PATCH v2 5/9] ext4: add freespace tree optimizations

In reply to Harshad Shirwadkar
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Harshad,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on ext4/dev]
[also build test WARNING on next-20200821]
[cannot apply to tip/perf/core v5.9-rc1]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Harshad-Shirwadkar/ext4-add-free-space-extent-based-allocator/20200821-095647
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: x86_64-randconfig-r036-20200820 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project b587ca93be114d07ec3bf654add97d7872325281)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> fs/ext4/mballoc.c:808:6: warning: no previous prototype for function 'ext4_mb_frsp_meta_reinsert' [-Wmissing-prototypes]
   void ext4_mb_frsp_meta_reinsert(struct super_block *sb,
        ^
   fs/ext4/mballoc.c:808:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   void ext4_mb_frsp_meta_reinsert(struct super_block *sb,
   ^
   static 
   fs/ext4/mballoc.c:890:6: warning: no previous prototype for function 'ext4_mb_frsp_free_tree' [-Wmissing-prototypes]
   void ext4_mb_frsp_free_tree(struct super_block *sb, struct ext4_frsp_tree *tree)
        ^
   fs/ext4/mballoc.c:890:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   void ext4_mb_frsp_free_tree(struct super_block *sb, struct ext4_frsp_tree *tree)
   ^
   static 
   fs/ext4/mballoc.c:920:24: warning: no previous prototype for function 'ext4_mb_frsp_search_by_off' [-Wmissing-prototypes]
   struct ext4_frsp_node *ext4_mb_frsp_search_by_off(struct super_block *sb,
                          ^
   fs/ext4/mballoc.c:920:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   struct ext4_frsp_node *ext4_mb_frsp_search_by_off(struct super_block *sb,
   ^
   static 
   fs/ext4/mballoc.c:945:5: warning: no previous prototype for function 'ext4_mb_frsp_node_can_merge' [-Wmissing-prototypes]
   int ext4_mb_frsp_node_can_merge(struct super_block *sb,
       ^
   fs/ext4/mballoc.c:945:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int ext4_mb_frsp_node_can_merge(struct super_block *sb,
   ^
   static 
   fs/ext4/mballoc.c:962:5: warning: no previous prototype for function 'ext4_mb_frsp_add_region' [-Wmissing-prototypes]
   int ext4_mb_frsp_add_region(struct super_block *sb, struct ext4_frsp_tree *tree,
       ^
   fs/ext4/mballoc.c:962:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int ext4_mb_frsp_add_region(struct super_block *sb, struct ext4_frsp_tree *tree,
   ^
   static 
   fs/ext4/mballoc.c:1014:5: warning: no previous prototype for function 'ext4_mb_frsp_free_blocks' [-Wmissing-prototypes]
   int ext4_mb_frsp_free_blocks(struct super_block *sb, ext4_group_t group,
       ^
   fs/ext4/mballoc.c:1014:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int ext4_mb_frsp_free_blocks(struct super_block *sb, ext4_group_t group,
   ^
   static 
   fs/ext4/mballoc.c:1034:5: warning: no previous prototype for function 'ext4_mb_frsp_bb_to_tree' [-Wmissing-prototypes]
   int ext4_mb_frsp_bb_to_tree(struct ext4_buddy *e4b, ext4_group_t group,
       ^
   fs/ext4/mballoc.c:1034:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int ext4_mb_frsp_bb_to_tree(struct ext4_buddy *e4b, ext4_group_t group,
   ^
   static 
   fs/ext4/mballoc.c:1066:5: warning: no previous prototype for function 'ext4_mb_frsp_load' [-Wmissing-prototypes]
   int ext4_mb_frsp_load(struct ext4_buddy *e4b)
       ^
   fs/ext4/mballoc.c:1066:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int ext4_mb_frsp_load(struct ext4_buddy *e4b)
   ^
   static 
>> fs/ext4/mballoc.c:1366:5: warning: no previous prototype for function 'ext4_mb_frsp_optimize' [-Wmissing-prototypes]
   int ext4_mb_frsp_optimize(struct ext4_allocation_context *ac, int *tree_idx)
       ^
   fs/ext4/mballoc.c:1366:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int ext4_mb_frsp_optimize(struct ext4_allocation_context *ac, int *tree_idx)
   ^
   static 
   fs/ext4/mballoc.c:1587:5: warning: no previous prototype for function 'ext4_mb_init_freespace_trees' [-Wmissing-prototypes]
   int ext4_mb_init_freespace_trees(struct super_block *sb)
       ^
   fs/ext4/mballoc.c:1587:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int ext4_mb_init_freespace_trees(struct super_block *sb)
   ^
   static 
   fs/ext4/mballoc.c:411:28: warning: unused function 'ext4_flex_offset_to_blkno' [-Wunused-function]
   static inline ext4_fsblk_t ext4_flex_offset_to_blkno(struct super_block *sb,
                              ^

11 warnings generated.

# https://github.com/0day-ci/linux/commit/832851db4656a8d433083fc076a53db955d43020
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Harshad-Shirwadkar/ext4-add-free-space-extent-based-allocator/20200821-095647 git checkout 832851db4656a8d433083fc076a53db955d43020
vim +/ext4_mb_frsp_meta_reinsert +808 fs/ext4/mballoc.c

807

 > 808	void ext4_mb_frsp_meta_reinsert(struct super_block *sb,

809 struct ext4_frsp_tree *tree)
810 {
811 struct ext4_sb_info *sbi = EXT4_SB(sb);
812 struct ext4_frsp_node *node;
813 struct rb_node *first = rb_first_cached(&tree->frsp_len_root);
814 struct rb_root_cached *meta_root = &EXT4_SB(sb)->s_mb_frsp_meta_tree;
815 int expected_len = 0;
816
817 if (!(tree->frsp_flags & EXT4_MB_FRSP_FLAG_LOADED))
818 return;
819
820 if (first) {
821 node = rb_entry(first, struct ext4_frsp_node, frsp_len_node);
822 expected_len = node->frsp_len;
823 }
824
825 if (tree->frsp_max_free_len == expected_len)
826 return;
827
828 write_lock(&sbi->s_mb_frsp_lock);
829 tree->frsp_max_free_len = expected_len;
830 rb_erase_cached(&tree->frsp_len_node, &sbi->s_mb_frsp_meta_tree);
831 RB_CLEAR_NODE(&tree->frsp_len_node);
832 ext4_mb_rb_insert(meta_root, tree, struct ext4_frsp_tree, frsp_len_node,
833 ext4_mb_frsp_meta_cmp);
834 write_unlock(&sbi->s_mb_frsp_lock);
835 }
836

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org