From: Xiubo Li via B4 Relay <devnull+xiubo.li.clyso.com@kernel.org>
To: Ilya Dryomov <idryomov@gmail.com>,
Alex Markuze <amarkuze@redhat.com>,
Viacheslav Dubeyko <slava@dubeyko.com>
Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
Xiubo Li <xiubo.li@clyso.com>
Subject: [PATCH 1/2] libceph: decode and apply pg_upmap_primary mappings
Date: Mon, 30 Nov 2026 07:12:04 +0100 [thread overview]
Message-ID: <20261130-b4-libceph-upmap-primary-v1-1-247b0a3d2e13@clyso.com> (raw)
In-Reply-To: <20261130-b4-libceph-upmap-primary-v1-0-247b0a3d2e13@clyso.com>
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
next prev parent reply other threads:[~2026-11-30 6:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-11-30 6:12 ` [PATCH 2/2] libceph: advertise SERVER_REEF Xiubo Li via B4 Relay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130-b4-libceph-upmap-primary-v1-1-247b0a3d2e13@clyso.com \
--to=devnull+xiubo.li.clyso.com@kernel.org \
--cc=amarkuze@redhat.com \
--cc=ceph-devel@vger.kernel.org \
--cc=idryomov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=slava@dubeyko.com \
--cc=xiubo.li@clyso.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®