mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] libceph: support pg_upmap_primary (the read balancer)
@ 2026-11-30  6:12 Xiubo Li via B4 Relay
  2026-11-30  6:12 ` [PATCH 1/2] libceph: decode and apply pg_upmap_primary mappings Xiubo Li via B4 Relay
  2026-11-30  6:12 ` [PATCH 2/2] libceph: advertise SERVER_REEF Xiubo Li via B4 Relay
  0 siblings, 2 replies; 3+ messages in thread
From: Xiubo Li via B4 Relay @ 2026-11-30  6:12 UTC (permalink / raw)
  To: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko
  Cc: ceph-devel, linux-kernel, Xiubo Li

Since reef, the mgr read balancer ("ceph balancer mode read" or
"upmap-read") and "ceph osd pg-upmap-primary" choose the primary of
each PG explicitly, so that reads, which normally go to the primary,
are spread evenly over the OSDs.

Kernel clients cannot take part today.  libceph does not decode
pg_upmap_primary and does not advertise SERVER_REEF, the feature the
monitors require from every client once the OSDMap holds such an
entry.  So "ceph osd set-require-min-compat-client reef" is refused
while kernel clients are connected, and a kernel client can neither
mount CephFS nor map an rbd image on a cluster that already uses the
read balancer:

  libceph: RADOS feature set mismatch: server's required > my supported 0x2f018fb87aa4aafe, missing 0x80000000
  libceph: mon0 (2)127.0.0.1:17300 missing required protocol features

Patch 1 decodes the mappings from full and incremental maps and
applies them the way OSDMap::_apply_upmap() does.  Patch 2 advertises
SERVER_REEF, which towards clients only selects the OSDMap encodings
that carry pg_upmap_primary.

Tested with the series applied to a 7.2-based tree, built as the
libceph, ceph and rbd modules, against a 3-OSD tentacle cluster:
CephFS mounts and rbd maps work with the read balancer on, the
kernel's pg_upmap_primary entries follow the cluster through full and
incremental maps, and all I/O of a PG goes to the chosen primary.
Without entries, krbd fio and an IO500 run show no difference from the
unpatched modules.  The read balancer numbers are in patch 2.

---
Xiubo Li (2):
      libceph: decode and apply pg_upmap_primary mappings
      libceph: advertise SERVER_REEF

 include/linux/ceph/ceph_features.h |  4 +-
 include/linux/ceph/osdmap.h        |  4 ++
 net/ceph/debugfs.c                 |  7 +++
 net/ceph/osdmap.c                  | 99 +++++++++++++++++++++++++++++++++++++-
 4 files changed, 112 insertions(+), 2 deletions(-)
---
base-commit: 3f90412e989cb381d4bf96260468f5c7b2d08655
change-id: 20261130-b4-libceph-upmap-primary-9fc9dbab8652

Best regards,
--  
Xiubo Li <xiubo.li@clyso.com>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] libceph: decode and apply pg_upmap_primary mappings
  2026-11-30  6:12 [PATCH 0/2] libceph: support pg_upmap_primary (the read balancer) Xiubo Li via B4 Relay
@ 2026-11-30  6:12 ` Xiubo Li via B4 Relay
  2026-11-30  6:12 ` [PATCH 2/2] libceph: advertise SERVER_REEF Xiubo Li via B4 Relay
  1 sibling, 0 replies; 3+ messages in thread
From: Xiubo Li via B4 Relay @ 2026-11-30  6:12 UTC (permalink / raw)
  To: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko
  Cc: ceph-devel, linux-kernel, Xiubo Li

From: Xiubo Li <xiubo.li@clyso.com>

Since reef, the mgr read balancer and "ceph osd pg-upmap-primary" can
choose the primary of a PG explicitly.  The mapping is kept in the
OSDMap as pg_upmap_primaries (client data v10 of a full map) and as
new_pg_upmap_primary/old_pg_upmap_primary (client data v9 of an
incremental), and the OSDs apply it after pg_upmap and pg_upmap_items:
if the chosen OSD is in the raw set and not marked out, it is swapped
into the first position.

libceph stops decoding after pg_upmap_items, so for every such PG it
computes a different primary than the OSDs do.  Decode the mapping,
skipping the crush_version, removed/purged snaps and last up/in change
fields in front of it, apply it in apply_upmap() the same way
OSDMap::_apply_upmap() does, and list it in the osdmap debugfs file.

The monitors and OSDs send these encodings only to clients that have
the SERVER_REEF feature, which the next patch advertises.

Signed-off-by: Xiubo Li <xiubo.li@clyso.com>
---
 include/linux/ceph/osdmap.h |  4 ++
 net/ceph/debugfs.c          |  7 ++++
 net/ceph/osdmap.c           | 99 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 109 insertions(+), 1 deletion(-)

diff --git a/include/linux/ceph/osdmap.h b/include/linux/ceph/osdmap.h
index 5553019c3f07..a13316417e6a 100644
--- a/include/linux/ceph/osdmap.h
+++ b/include/linux/ceph/osdmap.h
@@ -164,6 +164,9 @@ struct ceph_pg_mapping {
 			int len;
 			int from_to[][2];
 		} pg_upmap_items;
+		struct {
+			int osd;
+		} pg_upmap_primary;
 	};
 };
 
@@ -185,6 +188,7 @@ struct ceph_osdmap {
 	/* remap (post-CRUSH, pre-up) */
 	struct rb_root pg_upmap;	/* PG := raw set */
 	struct rb_root pg_upmap_items;	/* from -> to within raw set */
+	struct rb_root pg_upmap_primaries; /* new primary within raw set */
 
 	u32 *osd_primary_affinity;
 
diff --git a/net/ceph/debugfs.c b/net/ceph/debugfs.c
index 20674e5d2711..aa79dd63bef7 100644
--- a/net/ceph/debugfs.c
+++ b/net/ceph/debugfs.c
@@ -138,6 +138,13 @@ static int osdmap_show(struct seq_file *s, void *p)
 				   pg->pg_upmap_items.from_to[i][1]);
 		seq_printf(s, "]\n");
 	}
+	for (n = rb_first(&map->pg_upmap_primaries); n; n = rb_next(n)) {
+		struct ceph_pg_mapping *pg =
+			rb_entry(n, struct ceph_pg_mapping, node);
+
+		seq_printf(s, "pg_upmap_primary %llu.%x %d\n", pg->pgid.pool,
+			   pg->pgid.seed, pg->pg_upmap_primary.osd);
+	}
 
 out_unlock:
 	up_read(&osdc->lock);
diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
index a946724d4ef7..aedb8b15c972 100644
--- a/net/ceph/osdmap.c
+++ b/net/ceph/osdmap.c
@@ -1152,6 +1152,7 @@ struct ceph_osdmap *ceph_osdmap_alloc(void)
 	map->primary_temp = RB_ROOT;
 	map->pg_upmap = RB_ROOT;
 	map->pg_upmap_items = RB_ROOT;
+	map->pg_upmap_primaries = RB_ROOT;
 
 	init_workspace_manager(&map->crush_wsm);
 
@@ -1194,6 +1195,13 @@ void ceph_osdmap_destroy(struct ceph_osdmap *map)
 		rb_erase(&pg->node, &map->pg_upmap_items);
 		kfree(pg);
 	}
+	while (!RB_EMPTY_ROOT(&map->pg_upmap_primaries)) {
+		struct ceph_pg_mapping *pg =
+			rb_entry(rb_first(&map->pg_upmap_primaries),
+				 struct ceph_pg_mapping, node);
+		rb_erase(&pg->node, &map->pg_upmap_primaries);
+		kfree(pg);
+	}
 	while (!RB_EMPTY_ROOT(&map->pg_pools)) {
 		struct ceph_pg_pool_info *pi =
 			rb_entry(rb_first(&map->pg_pools),
@@ -1678,6 +1686,44 @@ static int decode_old_pg_upmap_items(void **p, void *end,
 	return decode_pg_mapping(p, end, &map->pg_upmap_items, NULL, true);
 }
 
+static struct ceph_pg_mapping *__decode_pg_upmap_primary(void **p, void *end,
+							 bool incremental)
+{
+	struct ceph_pg_mapping *pg;
+	u32 osd;
+
+	ceph_decode_32_safe(p, end, osd, e_inval);
+	pg = alloc_pg_mapping(0);
+	if (!pg)
+		return ERR_PTR(-ENOMEM);
+
+	pg->pg_upmap_primary.osd = osd;
+	return pg;
+
+e_inval:
+	return ERR_PTR(-EINVAL);
+}
+
+static int decode_pg_upmap_primaries(void **p, void *end,
+				     struct ceph_osdmap *map)
+{
+	return decode_pg_mapping(p, end, &map->pg_upmap_primaries,
+				 __decode_pg_upmap_primary, false);
+}
+
+static int decode_new_pg_upmap_primaries(void **p, void *end,
+					 struct ceph_osdmap *map)
+{
+	return decode_pg_mapping(p, end, &map->pg_upmap_primaries,
+				 __decode_pg_upmap_primary, true);
+}
+
+static int decode_old_pg_upmap_primaries(void **p, void *end,
+					 struct ceph_osdmap *map)
+{
+	return decode_pg_mapping(p, end, &map->pg_upmap_primaries, NULL, true);
+}
+
 /*
  * decode a full map.
  */
@@ -1812,6 +1858,23 @@ static int osdmap_decode(void **p, void *end, bool msgr2,
 		WARN_ON(!RB_EMPTY_ROOT(&map->pg_upmap_items));
 	}
 
+	if (struct_v >= 10) {
+		/* crush_version */
+		ceph_decode_skip_32(p, end, e_inval);
+		/* new_removed_snaps, new_purged_snaps */
+		ceph_decode_skip_map_of_map(p, end, 64, 64, 64, e_inval);
+		ceph_decode_skip_map_of_map(p, end, 64, 64, 64, e_inval);
+		/* last_up_change, last_in_change */
+		ceph_decode_skip_n(p, end, 2 * sizeof(struct ceph_timespec),
+				   e_inval);
+
+		err = decode_pg_upmap_primaries(p, end, map);
+		if (err)
+			goto bad;
+	} else {
+		WARN_ON(!RB_EMPTY_ROOT(&map->pg_upmap_primaries));
+	}
+
 	/* ignore the rest */
 	*p = end;
 
@@ -2127,6 +2190,23 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, bool msgr2,
 			goto bad;
 	}
 
+	if (struct_v >= 9) {
+		/* new_removed_snaps, new_purged_snaps */
+		ceph_decode_skip_map_of_map(p, end, 64, 64, 64, e_inval);
+		ceph_decode_skip_map_of_map(p, end, 64, 64, 64, e_inval);
+		/* new_last_up_change, new_last_in_change */
+		ceph_decode_skip_n(p, end, 2 * sizeof(struct ceph_timespec),
+				   e_inval);
+
+		err = decode_new_pg_upmap_primaries(p, end, map);
+		if (err)
+			goto bad;
+
+		err = decode_old_pg_upmap_primaries(p, end, map);
+		if (err)
+			goto bad;
+	}
+
 	/* ignore the rest */
 	*p = end;
 
@@ -2631,7 +2711,7 @@ static void pg_to_raw_osds(struct ceph_osdmap *osdmap,
 	remove_nonexistent_osds(osdmap, pi, raw);
 }
 
-/* apply pg_upmap[_items] mappings */
+/* apply pg_upmap[_items] and pg_upmap_primary mappings */
 static void apply_upmap(struct ceph_osdmap *osdmap,
 			const struct ceph_pg *pgid,
 			struct ceph_osds *raw)
@@ -2690,6 +2770,23 @@ static void apply_upmap(struct ceph_osdmap *osdmap,
 				raw->osds[pos] = to;
 		}
 	}
+
+	pg = lookup_pg_mapping(&osdmap->pg_upmap_primaries, pgid);
+	if (pg) {
+		int osd = pg->pg_upmap_primary.osd;
+
+		/* ignore mapping if new primary is invalid or marked out */
+		if (osd != CRUSH_ITEM_NONE && osd >= 0 &&
+		    osd < osdmap->max_osd && osdmap->osd_weight[osd] != 0) {
+			for (i = 1; i < raw->size; i++) {
+				if (raw->osds[i] == osd) {
+					raw->osds[i] = raw->osds[0];
+					raw->osds[0] = osd;
+					break;
+				}
+			}
+		}
+	}
 }
 
 /*

-- 
2.53.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] libceph: advertise SERVER_REEF
  2026-11-30  6:12 [PATCH 0/2] libceph: support pg_upmap_primary (the read balancer) Xiubo Li via B4 Relay
  2026-11-30  6:12 ` [PATCH 1/2] libceph: decode and apply pg_upmap_primary mappings Xiubo Li via B4 Relay
@ 2026-11-30  6:12 ` Xiubo Li via B4 Relay
  1 sibling, 0 replies; 3+ messages in thread
From: Xiubo Li via B4 Relay @ 2026-11-30  6:12 UTC (permalink / raw)
  To: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko
  Cc: ceph-devel, linux-kernel, Xiubo Li

From: Xiubo Li <xiubo.li@clyso.com>

Once the OSDMap holds a pg_upmap_primary entry, the monitors require
the SERVER_REEF feature from every client, and "ceph osd
set-require-min-compat-client reef", which pg-upmap-primary needs
first, is refused while clients without it are connected.  So a
cluster with kernel clients cannot use the read balancer, and a kernel
client cannot connect to a cluster that already uses it.

SERVER_REEF reuses bit 31, whose first incarnation MON_SINGLE_PAXOS is
retired.  Towards clients it only selects the OSDMap encodings that
carry pg_upmap_primary, which libceph decodes now, so advertise it.

Tested on a 3-OSD tentacle cluster with the read balancer
(osdmaptool --read) applied to its pools.  Without this series the
monitors drop the session ("missing required protocol features",
0x80000000), so neither a CephFS mount nor an rbd map succeeds.  With
it, both work; after the full map at mount time and after a burst of
22 incrementals the kernel's pg_upmap_primary list matches the
cluster's, all reads and writes of a PG go to the chosen primary, and
no OSD logs a misdirected op.

krbd fio on a 128-PG pool whose primaries were split 40/48/40, and
43/43/42 after the read balancer added 5 entries (O_DIRECT, 30 s,
median of 3 runs, MiB/s with p99 latency):

  +-----------------------------+------------------+------------------+
  |                             | primary reads    | read balancer    |
  +-----------------------------+------------------+------------------+
  | 4M seq read, 4 x qd16       | 4713 (163 ms)    | 4995 (128 ms)    |
  | 4K random read, 4 x qd32    |  586 (1.93 ms)   |  594 (1.73 ms)   |
  +-----------------------------+------------------+------------------+

4K random writes do not change beyond the run-to-run spread.  The gain
follows how uneven the primaries were: the busiest OSD went from 37.5%
to 33.6% of the primaries here.

Signed-off-by: Xiubo Li <xiubo.li@clyso.com>
---
 include/linux/ceph/ceph_features.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/ceph/ceph_features.h b/include/linux/ceph/ceph_features.h
index 1e4dce93a8a1..9202749a820d 100644
--- a/include/linux/ceph/ceph_features.h
+++ b/include/linux/ceph/ceph_features.h
@@ -118,7 +118,8 @@ DEFINE_CEPH_FEATURE_RETIRED(28, 1, OSD_HBMSGS, HAMMER, JEWEL)
 DEFINE_CEPH_FEATURE(28, 2, SERVER_MIMIC)
 DEFINE_CEPH_FEATURE(29, 1, MDSENC)
 DEFINE_CEPH_FEATURE(30, 1, OSDHASHPSPOOL)
-DEFINE_CEPH_FEATURE(31, 1, MON_SINGLE_PAXOS)  // deprecate me
+DEFINE_CEPH_FEATURE_RETIRED(31, 1, MON_SINGLE_PAXOS, NAUTILUS, PACIFIC)
+DEFINE_CEPH_FEATURE(31, 3, SERVER_REEF)
 DEFINE_CEPH_FEATURE_RETIRED(32, 1, OSD_SNAPMAPPER, JEWEL, LUMINOUS)
 
 DEFINE_CEPH_FEATURE_RETIRED(33, 1, MON_SCRUB, JEWEL, LUMINOUS)
@@ -210,6 +211,7 @@ DEFINE_CEPH_FEATURE_DEPRECATED(63, 1, RESERVED_BROKEN, LUMINOUS) // client-facin
 	 CEPH_FEATURE_CRUSH_TUNABLES2 |		\
 	 CEPH_FEATURE_REPLY_CREATE_INODE |	\
 	 CEPH_FEATURE_SERVER_MIMIC |		\
+	 CEPH_FEATURE_SERVER_REEF |		\
 	 CEPH_FEATURE_MDSENC |			\
 	 CEPH_FEATURE_OSDHASHPSPOOL |		\
 	 CEPH_FEATURE_OSD_CACHEPOOL |		\

-- 
2.53.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-30  6:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30  6:12 [PATCH 0/2] libceph: support pg_upmap_primary (the read balancer) Xiubo Li via B4 Relay
2026-11-30  6:12 ` [PATCH 1/2] libceph: decode and apply pg_upmap_primary mappings Xiubo Li via B4 Relay
2026-11-30  6:12 ` [PATCH 2/2] libceph: advertise SERVER_REEF Xiubo Li via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®