Skip to content

Commit c2ea3fd

Browse files
committed
ext4: Remove old legacy block allocator
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 240799c commit c2ea3fd

12 files changed

Lines changed: 40 additions & 1528 deletions

File tree

‎fs/ext4/balloc.c‎

Lines changed: 11 additions & 1344 deletions
Large diffs are not rendered by default.

‎fs/ext4/ext4.h‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ do { \
539539
#define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */
540540
#define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */
541541
#define EXT4_MOUNT_I_VERSION 0x2000000 /* i_version support */
542-
#define EXT4_MOUNT_MBALLOC 0x4000000 /* Buddy allocation support */
543542
#define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */
544543
/* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
545544
#ifndef _LINUX_EXT2_FS_H
@@ -1002,8 +1001,6 @@ extern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
10021001
extern ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
10031002
ext4_lblk_t iblock, ext4_fsblk_t goal,
10041003
unsigned long *count, int *errp);
1005-
extern ext4_fsblk_t ext4_old_new_blocks(handle_t *handle, struct inode *inode,
1006-
ext4_fsblk_t goal, unsigned long *count, int *errp);
10071004
extern int ext4_claim_free_blocks(struct ext4_sb_info *sbi, s64 nblocks);
10081005
extern ext4_fsblk_t ext4_has_free_blocks(struct ext4_sb_info *sbi,
10091006
s64 nblocks);
@@ -1018,8 +1015,6 @@ extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
10181015
ext4_group_t block_group,
10191016
struct buffer_head ** bh);
10201017
extern int ext4_should_retry_alloc(struct super_block *sb, int *retries);
1021-
extern void ext4_init_block_alloc_info(struct inode *);
1022-
extern void ext4_rsv_window_add(struct super_block *sb, struct ext4_reserve_window_node *rsv);
10231018

10241019
/* dir.c */
10251020
extern int ext4_check_dir_entry(const char *, struct inode *,
@@ -1054,7 +1049,7 @@ extern int ext4_mb_release(struct super_block *);
10541049
extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *,
10551050
struct ext4_allocation_request *, int *);
10561051
extern int ext4_mb_reserve_blocks(struct super_block *, int);
1057-
extern void ext4_mb_discard_inode_preallocations(struct inode *);
1052+
extern void ext4_discard_preallocations(struct inode *);
10581053
extern int __init init_ext4_mballoc(void);
10591054
extern void exit_ext4_mballoc(void);
10601055
extern void ext4_mb_free_blocks(handle_t *, struct inode *,
@@ -1084,7 +1079,6 @@ extern int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
10841079
struct kstat *stat);
10851080
extern void ext4_delete_inode(struct inode *);
10861081
extern int ext4_sync_inode(handle_t *, struct inode *);
1087-
extern void ext4_discard_reservation(struct inode *);
10881082
extern void ext4_dirty_inode(struct inode *);
10891083
extern int ext4_change_inode_journal_flag(struct inode *, int);
10901084
extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);

‎fs/ext4/ext4_i.h‎

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,6 @@ typedef __u32 ext4_lblk_t;
3333
/* data type for block group number */
3434
typedef unsigned long ext4_group_t;
3535

36-
struct ext4_reserve_window {
37-
ext4_fsblk_t _rsv_start; /* First byte reserved */
38-
ext4_fsblk_t _rsv_end; /* Last byte reserved or 0 */
39-
};
40-
41-
struct ext4_reserve_window_node {
42-
struct rb_node rsv_node;
43-
__u32 rsv_goal_size;
44-
__u32 rsv_alloc_hit;
45-
struct ext4_reserve_window rsv_window;
46-
};
47-
48-
struct ext4_block_alloc_info {
49-
/* information about reservation window */
50-
struct ext4_reserve_window_node rsv_window_node;
51-
/*
52-
* was i_next_alloc_block in ext4_inode_info
53-
* is the logical (file-relative) number of the
54-
* most-recently-allocated block in this file.
55-
* We use this for detecting linearly ascending allocation requests.
56-
*/
57-
ext4_lblk_t last_alloc_logical_block;
58-
/*
59-
* Was i_next_alloc_goal in ext4_inode_info
60-
* is the *physical* companion to i_next_alloc_block.
61-
* it the physical block number of the block which was most-recentl
62-
* allocated to this file. This give us the goal (target) for the next
63-
* allocation when we detect linearly ascending requests.
64-
*/
65-
ext4_fsblk_t last_alloc_physical_block;
66-
};
67-
6836
#define rsv_start rsv_window._rsv_start
6937
#define rsv_end rsv_window._rsv_end
7038

@@ -97,9 +65,6 @@ struct ext4_inode_info {
9765
ext4_group_t i_block_group;
9866
__u32 i_state; /* Dynamic state flags for ext4 */
9967

100-
/* block reservation info */
101-
struct ext4_block_alloc_info *i_block_alloc_info;
102-
10368
ext4_lblk_t i_dir_start_lookup;
10469
#ifdef CONFIG_EXT4DEV_FS_XATTR
10570
/*

‎fs/ext4/ext4_sb.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ struct ext4_sb_info {
6767
/* root of the per fs reservation window tree */
6868
spinlock_t s_rsv_window_lock;
6969
struct rb_root s_rsv_window_root;
70-
struct ext4_reserve_window_node s_rsv_window_head;
7170

7271
/* Journaling */
7372
struct inode *s_journal_inode;

‎fs/ext4/extents.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,11 +2697,8 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
26972697
goto out2;
26982698
}
26992699
/*
2700-
* Okay, we need to do block allocation. Lazily initialize the block
2701-
* allocation info here if necessary.
2700+
* Okay, we need to do block allocation.
27022701
*/
2703-
if (S_ISREG(inode->i_mode) && (!EXT4_I(inode)->i_block_alloc_info))
2704-
ext4_init_block_alloc_info(inode);
27052702

27062703
/* find neighbour allocated blocks */
27072704
ar.lleft = iblock;
@@ -2761,7 +2758,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
27612758
/* free data blocks we just allocated */
27622759
/* not a good idea to call discard here directly,
27632760
* but otherwise we'd need to call it every free() */
2764-
ext4_mb_discard_inode_preallocations(inode);
2761+
ext4_discard_preallocations(inode);
27652762
ext4_free_blocks(handle, inode, ext_pblock(&newex),
27662763
ext4_ext_get_actual_len(&newex), 0);
27672764
goto out2;
@@ -2825,7 +2822,7 @@ void ext4_ext_truncate(struct inode *inode)
28252822
down_write(&EXT4_I(inode)->i_data_sem);
28262823
ext4_ext_invalidate_cache(inode);
28272824

2828-
ext4_discard_reservation(inode);
2825+
ext4_discard_preallocations(inode);
28292826

28302827
/*
28312828
* TODO: optimization is possible here.

‎fs/ext4/file.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int ext4_release_file(struct inode *inode, struct file *filp)
3838
(atomic_read(&inode->i_writecount) == 1))
3939
{
4040
down_write(&EXT4_I(inode)->i_data_sem);
41-
ext4_discard_reservation(inode);
41+
ext4_discard_preallocations(inode);
4242
up_write(&EXT4_I(inode)->i_data_sem);
4343
}
4444
if (is_dx(inode) && filp->private_data)

‎fs/ext4/ialloc.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,6 @@ struct inode *ext4_new_inode(handle_t *handle, struct inode *dir, int mode)
817817
ei->i_flags &= ~EXT4_DIRSYNC_FL;
818818
ei->i_file_acl = 0;
819819
ei->i_dtime = 0;
820-
ei->i_block_alloc_info = NULL;
821820
ei->i_block_group = group;
822821

823822
ext4_set_inode_flags(inode);

‎fs/ext4/inode.c‎

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -486,18 +486,9 @@ static ext4_fsblk_t ext4_find_near(struct inode *inode, Indirect *ind)
486486
static ext4_fsblk_t ext4_find_goal(struct inode *inode, ext4_lblk_t block,
487487
Indirect *partial)
488488
{
489-
struct ext4_block_alloc_info *block_i;
490-
491-
block_i = EXT4_I(inode)->i_block_alloc_info;
492-
493489
/*
494-
* try the heuristic for sequential allocation,
495-
* failing that at least try to get decent locality.
490+
* XXX need to get goal block from mballoc's data structures
496491
*/
497-
if (block_i && (block == block_i->last_alloc_logical_block + 1)
498-
&& (block_i->last_alloc_physical_block != 0)) {
499-
return block_i->last_alloc_physical_block + 1;
500-
}
501492

502493
return ext4_find_near(inode, partial);
503494
}
@@ -757,10 +748,8 @@ static int ext4_splice_branch(handle_t *handle, struct inode *inode,
757748
{
758749
int i;
759750
int err = 0;
760-
struct ext4_block_alloc_info *block_i;
761751
ext4_fsblk_t current_block;
762752

763-
block_i = EXT4_I(inode)->i_block_alloc_info;
764753
/*
765754
* If we're splicing into a [td]indirect block (as opposed to the
766755
* inode) then we need to get write access to the [td]indirect block
@@ -786,17 +775,6 @@ static int ext4_splice_branch(handle_t *handle, struct inode *inode,
786775
*(where->p + i) = cpu_to_le32(current_block++);
787776
}
788777

789-
/*
790-
* update the most recently allocated logical & physical block
791-
* in i_block_alloc_info, to assist find the proper goal block for next
792-
* allocation
793-
*/
794-
if (block_i) {
795-
block_i->last_alloc_logical_block = block + blks - 1;
796-
block_i->last_alloc_physical_block =
797-
le32_to_cpu(where[num].key) + blks - 1;
798-
}
799-
800778
/* We are done with atomic stuff, now do the rest of housekeeping */
801779

802780
inode->i_ctime = ext4_current_time(inode);
@@ -914,12 +892,8 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
914892
goto cleanup;
915893

916894
/*
917-
* Okay, we need to do block allocation. Lazily initialize the block
918-
* allocation info here if necessary
895+
* Okay, we need to do block allocation.
919896
*/
920-
if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info))
921-
ext4_init_block_alloc_info(inode);
922-
923897
goal = ext4_find_goal(inode, iblock, partial);
924898

925899
/* the number of blocks need to allocate for [d,t]indirect blocks */
@@ -3738,7 +3712,7 @@ void ext4_truncate(struct inode *inode)
37383712
*/
37393713
down_write(&ei->i_data_sem);
37403714

3741-
ext4_discard_reservation(inode);
3715+
ext4_discard_preallocations(inode);
37423716

37433717
/*
37443718
* The orphan list entry will now protect us from any crash which
@@ -4071,7 +4045,6 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
40714045
ei->i_acl = EXT4_ACL_NOT_CACHED;
40724046
ei->i_default_acl = EXT4_ACL_NOT_CACHED;
40734047
#endif
4074-
ei->i_block_alloc_info = NULL;
40754048

40764049
ret = __ext4_get_inode_loc(inode, &iloc, 0);
40774050
if (ret < 0)

‎fs/ext4/ioctl.c‎

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2323
struct inode *inode = filp->f_dentry->d_inode;
2424
struct ext4_inode_info *ei = EXT4_I(inode);
2525
unsigned int flags;
26-
unsigned short rsv_window_size;
2726

2827
ext4_debug("cmd = %u, arg = %lu\n", cmd, arg);
2928

@@ -190,49 +189,6 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
190189
return ret;
191190
}
192191
#endif
193-
case EXT4_IOC_GETRSVSZ:
194-
if (test_opt(inode->i_sb, RESERVATION)
195-
&& S_ISREG(inode->i_mode)
196-
&& ei->i_block_alloc_info) {
197-
rsv_window_size = ei->i_block_alloc_info->rsv_window_node.rsv_goal_size;
198-
return put_user(rsv_window_size, (int __user *)arg);
199-
}
200-
return -ENOTTY;
201-
case EXT4_IOC_SETRSVSZ: {
202-
int err;
203-
204-
if (!test_opt(inode->i_sb, RESERVATION) || !S_ISREG(inode->i_mode))
205-
return -ENOTTY;
206-
207-
if (!is_owner_or_cap(inode))
208-
return -EACCES;
209-
210-
if (get_user(rsv_window_size, (int __user *)arg))
211-
return -EFAULT;
212-
213-
err = mnt_want_write(filp->f_path.mnt);
214-
if (err)
215-
return err;
216-
217-
if (rsv_window_size > EXT4_MAX_RESERVE_BLOCKS)
218-
rsv_window_size = EXT4_MAX_RESERVE_BLOCKS;
219-
220-
/*
221-
* need to allocate reservation structure for this inode
222-
* before set the window size
223-
*/
224-
down_write(&ei->i_data_sem);
225-
if (!ei->i_block_alloc_info)
226-
ext4_init_block_alloc_info(inode);
227-
228-
if (ei->i_block_alloc_info){
229-
struct ext4_reserve_window_node *rsv = &ei->i_block_alloc_info->rsv_window_node;
230-
rsv->rsv_goal_size = rsv_window_size;
231-
}
232-
up_write(&ei->i_data_sem);
233-
mnt_drop_write(filp->f_path.mnt);
234-
return 0;
235-
}
236192
case EXT4_IOC_GROUP_EXTEND: {
237193
ext4_fsblk_t n_blocks_count;
238194
struct super_block *sb = inode->i_sb;

‎fs/ext4/mballoc.c‎

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,6 @@ static int __mb_check_buddy(struct ext4_buddy *e4b, char *file,
534534
void *buddy;
535535
void *buddy2;
536536

537-
if (!test_opt(sb, MBALLOC))
538-
return 0;
539-
540537
{
541538
static int mb_check_counter;
542539
if (mb_check_counter++ % 100 != 0)
@@ -2487,19 +2484,14 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery)
24872484
unsigned max;
24882485
int ret;
24892486

2490-
if (!test_opt(sb, MBALLOC))
2491-
return 0;
2492-
24932487
i = (sb->s_blocksize_bits + 2) * sizeof(unsigned short);
24942488

24952489
sbi->s_mb_offsets = kmalloc(i, GFP_KERNEL);
24962490
if (sbi->s_mb_offsets == NULL) {
2497-
clear_opt(sbi->s_mount_opt, MBALLOC);
24982491
return -ENOMEM;
24992492
}
25002493
sbi->s_mb_maxs = kmalloc(i, GFP_KERNEL);
25012494
if (sbi->s_mb_maxs == NULL) {
2502-
clear_opt(sbi->s_mount_opt, MBALLOC);
25032495
kfree(sbi->s_mb_maxs);
25042496
return -ENOMEM;
25052497
}
@@ -2522,7 +2514,6 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery)
25222514
/* init file for buddy data */
25232515
ret = ext4_mb_init_backend(sb);
25242516
if (ret != 0) {
2525-
clear_opt(sbi->s_mount_opt, MBALLOC);
25262517
kfree(sbi->s_mb_offsets);
25272518
kfree(sbi->s_mb_maxs);
25282519
return ret;
@@ -2544,7 +2535,6 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery)
25442535

25452536
sbi->s_locality_groups = alloc_percpu(struct ext4_locality_group);
25462537
if (sbi->s_locality_groups == NULL) {
2547-
clear_opt(sbi->s_mount_opt, MBALLOC);
25482538
kfree(sbi->s_mb_offsets);
25492539
kfree(sbi->s_mb_maxs);
25502540
return -ENOMEM;
@@ -2590,9 +2580,6 @@ int ext4_mb_release(struct super_block *sb)
25902580
struct ext4_group_info *grinfo;
25912581
struct ext4_sb_info *sbi = EXT4_SB(sb);
25922582

2593-
if (!test_opt(sb, MBALLOC))
2594-
return 0;
2595-
25962583
/* release freed, non-committed blocks */
25972584
spin_lock(&sbi->s_md_lock);
25982585
list_splice_init(&sbi->s_closed_transaction,
@@ -3805,7 +3792,7 @@ ext4_mb_discard_group_preallocations(struct super_block *sb,
38053792
*
38063793
* FIXME!! Make sure it is valid at all the call sites
38073794
*/
3808-
void ext4_mb_discard_inode_preallocations(struct inode *inode)
3795+
void ext4_discard_preallocations(struct inode *inode)
38093796
{
38103797
struct ext4_inode_info *ei = EXT4_I(inode);
38113798
struct super_block *sb = inode->i_sb;
@@ -3817,7 +3804,7 @@ void ext4_mb_discard_inode_preallocations(struct inode *inode)
38173804
struct ext4_buddy e4b;
38183805
int err;
38193806

3820-
if (!test_opt(sb, MBALLOC) || !S_ISREG(inode->i_mode)) {
3807+
if (!S_ISREG(inode->i_mode)) {
38213808
/*BUG_ON(!list_empty(&ei->i_prealloc_list));*/
38223809
return;
38233810
}
@@ -4300,11 +4287,6 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
43004287
sb = ar->inode->i_sb;
43014288
sbi = EXT4_SB(sb);
43024289

4303-
if (!test_opt(sb, MBALLOC)) {
4304-
block = ext4_old_new_blocks(handle, ar->inode, ar->goal,
4305-
&(ar->len), errp);
4306-
return block;
4307-
}
43084290
if (!EXT4_I(ar->inode)->i_delalloc_reserved_flag) {
43094291
/*
43104292
* With delalloc we already reserved the blocks

0 commit comments

Comments
 (0)