From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796091491; b=GYL6pOuPOmZqifhoJ5XB1c0K0x3JGThBK9tGL1M2OkANNp2xl0gQ2zIRzK2CDTitK+P/ 3luiLsFL3ir2+d9drB+Gtoxgs2y4oBe2wakY3d0hik5JsPO0yxRMFW2q0gw//WQD0TxZm JsLKsMPDADFtmSUZeGPgNaGMXvJKKt1JIulyHS75F+DnNDmZ9QZtPVTK8uTYhGe1CJj35 7XJ3QdKV0V85LEP2j6mm1GP2Y38wUuMow6KdTFN35EP9rBZjq6+f3Mnqh5PEBSIOyd2u8 eMCWqWFoQiWshrRY5UkEcM7V7+7I9UKu9WE34vcbP+D/qT6OcaynfhVb6lfPEPoYdKg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796091491; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=k+WmD/+Ntm9DRszG5QGngGNQFhKsKkkrAkJMTX+TbM0=; b=uc7k6e4tCg/XMGw37gVBYWgpqstEehmP6brwgroqkt6iELq3NrgwX7gNKkt3pDBxb+4M cZTBENMItMfda2csRnvr8ZsrjP8K880wcDfuxIZc4Gy9zV72DAErUR+IrTLfdMkSxUOMJ BR3gq440Xlnyxs38jkoUYhu6QyP1njY9c1704T/LIwZSfZfKYo1xPlNBCMs6d5izlDPTo DrOzpDnrXjqgU8G3JThRHkUWOq+S0ShrZ9Jr8bXrj3IOaL8NN/KIgJ7Ez9VK1ZKNMqVu8 5V+LQGj8oWcvBgQ4j2ey/FmQlNjeqM6fXYiWrey9TpnDLkZI1Mg55XhnZoLi8WWp9HQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fwY7qksD; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81286606A31A; Tue, 1 Dec 2026 02:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fwY7qksD Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796091491; b=ILZDCkoBW5ZMIwksDw87mvCOWcigi9DyRlwYjCLZ1fHwgehABSOY/3xofkHyNjldmVRn hrbOXopdx6mYKn/1ay6sbWskhiQOz63wfhCUgC6VW0qUFAV9d4NI0tMyLcnOfXMXp30ai 6d8iU2DX6VQcKrLL335L3eDrnmJ8v/PwHiOlKD5LC5aZ5Kl1Wbb4+iCoKXhfUPV288Pn6 9kP6O5DELpI4keOAnpVrk0s0ycUbwTDrCXm4zDC/OBpitgKBCzHAIkdrNTdtNC9A24Tj+ rtftEzeXJ3Y+JPCJDsolnu7K3dLPD3CE4E8AYlVlHAfljzlhDK7TJIf0xVh0JElgZHA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796091491; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=k+WmD/+Ntm9DRszG5QGngGNQFhKsKkkrAkJMTX+TbM0=; b=N3nfRyij+NglQnqkSLDFU16mhmu3VjmVhIOuvaYn42ZHRQA9D0sF2yTlViOmVpncFSgi Ka+Obq0QfGZds/Hj6R9akkvUMSiqyxfzuVRPeihJS1yojc2hvEhxrafBdl8AS41u3tVwm t4K/2pro2KNEIPYLmu3dP234RVD0xseaOMsJOFSKphbD68oMzP9jreNvDgXyfgSjc0bXS 334DoPk3ljgr6tdDU3xtaFCgSeEEdEZeoUe2exFz01rAwBZlkvjRsbnV9gkDfijoGgsLn QmmROe4rfYD0S3rQhc0XmoAKZXMXDib9wRrxLklEGMJ5ljZXxkY+D+tuO62W65LNmBA== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id EECCA1F0089B; Tue, 1 Dec 2026 02:18:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796091491; bh=k+WmD/+Ntm9DRszG5QGngGNQFhKsKkkrAkJMTX+TbM0=; h=From:Date:Subject:To:Cc:Reply-To; b=fwY7qksD04RfKstiQNLAf+V1HRKHA7gc25ryjK5Ia0kxx33uVuGiGaBI6BfP9HPjW Tw6ugKraPTyTI71Bhl/Yt1h8DVnjIIyFIA+iuxNIww6LF38JEQ1dUMb/9Q1Gd2TXvC OKrR4S9khaHA5ZbZxiEYJ7Ay53bE1rmLpj+IoktPqtCPk5NsgcEge6eK06KbJHKDfX wOr4zoRfr071Ghp2e+jhTPdR6rIZONyz97cdsuKW6d0MSQy2gMJGjgMfQ6oGtEwuhf C7kmY/vaDyZM5Zu/oabLY5np2F7G+BsbXUTi73slwZihkZI7UnlfQuvO/CVQkJpSSL kTwJG41nC8yEg== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 4F8E24EB54; Tue, 1 Dec 2026 02:18:00 +0000 (UTC) From: Xiubo Li via B4 Relay Date: Tue, 01 Dec 2026 03:17:49 +0100 Subject: [PATCH] libceph: don't assume the primary leads the acting set for replica reads X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261201-b4-libceph-replica-read-v1-1-6c4436b238ca@clyso.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yXMywqDMBCF4VeRWTtgQr31VaSLZJzoiNiQ2CJI3 t20rg7f4vwnRA7CEZ7FCYG/EuW9ZaiyAJrNNjHKmA260o3SlUL7wFUssZ8xsF+FTF4zYt07alV H1tQN5LcP7OT4l4fX7fixC9P+y0FKF6lbn7N7AAAA X-Change-ID: 20261201-b4-libceph-replica-read-59fc718cba56 To: Ilya Dryomov , Alex Markuze , Viacheslav Dubeyko Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Xiubo Li X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796091478; l=5111; i=xiubo.li@clyso.com; s=20260625; h=from:subject:message-id; bh=Hc64a2Cgrob1Mi3R2ovQ22XepHzAj0tiZSulU+UOmZg=; b=q3VFVkntw64Dyb80pQNMCAfB/n7PRM4HxhLBjPH3i6uZbwWm/Hnm6ZOYKEhgH+hDqB38w6BMg 8B2D962Ak/fDxdJOV9+5FIJ5RtxkJtxpe/AchfefUiXcDsoP8RU0/BF X-Developer-Key: i=xiubo.li@clyso.com; a=ed25519; pk=V3NGr0AgAopiUhaLY51ipBkLN5LlcLhjOEfLEq1RoZ8= X-Endpoint-Received: by B4 Relay for xiubo.li@clyso.com/20260625 with auth_id=840 X-Original-From: Xiubo Li Reply-To: xiubo.li@clyso.com Content-Transfer-Encoding: 7bit From: Xiubo Li A primary_temp ("ceph osd primary-temp") names the primary of a PG without moving it to the front of the acting set: get_temp_osds() takes it as is, like OSDMap::_get_temp_osds() does. calc_target() however assumes that acting.osds[0] is the primary when it picks a replica for a balanced or localized read: - it warns, every time the target is recalculated, when that is not the case; - it derives used_replica from the index, so a read sent to acting.osds[0], which then is a replica, is not marked as one, and the EAGAIN that replica may return trips the WARN_ON in handle_reply(); - pick_closest_replica() breaks ties in favour of acting.osds[0] instead of the primary, against its own comment. Set used_replica by comparing the chosen OSD with the primary, and start the locality search from the primary. Tested with read_from_replica=balance against a 3-OSD cluster with a primary_temp on 8 PGs of the data pool, each naming the second OSD of the acting set, writing a file and reading it back after dropping the page cache: +-------------------------------+-----------+-----------+ | | before | after | +-------------------------------+-----------+-----------+ | WARN_ON in calc_target() | 52 | 0 | | data read back matches | yes | yes | | misdirected ops in OSD logs | 0 | 0 | +-------------------------------+-----------+-----------+ Without a primary_temp the target does not change. An IO500 run with read_from_replica=balance on the same cluster (16 processes over 4 mounts, one run each) is within the spread seen between repeated runs: +-------------------------+-----------+-----------+ | | before | after | +-------------------------+-----------+-----------+ | ior-easy-read (GiB/s) | 5.955 | 6.253 | | ior-hard-read (GiB/s) | 3.900 | 3.876 | | mdtest-hard-read (kIOPS)| 19.180 | 19.228 | | mdtest-easy-stat (kIOPS)| 31.809 | 31.311 | | score | 5.197 | 5.272 | +-------------------------+-----------+-----------+ Fixes: 117d96a04f00 ("libceph: support for balanced and localized reads") Signed-off-by: Xiubo Li --- A primary_temp leaves the primary where it is in the acting set, and balanced and localized reads then warn on every target calculation and do not mark a read sent to acting.osds[0] as a replica read. --- net/ceph/osd_client.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c index 22a793a4bdc8..edb5c50045de 100644 --- a/net/ceph/osd_client.c +++ b/net/ceph/osd_client.c @@ -1549,27 +1549,38 @@ static int pick_random_replica(const struct ceph_osds *acting) /* * Picks the closest replica based on client's location given by * crush_location option. Prefers the primary if the locality is - * the same. + * the same. The primary need not be acting->osds[0]: a primary_temp + * names it without reordering the acting set. */ static int pick_closest_replica(struct ceph_osd_client *osdc, const struct ceph_osds *acting) { struct ceph_options *opt = osdc->client->options; - int best_i, best_locality; - int i = 0, locality; + int best_i = 0, best_locality; + int i, locality; - do { + for (i = 0; i < acting->size; i++) { + if (acting->osds[i] == acting->primary) { + best_i = i; + break; + } + } + best_locality = ceph_get_crush_locality(osdc->osdmap, + acting->osds[best_i], + &opt->crush_locs); + + for (i = 0; i < acting->size; i++) { + if (i == best_i) + continue; locality = ceph_get_crush_locality(osdc->osdmap, acting->osds[i], &opt->crush_locs); - if (i == 0 || - (locality >= 0 && best_locality < 0) || - (locality >= 0 && best_locality >= 0 && - locality < best_locality)) { + if (locality >= 0 && + (best_locality < 0 || locality < best_locality)) { best_i = i; best_locality = locality; } - } while (++i < acting->size); + } dout("%s picked osd%d with locality %d, primary osd%d\n", __func__, acting->osds[best_i], best_locality, acting->primary); @@ -1692,14 +1703,14 @@ static enum calc_target_result calc_target(struct ceph_osd_client *osdc, acting.size > 1) { int pos; - WARN_ON(!is_read || acting.osds[0] != acting.primary); + WARN_ON(!is_read); if (t->flags & CEPH_OSD_FLAG_BALANCE_READS) { pos = pick_random_replica(&acting); } else { pos = pick_closest_replica(osdc, &acting); } t->osd = acting.osds[pos]; - t->used_replica = pos > 0; + t->used_replica = t->osd != acting.primary; } else { t->osd = acting.primary; t->used_replica = false; --- base-commit: 3f90412e989cb381d4bf96260468f5c7b2d08655 change-id: 20261201-b4-libceph-replica-read-59fc718cba56 Best regards, -- Xiubo Li