From 4ebdd59cfe46334d8c64c40756d27cbb127f152b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 10 Oct 2024 13:33:17 +0200 Subject: [PATCH] mds: combine several fixed-size `encode()` calls The `denc` library allows appending multiple values in a single `buffer::list` call by wrapping them in a `std::tuple`. This reduces overhead because the buffer bounds checks have to be performed only once. This patch optimizes several types that turned up in the profiler. Signed-off-by: Max Kellermann --- src/mds/Anchor.cc | 7 ++++-- src/mds/CInode.cc | 51 +++++++++++++++++++++++------------------- src/mds/journal.cc | 55 ++++++++++++++++++++++++++++------------------ 3 files changed, 67 insertions(+), 46 deletions(-) diff --git a/src/mds/Anchor.cc b/src/mds/Anchor.cc index 81d55e6b115f..c9033f7331ab 100644 --- a/src/mds/Anchor.cc +++ b/src/mds/Anchor.cc @@ -15,12 +15,15 @@ #include "mds/Anchor.h" #include "common/Formatter.h" +#include "include/denc.h" void Anchor::encode(bufferlist &bl) const { ENCODE_START(2, 1, bl); - encode(ino, bl); - encode(dirino, bl); + encode(std::tuple{ + ino, + dirino, + }, bl, 0); encode(d_name, bl); encode(d_type, bl); encode(frags, bl); diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index dfad411d323d..feeef0a60d1b 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -40,6 +40,7 @@ #include "common/config.h" #include "global/global_context.h" +#include "include/denc.h" #include "include/ceph_assert.h" #include "mds/MDSContinuation.h" @@ -4110,35 +4111,39 @@ int CInode::encode_inodestat(bufferlist& bl, Session *session, */ if (session->info.has_feature(CEPHFS_FEATURE_REPLY_ENCODING)) { ENCODE_START(7, 1, bl); - encode(oi->ino, bl); - encode(snapid, bl); - encode(oi->rdev, bl); - encode(version, bl); - encode(xattr_version, bl); + encode(std::tuple{ + oi->ino, + snapid, + oi->rdev, + version, + xattr_version, + }, bl, 0); encode(ecap, bl); { ceph_file_layout legacy_layout; layout.to_legacy(&legacy_layout); encode(legacy_layout, bl); } - encode(any_i->ctime, bl); - encode(file_i->mtime, bl); - encode(file_i->atime, bl); - encode(file_i->time_warp_seq, bl); - encode(file_i->size, bl); - encode(max_size, bl); - encode(file_i->truncate_size, bl); - encode(file_i->truncate_seq, bl); - encode(auth_i->mode, bl); - encode((uint32_t)auth_i->uid, bl); - encode((uint32_t)auth_i->gid, bl); - encode(link_i->nlink, bl); - encode(file_i->dirstat.nfiles, bl); - encode(file_i->dirstat.nsubdirs, bl); - encode(file_i->rstat.rbytes, bl); - encode(file_i->rstat.rfiles, bl); - encode(file_i->rstat.rsubdirs, bl); - encode(file_i->rstat.rctime, bl); + encode(std::tuple{ + any_i->ctime, + file_i->mtime, + file_i->atime, + file_i->time_warp_seq, + file_i->size, + max_size, + file_i->truncate_size, + file_i->truncate_seq, + auth_i->mode, + (uint32_t)auth_i->uid, + (uint32_t)auth_i->gid, + link_i->nlink, + file_i->dirstat.nfiles, + file_i->dirstat.nsubdirs, + file_i->rstat.rbytes, + file_i->rstat.rfiles, + file_i->rstat.rsubdirs, + file_i->rstat.rctime, + }, bl, 0); dirfragtree.encode(bl); encode(symlink, bl); encode(file_i->dir_layout, bl); diff --git a/src/mds/journal.cc b/src/mds/journal.cc index b7fc058692a6..e5f679b33433 100644 --- a/src/mds/journal.cc +++ b/src/mds/journal.cc @@ -38,6 +38,7 @@ #include "events/ESegment.h" #include "events/ELid.h" +#include "include/denc.h" #include "include/stringify.h" #include "LogSegment.h" @@ -686,12 +687,14 @@ void EMetaBlob::remotebit::encode(bufferlist& bl) const { ENCODE_START(3, 2, bl); encode(dn, bl); - encode(dnfirst, bl); - encode(dnlast, bl); - encode(dnv, bl); - encode(ino, bl); - encode(d_type, bl); - encode(dirty, bl); + encode(std::tuple{ + dnfirst, + dnlast, + dnv, + ino, + d_type, + dirty, + }, bl, 0); encode(alternate_name, bl); ENCODE_FINISH(bl); } @@ -758,10 +761,12 @@ void EMetaBlob::nullbit::encode(bufferlist& bl) const { ENCODE_START(2, 2, bl); encode(dn, bl); - encode(dnfirst, bl); - encode(dnlast, bl); - encode(dnv, bl); - encode(dirty, bl); + encode(std::tuple{ + dnfirst, + dnlast, + dnv, + dirty, + }, bl, 0); ENCODE_FINISH(bl); } @@ -799,10 +804,12 @@ void EMetaBlob::dirlump::encode(bufferlist& bl, uint64_t features) const { ENCODE_START(2, 2, bl); encode(*fnode, bl); - encode(state, bl); - encode(nfull, bl); - encode(nremote, bl); - encode(nnull, bl); + encode(std::tuple{ + state, + nfull, + nremote, + nnull, + }, bl, 0); _encode_bits(features); encode(dnbl, bl); ENCODE_FINISH(bl); @@ -879,13 +886,17 @@ void EMetaBlob::encode(bufferlist& bl, uint64_t features) const encode(lump_map, bl, features); encode(roots, bl, features); encode(table_tids, bl); - encode(opened_ino, bl); - encode(allocated_ino, bl); - encode(used_preallocated_ino, bl); + encode(std::tuple{ + opened_ino, + allocated_ino, + used_preallocated_ino, + }, bl, 0); encode(preallocated_inos, bl); encode(client_name, bl); - encode(inotablev, bl); - encode(sessionmapv, bl); + encode(std::tuple{ + inotablev, + sessionmapv, + }, bl, 0); encode(truncate_start, bl); encode(truncate_finish, bl); encode(destroyed_inodes, bl); @@ -896,8 +907,10 @@ void EMetaBlob::encode(bufferlist& bl, uint64_t features) const // make MDSRank use v6 format happy int64_t i = -1; bool b = false; - encode(i, bl); - encode(b, bl); + encode(std::tuple{ + i, + b, + }, bl, 0); } encode(client_flushes, bl); ENCODE_FINISH(bl); -- 2.47.3