Skip to content

Commit 60797f6

Browse files
committed
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 <[email protected]>
1 parent 3a35aeb commit 60797f6

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/osd/PrimaryLogPG.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5798,10 +5798,19 @@ int PrimaryLogPG::do_extent_cmp(OpContext *ctx, OSDOp& osd_op)
57985798

57995799
int PrimaryLogPG::finish_extent_cmp(OSDOp& osd_op, const bufferlist &read_bl)
58005800
{
5801-
for (uint64_t idx = 0; idx < osd_op.indata.length(); ++idx) {
5802-
char read_byte = (idx < read_bl.length() ? read_bl[idx] : 0);
5803-
if (osd_op.indata[idx] != read_byte) {
5804-
return (-MAX_ERRNO - idx);
5801+
auto input_iter = osd_op.indata.begin();
5802+
auto read_iter = read_bl.begin();
5803+
uint64_t idx = 0;
5804+
5805+
while (input_iter != osd_op.indata.end()) {
5806+
char read_byte = (read_iter != read_bl.end() ? *read_iter : 0);
5807+
if (*input_iter != read_byte) {
5808+
return (-MAX_ERRNO - idx);
5809+
}
5810+
++idx;
5811+
++input_iter;
5812+
if (read_iter != read_bl.end()) {
5813+
++read_iter;
58055814
}
58065815
}
58075816

0 commit comments

Comments
 (0)