aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/balloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/balloc.c')
-rw-r--r--fs/ext4/balloc.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 264f6949511..f8224adf496 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -620,3 +620,51 @@ unsigned long ext4_bg_num_gdb(struct super_block *sb, ext4_group_t group)
620 620
621} 621}
622 622
623/**
624 * ext4_inode_to_goal_block - return a hint for block allocation
625 * @inode: inode for block allocation
626 *
627 * Return the ideal location to start allocating blocks for a
628 * newly created inode.
629 */
630ext4_fsblk_t ext4_inode_to_goal_block(struct inode *inode)
631{
632 struct ext4_inode_info *ei = EXT4_I(inode);
633 ext4_group_t block_group;
634 ext4_grpblk_t colour;
635 int flex_size = ext4_flex_bg_size(EXT4_SB(inode->i_sb));
636 ext4_fsblk_t bg_start;
637 ext4_fsblk_t last_block;
638
639 block_group = ei->i_block_group;
640 if (flex_size >= EXT4_FLEX_SIZE_DIR_ALLOC_SCHEME) {
641 /*
642 * If there are at least EXT4_FLEX_SIZE_DIR_ALLOC_SCHEME
643 * block groups per flexgroup, reserve the first block
644 * group for directories and special files. Regular
645 * files will start at the second block group. This
646 * tends to speed up directory access and improves
647 * fsck times.
648 */
649 block_group &= ~(flex_size-1);
650 if (S_ISREG(inode->i_mode))
651 block_group++;
652 }
653 bg_start = ext4_group_first_block_no(inode->i_sb, block_group);
654 last_block = ext4_blocks_count(EXT4_SB(inode->i_sb)->s_es) - 1;
655
656 /*
657 * If we are doing delayed allocation, we don't need take
658 * colour into account.
659 */
660 if (test_opt(inode->i_sb, DELALLOC))
661 return bg_start;
662
663 if (bg_start + EXT4_BLOCKS_PER_GROUP(inode->i_sb) <= last_block)
664 colour = (current->pid % 16) *
665 (EXT4_BLOCKS_PER_GROUP(inode->i_sb) / 16);
666 else
667 colour = (current->pid % 16) * ((last_block - bg_start) / 16);
668 return bg_start + colour;
669}
670