diff options
author | Dongdong Tao <tdd21151186@gmail.com> | 2024-11-22 02:56:30 +0100 |
---|---|---|
committer | Dongdong Tao <tdd21151186@gmail.com> | 2024-11-22 15:07:31 +0100 |
commit | 60797f6862f8387be2b09ad61e198a60c55383d5 (patch) | |
tree | 59009b8646dafbaccde8fc1c4e914f9400b075ab | |
parent | Merge pull request #60655 from xxhdx1985126/wip-seastore-move-out-root-meta (diff) | |
download | ceph-60797f6862f8387be2b09ad61e198a60c55383d5.tar.xz ceph-60797f6862f8387be2b09ad61e198a60c55383d5.zip |
osd: optimize extent comparison in PrimaryLogPG
Improve the performance of finish_extent_cmp by using bufferlist iterators
instead of array access operator[]. This change:
- Replaces O(N) array access with O(1) iterator operations
The original implementation used array access which has O(N) complexity
for each access in bufferlist (N being the number of buffers in a bufferlist).
The new version uses iterators which wprovide O(1) increment operations,
reducing the overall function complexity from O(M*N) to O(M) with M being the
length of the bufferlist.
Fixes: https://tracker.ceph.com/issues/69014
Signed-off-by: Dongdong Tao <dongdong.tao@canonical.com>
-rw-r--r-- | src/osd/PrimaryLogPG.cc | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index 14d2f85f40f..930e06c4d5a 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -5798,10 +5798,19 @@ int PrimaryLogPG::do_extent_cmp(OpContext *ctx, OSDOp& osd_op) int PrimaryLogPG::finish_extent_cmp(OSDOp& osd_op, const bufferlist &read_bl) { - for (uint64_t idx = 0; idx < osd_op.indata.length(); ++idx) { - char read_byte = (idx < read_bl.length() ? read_bl[idx] : 0); - if (osd_op.indata[idx] != read_byte) { - return (-MAX_ERRNO - idx); + auto input_iter = osd_op.indata.begin(); + auto read_iter = read_bl.begin(); + uint64_t idx = 0; + + while (input_iter != osd_op.indata.end()) { + char read_byte = (read_iter != read_bl.end() ? *read_iter : 0); + if (*input_iter != read_byte) { + return (-MAX_ERRNO - idx); + } + ++idx; + ++input_iter; + if (read_iter != read_bl.end()) { + ++read_iter; } } |