Skip to content

Commit 0cfcde1

Browse files
committed
Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
Pull ext4 updates from Ted Ts'o: "There are a number of major cleanups in ext4 this cycle: - The data=journal writepath has been significantly cleaned up and simplified, and reduces a large number of data=journal special cases by Jan Kara. - Ojaswin Muhoo has replaced linked list used to track extents that have been used for inode preallocation with a red-black tree in the multi-block allocator. This improves performance for workloads which do a large number of random allocating writes. - Thanks to Kemeng Shi for a lot of cleanup and bug fixes in the multi-block allocator. - Matthew wilcox has converted the code paths for reading and writing ext4 pages to use folios. - Jason Yan has continued to factor out ext4_fill_super() into smaller functions for improve ease of maintenance and comprehension. - Josh Triplett has created an uapi header for ext4 userspace API's" * tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (105 commits) ext4: Add a uapi header for ext4 userspace APIs ext4: remove useless conditional branch code ext4: remove unneeded check of nr_to_submit ext4: move dax and encrypt checking into ext4_check_feature_compatibility() ext4: factor out ext4_block_group_meta_init() ext4: move s_reserved_gdt_blocks and addressable checking into ext4_check_geometry() ext4: rename two functions with 'check' ext4: factor out ext4_flex_groups_free() ext4: use ext4_group_desc_free() in ext4_put_super() to save some duplicated code ext4: factor out ext4_percpu_param_init() and ext4_percpu_param_destroy() ext4: factor out ext4_hash_info_init() Revert "ext4: Fix warnings when freezing filesystem with journaled data" ext4: Update comment in mpage_prepare_extent_to_map() ext4: Simplify handling of journalled data in ext4_bmap() ext4: Drop special handling of journalled data from ext4_quota_on() ext4: Drop special handling of journalled data from ext4_evict_inode() ext4: Fix special handling of journalled data from extent zeroing ext4: Drop special handling of journalled data from extent shifting operations ext4: Drop special handling of journalled data from ext4_sync_file() ext4: Commit transaction before writing back pages in data=journal mode ...
2 parents c3558a6 + 519fe1b commit 0cfcde1

File tree

30 files changed

+1413
-1441
lines changed

30 files changed

+1413
-1441
lines changed

Documentation/admin-guide/ext4.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,6 @@ Files in /sys/fs/ext4/<devname>:
489489
multiple of this tuning parameter if the stripe size is not set in the
490490
ext4 superblock
491491

492-
mb_max_inode_prealloc
493-
The maximum length of per-inode ext4_prealloc_space list.
494-
495492
mb_max_to_scan
496493
The maximum number of extents the multiblock allocator will search to
497494
find the best extent.

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7745,6 +7745,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git
77457745
F: Documentation/filesystems/ext4/
77467746
F: fs/ext4/
77477747
F: include/trace/events/ext4.h
7748+
F: include/uapi/linux/ext4.h
77487749

77497750
Extended Verification Module (EVM)
77507751
M: Mimi Zohar <[email protected]>

block/bio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,7 @@ bool bio_add_folio(struct bio *bio, struct folio *folio, size_t len,
11591159
return false;
11601160
return bio_add_page(bio, &folio->page, len, off) > 0;
11611161
}
1162+
EXPORT_SYMBOL(bio_add_folio);
11621163

11631164
void __bio_release_pages(struct bio *bio, bool mark_dirty)
11641165
{

fs/ext4/balloc.c

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -80,79 +80,83 @@ static inline int ext4_block_in_group(struct super_block *sb,
8080
return (actual_group == block_group) ? 1 : 0;
8181
}
8282

83-
/* Return the number of clusters used for file system metadata; this
83+
/*
84+
* Return the number of clusters used for file system metadata; this
8485
* represents the overhead needed by the file system.
8586
*/
8687
static unsigned ext4_num_overhead_clusters(struct super_block *sb,
8788
ext4_group_t block_group,
8889
struct ext4_group_desc *gdp)
8990
{
90-
unsigned num_clusters;
91-
int block_cluster = -1, inode_cluster = -1, itbl_cluster = -1, i, c;
91+
unsigned base_clusters, num_clusters;
92+
int block_cluster = -1, inode_cluster;
93+
int itbl_cluster_start = -1, itbl_cluster_end = -1;
9294
ext4_fsblk_t start = ext4_group_first_block_no(sb, block_group);
93-
ext4_fsblk_t itbl_blk;
95+
ext4_fsblk_t end = start + EXT4_BLOCKS_PER_GROUP(sb) - 1;
96+
ext4_fsblk_t itbl_blk_start, itbl_blk_end;
9497
struct ext4_sb_info *sbi = EXT4_SB(sb);
9598

9699
/* This is the number of clusters used by the superblock,
97100
* block group descriptors, and reserved block group
98101
* descriptor blocks */
99-
num_clusters = ext4_num_base_meta_clusters(sb, block_group);
102+
base_clusters = ext4_num_base_meta_clusters(sb, block_group);
103+
num_clusters = base_clusters;
104+
105+
/*
106+
* Account and record inode table clusters if any cluster
107+
* is in the block group, or inode table cluster range is
108+
* [-1, -1] and won't overlap with block/inode bitmap cluster
109+
* accounted below.
110+
*/
111+
itbl_blk_start = ext4_inode_table(sb, gdp);
112+
itbl_blk_end = itbl_blk_start + sbi->s_itb_per_group - 1;
113+
if (itbl_blk_start <= end && itbl_blk_end >= start) {
114+
itbl_blk_start = itbl_blk_start >= start ?
115+
itbl_blk_start : start;
116+
itbl_blk_end = itbl_blk_end <= end ?
117+
itbl_blk_end : end;
118+
119+
itbl_cluster_start = EXT4_B2C(sbi, itbl_blk_start - start);
120+
itbl_cluster_end = EXT4_B2C(sbi, itbl_blk_end - start);
121+
122+
num_clusters += itbl_cluster_end - itbl_cluster_start + 1;
123+
/* check if border cluster is overlapped */
124+
if (itbl_cluster_start == base_clusters - 1)
125+
num_clusters--;
126+
}
100127

101128
/*
102-
* For the allocation bitmaps and inode table, we first need
103-
* to check to see if the block is in the block group. If it
104-
* is, then check to see if the cluster is already accounted
105-
* for in the clusters used for the base metadata cluster, or
106-
* if we can increment the base metadata cluster to include
107-
* that block. Otherwise, we will have to track the cluster
108-
* used for the allocation bitmap or inode table explicitly.
129+
* For the allocation bitmaps, we first need to check to see
130+
* if the block is in the block group. If it is, then check
131+
* to see if the cluster is already accounted for in the clusters
132+
* used for the base metadata cluster and inode tables cluster.
109133
* Normally all of these blocks are contiguous, so the special
110134
* case handling shouldn't be necessary except for *very*
111135
* unusual file system layouts.
112136
*/
113137
if (ext4_block_in_group(sb, ext4_block_bitmap(sb, gdp), block_group)) {
114138
block_cluster = EXT4_B2C(sbi,
115139
ext4_block_bitmap(sb, gdp) - start);
116-
if (block_cluster < num_clusters)
117-
block_cluster = -1;
118-
else if (block_cluster == num_clusters) {
140+
if (block_cluster >= base_clusters &&
141+
(block_cluster < itbl_cluster_start ||
142+
block_cluster > itbl_cluster_end))
119143
num_clusters++;
120-
block_cluster = -1;
121-
}
122144
}
123145

124146
if (ext4_block_in_group(sb, ext4_inode_bitmap(sb, gdp), block_group)) {
125147
inode_cluster = EXT4_B2C(sbi,
126148
ext4_inode_bitmap(sb, gdp) - start);
127-
if (inode_cluster < num_clusters)
128-
inode_cluster = -1;
129-
else if (inode_cluster == num_clusters) {
130-
num_clusters++;
131-
inode_cluster = -1;
132-
}
133-
}
134-
135-
itbl_blk = ext4_inode_table(sb, gdp);
136-
for (i = 0; i < sbi->s_itb_per_group; i++) {
137-
if (ext4_block_in_group(sb, itbl_blk + i, block_group)) {
138-
c = EXT4_B2C(sbi, itbl_blk + i - start);
139-
if ((c < num_clusters) || (c == inode_cluster) ||
140-
(c == block_cluster) || (c == itbl_cluster))
141-
continue;
142-
if (c == num_clusters) {
143-
num_clusters++;
144-
continue;
145-
}
149+
/*
150+
* Additional check if inode bitmap is in just accounted
151+
* block_cluster
152+
*/
153+
if (inode_cluster != block_cluster &&
154+
inode_cluster >= base_clusters &&
155+
(inode_cluster < itbl_cluster_start ||
156+
inode_cluster > itbl_cluster_end))
146157
num_clusters++;
147-
itbl_cluster = c;
148-
}
149158
}
150159

151-
if (block_cluster != -1)
152-
num_clusters++;
153-
if (inode_cluster != -1)
154-
num_clusters++;
155-
156160
return num_clusters;
157161
}
158162

@@ -187,8 +191,6 @@ static int ext4_init_block_bitmap(struct super_block *sb,
187191

188192
ASSERT(buffer_locked(bh));
189193

190-
/* If checksum is bad mark all blocks used to prevent allocation
191-
* essentially implementing a per-group read-only flag. */
192194
if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) {
193195
ext4_mark_group_bitmap_corrupted(sb, block_group,
194196
EXT4_GROUP_INFO_BBITMAP_CORRUPT |
@@ -350,13 +352,13 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb,
350352
blk = ext4_inode_table(sb, desc);
351353
offset = blk - group_first_block;
352354
if (offset < 0 || EXT4_B2C(sbi, offset) >= max_bit ||
353-
EXT4_B2C(sbi, offset + sbi->s_itb_per_group) >= max_bit)
355+
EXT4_B2C(sbi, offset + sbi->s_itb_per_group - 1) >= max_bit)
354356
return blk;
355357
next_zero_bit = ext4_find_next_zero_bit(bh->b_data,
356-
EXT4_B2C(sbi, offset + sbi->s_itb_per_group),
358+
EXT4_B2C(sbi, offset + sbi->s_itb_per_group - 1) + 1,
357359
EXT4_B2C(sbi, offset));
358360
if (next_zero_bit <
359-
EXT4_B2C(sbi, offset + sbi->s_itb_per_group))
361+
EXT4_B2C(sbi, offset + sbi->s_itb_per_group - 1) + 1)
360362
/* bad bitmap for inode tables */
361363
return blk;
362364
return 0;
@@ -383,8 +385,7 @@ static int ext4_validate_block_bitmap(struct super_block *sb,
383385
ext4_lock_group(sb, block_group);
384386
if (buffer_verified(bh))
385387
goto verified;
386-
if (unlikely(!ext4_block_bitmap_csum_verify(sb, block_group,
387-
desc, bh) ||
388+
if (unlikely(!ext4_block_bitmap_csum_verify(sb, desc, bh) ||
388389
ext4_simulate_fail(sb, EXT4_SIM_BBITMAP_CRC))) {
389390
ext4_unlock_group(sb, block_group);
390391
ext4_error(sb, "bg %u: bad block bitmap checksum", block_group);
@@ -474,17 +475,19 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group,
474475
goto out;
475476
}
476477
err = ext4_init_block_bitmap(sb, bh, block_group, desc);
477-
set_bitmap_uptodate(bh);
478-
set_buffer_uptodate(bh);
479-
set_buffer_verified(bh);
480-
ext4_unlock_group(sb, block_group);
481-
unlock_buffer(bh);
482478
if (err) {
479+
ext4_unlock_group(sb, block_group);
480+
unlock_buffer(bh);
483481
ext4_error(sb, "Failed to init block bitmap for group "
484482
"%u: %d", block_group, err);
485483
goto out;
486484
}
487-
goto verify;
485+
set_bitmap_uptodate(bh);
486+
set_buffer_uptodate(bh);
487+
set_buffer_verified(bh);
488+
ext4_unlock_group(sb, block_group);
489+
unlock_buffer(bh);
490+
return bh;
488491
}
489492
ext4_unlock_group(sb, block_group);
490493
if (buffer_uptodate(bh)) {
@@ -842,10 +845,7 @@ static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb,
842845
if (!ext4_bg_has_super(sb, group))
843846
return 0;
844847

845-
if (ext4_has_feature_meta_bg(sb))
846-
return le32_to_cpu(EXT4_SB(sb)->s_es->s_first_meta_bg);
847-
else
848-
return EXT4_SB(sb)->s_gdb_count;
848+
return EXT4_SB(sb)->s_gdb_count;
849849
}
850850

851851
/**
@@ -887,11 +887,11 @@ static unsigned ext4_num_base_meta_clusters(struct super_block *sb,
887887
block_group < le32_to_cpu(sbi->s_es->s_first_meta_bg) *
888888
sbi->s_desc_per_block) {
889889
if (num) {
890-
num += ext4_bg_num_gdb(sb, block_group);
890+
num += ext4_bg_num_gdb_nometa(sb, block_group);
891891
num += le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks);
892892
}
893893
} else { /* For META_BG_BLOCK_GROUPS */
894-
num += ext4_bg_num_gdb(sb, block_group);
894+
num += ext4_bg_num_gdb_meta(sb, block_group);
895895
}
896896
return EXT4_NUM_B2C(sbi, num);
897897
}

fs/ext4/bitmap.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
1616
return numchars * BITS_PER_BYTE - memweight(bitmap, numchars);
1717
}
1818

19-
int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
19+
int ext4_inode_bitmap_csum_verify(struct super_block *sb,
2020
struct ext4_group_desc *gdp,
2121
struct buffer_head *bh, int sz)
2222
{
@@ -38,7 +38,7 @@ int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
3838
return provided == calculated;
3939
}
4040

41-
void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
41+
void ext4_inode_bitmap_csum_set(struct super_block *sb,
4242
struct ext4_group_desc *gdp,
4343
struct buffer_head *bh, int sz)
4444
{
@@ -54,7 +54,7 @@ void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
5454
gdp->bg_inode_bitmap_csum_hi = cpu_to_le16(csum >> 16);
5555
}
5656

57-
int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
57+
int ext4_block_bitmap_csum_verify(struct super_block *sb,
5858
struct ext4_group_desc *gdp,
5959
struct buffer_head *bh)
6060
{
@@ -74,13 +74,10 @@ int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
7474
} else
7575
calculated &= 0xFFFF;
7676

77-
if (provided == calculated)
78-
return 1;
79-
80-
return 0;
77+
return provided == calculated;
8178
}
8279

83-
void ext4_block_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
80+
void ext4_block_bitmap_csum_set(struct super_block *sb,
8481
struct ext4_group_desc *gdp,
8582
struct buffer_head *bh)
8683
{

0 commit comments

Comments
 (0)