Skip to content

Commit 89747d3

Browse files
Mingming CaoLinus Torvalds
authored andcommitted
[PATCH] ext3_get_blocks: Mapping multiple blocks at a once
Currently ext3_get_block() only maps or allocates one block at a time. This is quite inefficient for sequential IO workload. I have posted a early implements a simply multiple block map and allocation with current ext3. The basic idea is allocating the 1st block in the existing way, and attempting to allocate the next adjacent blocks on a best effort basis. More description about the implementation could be found here: http://marc.theaimsgroup.com/?l=ext2-devel&m=112162230003522&w=2 The following the latest version of the patch: break the original patch into 5 patches, re-worked some logicals, and fixed some bugs. The break ups are: [patch 1] Adding map multiple blocks at a time in ext3_get_blocks() [patch 2] Extend ext3_get_blocks() to support multiple block allocation [patch 3] Implement multiple block allocation in ext3-try-to-allocate (called via ext3_new_block()). [patch 4] Proper accounting updates in ext3_new_blocks() [patch 5] Adjust reservation window size properly (by the given number of blocks to allocate) before block allocation to increase the possibility of allocating multiple blocks in a single call. Tests done so far includes fsx,tiobench and dbench. The following numbers collected from Direct IO tests (1G file creation/read) shows the system time have been greatly reduced (more than 50% on my 8 cpu system) with the patches. 1G file DIO write: 2.6.15 2.6.15+patches real 0m31.275s 0m31.161s user 0m0.000s 0m0.000s sys 0m3.384s 0m0.564s 1G file DIO read: 2.6.15 2.6.15+patches real 0m30.733s 0m30.624s user 0m0.000s 0m0.004s sys 0m0.748s 0m0.380s Some previous test we did on buffered IO with using multiple blocks allocation and delayed allocation shows noticeable improvement on throughput and system time. This patch: Add support of mapping multiple blocks in one call. This is useful for DIO reads and re-writes (where blocks are already allocated), also is in line with Christoph's proposal of using getblocks() in mpage_readpage() or mpage_readpages(). Signed-off-by: Mingming Cao <cmm@us.ibm.com> Cc: Badari Pulavarty <pbadari@us.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent e2d53f9 commit 89747d3

3 files changed

Lines changed: 82 additions & 34 deletions

File tree

‎fs/ext3/dir.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ static int ext3_readdir(struct file * filp,
131131
struct buffer_head *bh = NULL;
132132

133133
map_bh.b_state = 0;
134-
err = ext3_get_block_handle(NULL, inode, blk, &map_bh, 0, 0);
135-
if (!err) {
134+
err = ext3_get_blocks_handle(NULL, inode, blk, 1,
135+
&map_bh, 0, 0);
136+
if (err > 0) {
136137
page_cache_readahead(sb->s_bdev->bd_inode->i_mapping,
137138
&filp->f_ra,
138139
filp,

‎fs/ext3/inode.c‎

Lines changed: 76 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static int ext3_block_to_path(struct inode *inode,
330330
ext3_warning (inode->i_sb, "ext3_block_to_path", "block > big");
331331
}
332332
if (boundary)
333-
*boundary = (i_block & (ptrs - 1)) == (final - 1);
333+
*boundary = final - 1 - (i_block & (ptrs - 1));
334334
return n;
335335
}
336336

@@ -669,23 +669,31 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode, long block,
669669
* akpm: `handle' can be NULL if create == 0.
670670
*
671671
* The BKL may not be held on entry here. Be sure to take it early.
672+
* return > 0, # of blocks mapped or allocated.
673+
* return = 0, if plain lookup failed.
674+
* return < 0, error case.
672675
*/
673676

674677
int
675-
ext3_get_block_handle(handle_t *handle, struct inode *inode, sector_t iblock,
676-
struct buffer_head *bh_result, int create, int extend_disksize)
678+
ext3_get_blocks_handle(handle_t *handle, struct inode *inode, sector_t iblock,
679+
unsigned long maxblocks, struct buffer_head *bh_result,
680+
int create, int extend_disksize)
677681
{
678682
int err = -EIO;
679683
int offsets[4];
680684
Indirect chain[4];
681685
Indirect *partial;
682686
unsigned long goal;
683687
int left;
684-
int boundary = 0;
685-
const int depth = ext3_block_to_path(inode, iblock, offsets, &boundary);
688+
int blocks_to_boundary = 0;
689+
int depth;
686690
struct ext3_inode_info *ei = EXT3_I(inode);
691+
int count = 0;
692+
unsigned long first_block = 0;
693+
687694

688695
J_ASSERT(handle != NULL || create == 0);
696+
depth = ext3_block_to_path(inode, iblock, offsets, &blocks_to_boundary);
689697

690698
if (depth == 0)
691699
goto out;
@@ -694,8 +702,31 @@ ext3_get_block_handle(handle_t *handle, struct inode *inode, sector_t iblock,
694702

695703
/* Simplest case - block found, no allocation needed */
696704
if (!partial) {
705+
first_block = chain[depth - 1].key;
697706
clear_buffer_new(bh_result);
698-
goto got_it;
707+
count++;
708+
/*map more blocks*/
709+
while (count < maxblocks && count <= blocks_to_boundary) {
710+
if (!verify_chain(chain, partial)) {
711+
/*
712+
* Indirect block might be removed by
713+
* truncate while we were reading it.
714+
* Handling of that case: forget what we've
715+
* got now. Flag the err as EAGAIN, so it
716+
* will reread.
717+
*/
718+
err = -EAGAIN;
719+
count = 0;
720+
break;
721+
}
722+
if (le32_to_cpu(*(chain[depth-1].p+count) ==
723+
(first_block + count)))
724+
count++;
725+
else
726+
break;
727+
}
728+
if (err != -EAGAIN)
729+
goto got_it;
699730
}
700731

701732
/* Next simple case - plain lookup or failed read of indirect block */
@@ -723,6 +754,7 @@ ext3_get_block_handle(handle_t *handle, struct inode *inode, sector_t iblock,
723754
}
724755
partial = ext3_get_branch(inode, depth, offsets, chain, &err);
725756
if (!partial) {
757+
count++;
726758
mutex_unlock(&ei->truncate_mutex);
727759
if (err)
728760
goto cleanup;
@@ -772,8 +804,9 @@ ext3_get_block_handle(handle_t *handle, struct inode *inode, sector_t iblock,
772804
set_buffer_new(bh_result);
773805
got_it:
774806
map_bh(bh_result, inode->i_sb, le32_to_cpu(chain[depth-1].key));
775-
if (boundary)
807+
if (blocks_to_boundary == 0)
776808
set_buffer_boundary(bh_result);
809+
err = count;
777810
/* Clean up and exit */
778811
partial = chain + depth - 1; /* the whole chain */
779812
cleanup:
@@ -787,21 +820,6 @@ ext3_get_block_handle(handle_t *handle, struct inode *inode, sector_t iblock,
787820
return err;
788821
}
789822

790-
static int ext3_get_block(struct inode *inode, sector_t iblock,
791-
struct buffer_head *bh_result, int create)
792-
{
793-
handle_t *handle = NULL;
794-
int ret;
795-
796-
if (create) {
797-
handle = ext3_journal_current_handle();
798-
J_ASSERT(handle != 0);
799-
}
800-
ret = ext3_get_block_handle(handle, inode, iblock,
801-
bh_result, create, 1);
802-
return ret;
803-
}
804-
805823
#define DIO_CREDITS (EXT3_RESERVE_TRANS_BLOCKS + 32)
806824

807825
static int
@@ -812,9 +830,12 @@ ext3_direct_io_get_blocks(struct inode *inode, sector_t iblock,
812830
handle_t *handle = journal_current_handle();
813831
int ret = 0;
814832

815-
if (!handle)
833+
if (!create)
816834
goto get_block; /* A read */
817835

836+
if (max_blocks == 1)
837+
goto get_block; /* A single block get */
838+
818839
if (handle->h_transaction->t_state == T_LOCKED) {
819840
/*
820841
* Huge direct-io writes can hold off commits for long
@@ -841,13 +862,31 @@ ext3_direct_io_get_blocks(struct inode *inode, sector_t iblock,
841862
}
842863

843864
get_block:
844-
if (ret == 0)
845-
ret = ext3_get_block_handle(handle, inode, iblock,
846-
bh_result, create, 0);
847-
bh_result->b_size = (1 << inode->i_blkbits);
865+
if (ret == 0) {
866+
ret = ext3_get_blocks_handle(handle, inode, iblock,
867+
max_blocks, bh_result, create, 0);
868+
if (ret > 0) {
869+
bh_result->b_size = (ret << inode->i_blkbits);
870+
ret = 0;
871+
}
872+
}
848873
return ret;
849874
}
850875

876+
static int ext3_get_blocks(struct inode *inode, sector_t iblock,
877+
unsigned long maxblocks, struct buffer_head *bh_result,
878+
int create)
879+
{
880+
return ext3_direct_io_get_blocks(inode, iblock, maxblocks,
881+
bh_result, create);
882+
}
883+
884+
static int ext3_get_block(struct inode *inode, sector_t iblock,
885+
struct buffer_head *bh_result, int create)
886+
{
887+
return ext3_get_blocks(inode, iblock, 1, bh_result, create);
888+
}
889+
851890
/*
852891
* `handle' can be NULL if create is zero
853892
*/
@@ -862,8 +901,16 @@ struct buffer_head *ext3_getblk(handle_t *handle, struct inode * inode,
862901
dummy.b_state = 0;
863902
dummy.b_blocknr = -1000;
864903
buffer_trace_init(&dummy.b_history);
865-
*errp = ext3_get_block_handle(handle, inode, block, &dummy, create, 1);
866-
if (!*errp && buffer_mapped(&dummy)) {
904+
err = ext3_get_blocks_handle(handle, inode, block, 1,
905+
&dummy, create, 1);
906+
if (err == 1) {
907+
err = 0;
908+
} else if (err >= 0) {
909+
WARN_ON(1);
910+
err = -EIO;
911+
}
912+
*errp = err;
913+
if (!err && buffer_mapped(&dummy)) {
867914
struct buffer_head *bh;
868915
bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
869916
if (!bh) {

‎include/linux/ext3_fs.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,9 @@ extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
775775
int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
776776
struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
777777
struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
778-
int ext3_get_block_handle(handle_t *handle, struct inode *inode,
779-
sector_t iblock, struct buffer_head *bh_result, int create,
780-
int extend_disksize);
778+
int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
779+
sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
780+
int create, int extend_disksize);
781781

782782
extern void ext3_read_inode (struct inode *);
783783
extern int ext3_write_inode (struct inode *, int);

0 commit comments

Comments
 (0)