From b6e2dad42b74532e3ad5c20e5cc44a4969925226 Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Thu, 15 Jul 2021 16:15:37 +0800 Subject: [PATCH] LU-14729 osd-ldiskfs: declare should consider concurrency Write in Lustre OSD is different than Ext4 since write is serialized in local filesystem, however in OSD side, many concurrent threads may grow tree before transaction starts. Also fix to use @dirty_groups rather than @extents, remove unnecessary @depth assignment. Lustre-change: https://review.whamcloud.com/44316 Lustre-commit: 934758366dbde211743d53b8c048c57819603cb3 Fixes: 9810341a8 ("LU-14729 osd-ldiskfs: fix to declare write commits") Signed-off-by: Wang Shilong Change-Id: I1e0fc9069a579736a74b0ba2607056fe980574c3 Reviewed-by: Li Dongyang Reviewed-by: Andreas Dilger Reviewed-on: https://review.whamcloud.com/45077 Tested-by: jenkins Tested-by: Andreas Dilger --- lustre/osd-ldiskfs/osd_io.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lustre/osd-ldiskfs/osd_io.c b/lustre/osd-ldiskfs/osd_io.c index 5e1e635..0c17451 100644 --- a/lustre/osd-ldiskfs/osd_io.c +++ b/lustre/osd-ldiskfs/osd_io.c @@ -1480,7 +1480,12 @@ static int osd_declare_write_commit(const struct lu_env *env, * split more than once, but this is really rare. */ if (LDISKFS_I(inode)->i_flags & LDISKFS_EXTENTS_FL) { + /* + * many concurrent threads may grow tree by the time + * our transaction starts. so, consider 2 is a min depth. + */ depth = ext_depth(inode); + depth = min(max(depth, 1) + 1, LDISKFS_MAX_EXTENT_DEPTH); if (extents <= 1) { credits += depth * 2 * extents; new_meta = depth; @@ -1497,7 +1502,6 @@ static int osd_declare_write_commit(const struct lu_env *env, new_meta = DIV_ROUND_UP(new_blocks, LDISKFS_ADDR_PER_BLOCK(inode->i_sb)) + 4; credits += new_meta; - depth = 3; } dirty_groups += (extents + new_meta); @@ -1518,7 +1522,7 @@ static int osd_declare_write_commit(const struct lu_env *env, credits += dirty_groups; /* we can't dirty more gd blocks than exist */ - if (extents > LDISKFS_SB(osd_sb(osd))->s_gdb_count) + if (dirty_groups > LDISKFS_SB(osd_sb(osd))->s_gdb_count) credits += LDISKFS_SB(osd_sb(osd))->s_gdb_count; else credits += dirty_groups; @@ -1957,7 +1961,7 @@ static ssize_t osd_declare_write(const struct lu_env *env, struct dt_object *dt, * level. */ depth = inode != NULL ? ext_depth(inode) : 0; - depth = max(depth, 1) + 1; + depth = min(max(depth, 1) + 1, LDISKFS_MAX_EXTENT_DEPTH); credits = depth; /* if not append, then split may need to modify * existing blocks moving entries into the new ones -- 1.8.3.1