From 503b7bd995ae8254610b720db170525a12c4df9c Mon Sep 17 00:00:00 2001 From: Xiubo Li Date: Tue, 1 Dec 2020 12:28:37 +0800 Subject: [PATCH] mds/CDir: make the data length as long as possible for each op The max_write_size is 10M as default, and every time when the len of the op data exceed it with a very small size it will be split into two ops, one of which will always be very small. Signed-off-by: Xiubo Li --- src/mds/CDir.cc | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/mds/CDir.cc b/src/mds/CDir.cc index c28a3d638d201..a68f5cd54176f 100644 --- a/src/mds/CDir.cc +++ b/src/mds/CDir.cc @@ -2249,21 +2249,23 @@ void CDir::_omap_commit_ops(int r, int op_prio, version_t version, bool _new, bu }; for (auto &key : stales) { - write_size += key.length() + sizeof(__u32); - _rm.emplace(key); - - if (write_size >= max_write_size) + unsigned size = key.length() + sizeof(__u32); + if (write_size + size > max_write_size) commit_one(); + + write_size += size; + _rm.emplace(key); } for (auto &k : to_remove) { string key; k.encode(key); - write_size += key.length() + sizeof(__u32); - _rm.emplace(std::move(key)); - - if (write_size >= max_write_size) + unsigned size = key.length() + sizeof(__u32); + if (write_size + size > max_write_size) commit_one(); + + write_size += size; + _rm.emplace(std::move(key)); } uint64_t off = 0; @@ -2312,10 +2314,12 @@ void CDir::_omap_commit_ops(int r, int op_prio, version_t version, bool _new, bu } off += item.dft_len; - write_size += key.length() + bl.length() + 2 * sizeof(__u32); - _set[std::move(key)].swap(bl); - if (write_size >= max_write_size) + unsigned size = key.length() + bl.length() + 2 * sizeof(__u32); + if (write_size + size > max_write_size) commit_one(); + + write_size += size; + _set[std::move(key)].swap(bl); } commit_one(true); -- 2.39.5