| Submitter | Robin Dong |
|---|---|
| Date | March 13, 2012, 11:38 a.m. |
| Message ID | <1331638698-14796-1-git-send-email-hao.bigrat@gmail.com> |
| Download | mbox | patch |
| Permalink | /patch/146388/ |
| State | New |
| Headers | show |
Comments
On Tue, Mar 13, 2012 at 07:38:16PM +0800, Robin Dong wrote: > Creating 4-byte files until ENOSPC in a delay-allocation and bigalloc ext4 fs and then sync it, the dmseg will report like: > > [ 482.154538] EXT4-fs (sdb6): delayed block allocation failed for inode 1664 at logical offset 0 with max blocks 1 with error -28 > [ 482.154540] EXT4-fs (sdb6): This should not happen!! Data will be lost > > The reason is ext4_has_free_clusters reporting wrong > result. Actually, the unit of sbi->s_dirtyclusters_counter is block, > so we should tranform it to cluster for argument "dirty_clusters", > just like "free_clusters". We have a bigger problem here, which is that this is not the only place where s_dirty_clusters_counter is being used in units of clusters. (See ext4_claim_free_clusters, which when called by mballoc is using units of clusters.) We definitely have brokeness here, but this is not the whole story. We need to take a step back here and decide whether the correct units is clusters or blocks. Ultimately I think it does need to be clusters, because we can't just convert blocks and clusters by using B2C; we could dirty 3 blocks, but if those 3 blocks span two 64-block clusters, what's important is that we have to reserve space for 2 clusters. We can't just calculate "3 >> 6" and assume that we can reserve 0 clusters and be done with it! This is one of the places where I think we need to solve things by having a better data structure for tracking which pages have been subject to delayed allocation, since if we touch another block in a cluster where we've done a delayed allocation, we don't need to bump s_dirtyclusters_counter. However, if this is the first time we've touched a block in a particular cluster, then we *do* need to bump s_dirtyclusters_counter --- and if we need to search all of the pages in the page cache to make this determination, it's going to be painful.... - Ted -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
在 2012年3月25日 上午5:05,Ted Ts'o <tytso@mit.edu> 写道: > On Tue, Mar 13, 2012 at 07:38:16PM +0800, Robin Dong wrote: >> Creating 4-byte files until ENOSPC in a delay-allocation and bigalloc ext4 fs and then sync it, the dmseg will report like: >> >> [ 482.154538] EXT4-fs (sdb6): delayed block allocation failed for inode 1664 at logical offset 0 with max blocks 1 with error -28 >> [ 482.154540] EXT4-fs (sdb6): This should not happen!! Data will be lost >> >> The reason is ext4_has_free_clusters reporting wrong >> result. Actually, the unit of sbi->s_dirtyclusters_counter is block, >> so we should tranform it to cluster for argument "dirty_clusters", >> just like "free_clusters". > > We have a bigger problem here, which is that this is not the only > place where s_dirty_clusters_counter is being used in units of > clusters. (See ext4_claim_free_clusters, which when called by mballoc > is using units of clusters.) > > We definitely have brokeness here, but this is not the whole story. > We need to take a step back here and decide whether the correct units > is clusters or blocks. Ultimately I think it does need to be > clusters, because we can't just convert blocks and clusters by using > B2C; we could dirty 3 blocks, but if those 3 blocks span two 64-block > clusters, what's important is that we have to reserve space for 2 > clusters. We can't just calculate "3 >> 6" and assume that we can > reserve 0 clusters and be done with it! Hi, Ted Actually, I have complete this logic in my "[PATCH 2/3] ext4: modify the implementation of quota reservation in bigalloc-delay-allocation" (http://marc.info/?l=linux-ext4&m=133163876628132&w=2) patch, when those 3 blocks span two clusters, the logic in ext4_ext_map_blocks() will check whether a block is already in a delay-allocated-cluster (or already be allocated in disk) and ultimately reserved 2 clusters for the 3 blocks. Imaging block0 and block1 in cluster0, block2 in cluster1. When ext4_da_map_blocks() process block0, we will call ext4_da_reserve_space() (which will reserve a cluster) and bump s_dirtycluster_counter , but when process block1, ext4_ext_map_blocks will return flag with EXT4_MAP_FROM_CLUSTER and we will not bump s_dirtycluster_counter this time since block1 is belong to a already reserved cluster. Maybe I misunderstanding your meaning, could you please point out my fault? Thanks. > > This is one of the places where I think we need to solve things by > having a better data structure for tracking which pages have been > subject to delayed allocation, since if we touch another block in a > cluster where we've done a delayed allocation, we don't need to bump > s_dirtyclusters_counter. However, if this is the first time we've > touched a block in a particular cluster, then we *do* need to bump > s_dirtyclusters_counter --- and if we need to search all of the pages > in the page cache to make this determination, it's going to be > painful.... > > - Ted
Patch
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c index f9e2cd8..2c518f8 100644 --- a/fs/ext4/balloc.c +++ b/fs/ext4/balloc.c @@ -426,7 +426,7 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi, if (free_clusters - (nclusters + root_clusters + dirty_clusters) < EXT4_FREECLUSTERS_WATERMARK) { - free_clusters = EXT4_C2B(sbi, percpu_counter_sum_positive(fcc)); + free_clusters = percpu_counter_sum_positive(fcc); dirty_clusters = percpu_counter_sum_positive(dcc); } /* Check whether we have space after accounting for current
Creating 4-byte files until ENOSPC in a delay-allocation and bigalloc ext4 fs and then sync it, the dmseg will report like: [ 482.154538] EXT4-fs (sdb6): delayed block allocation failed for inode 1664 at logical offset 0 with max blocks 1 with error -28 [ 482.154540] EXT4-fs (sdb6): This should not happen!! Data will be lost The reason is ext4_has_free_clusters reporting wrong result. Actually, the unit of sbi->s_dirtyclusters_counter is block, so we should tranform it to cluster for argument "dirty_clusters", just like "free_clusters". Reported-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Robin Dong <sanbai@taobao.com> --- fs/ext4/balloc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)