From object name to OSD
In the book: Chapter 2, Chapter 8, Chapter 13, Chapter 27, Chapter 28, Chapter 37
From object name to OSD
Type a file or object name and follow, step by step, how Ceph hashes it, which PG it falls into and which OSDs CRUSH picks for it with each of the five bucket algorithms; then see how much data an added OSD, a new weight or an out OSD moves with each algorithm. Switch to an RBD image to see which rbd_data objects a byte range of the image falls into, and where each of them and the image's metadata objects land. Switch the pool to erasure-coded to see where the k+m shards go, how missing OSDs leave NONE holes and how a write is cut into stripes and chunks.
- photos/2026/11/img_0001.jpgname
- 0x755a2e85rjenkins
- pg 1.5stable_mod
- x 0xf58b672dpps
- [10,8,4]up · straw2
1Hash the object name
ceph_str_hash_rjenkins("photos/2026/11/img_0001.jpg") (27 B, UTF-8) = 0x755a2e85 = 1968844421The client (librados) feeds the name's UTF-8 bytes to ceph_str_hash_rjenkins, the default object_hash of a pool. The result is a 32-bit number; no table is looked up anywhere.
2From the hash to a PG
pg_num = 64 · pg_num_mask = 0x3f
0x755a2e85 & 0x3f = 5 < 64 ⇒ ps = 5
pgid = 1.55 is below pg_num, so it is the PG number. The PG id is the pool id and the PG number in hex; ceph osd map also prints the full hash: pg 1.755a2e85 (1.5).
3From the PG to the CRUSH input (pps)
ceph_stable_mod(5, pgp_num 64, 0x3f) = 5
x = crush_hash32_rjenkins1_2(5, pool 1) = 0xf58b672d = 4119553837With the hashpspool flag (the default) the PG number is reduced again with pgp_num and then hashed with the pool id, so that PGs with the same number in different pools do not land on the same OSDs.
4CRUSH: one draw per bucket
rule replicated_rule { step take default; step chooseleaf firstn 0 type host; step emit } # straw2, tunables jewel, size 3The rule starts at the root and, for each replica, picks a host and an OSD under it. r is the attempt number, r = replica + ftotal: every rejected or repeated choice adds one to r and the draw is made again. The winning row of each table is highlighted.
Replica 0 → osd.10
bucket default (straw2), r = 0 winner: host4
Item Weight u = hash₃(x, id, r) & 0xffff draw ≈ log₂((u+1)/2¹⁶) / w host1 12 0x8451 -0.0793 host2 12 0xab14 -0.0485 host3 12 0x561f -0.1310 host4 12 0xd865 -0.0202 bucket host4 (straw2), r = 0 winner: osd.10
Item Weight u = hash₃(x, id, r) & 0xffff draw ≈ log₂((u+1)/2¹⁶) / w osd.9 4 0x7431 -0.2849 osd.10 4 0xd76a -0.0623 osd.11 4 0x4323 -0.4827 Replica 1 → osd.8
bucket default (straw2), r = 1 winner: host3
Item Weight u = hash₃(x, id, r) & 0xffff draw ≈ log₂((u+1)/2¹⁶) / w host1 12 0x66bf -0.1098 host2 12 0xecce -0.0094 host3 12 0xf3e0 -0.0058 host4 12 0xc1f1 -0.0334 bucket host3 (straw2), r = 1 winner: osd.8
Item Weight u = hash₃(x, id, r) & 0xffff draw ≈ log₂((u+1)/2¹⁶) / w osd.6 4 0xdc72 -0.0539 osd.7 4 0x602c -0.3531 osd.8 4 0xebe4 -0.0295 Replica 2 → osd.4
bucket default (straw2), r = 2 winner: host4
Item Weight u = hash₃(x, id, r) & 0xffff draw ≈ log₂((u+1)/2¹⁶) / w host1 12 0xb671 -0.0407 host2 12 0xaa01 -0.0492 host3 12 0x25f6 -0.2295 host4 12 0xb747 -0.0402 ✗ host4 was already chosen (a collision); try again with r=3.
bucket default (straw2), r = 3 winner: host2
Item Weight u = hash₃(x, id, r) & 0xffff draw ≈ log₂((u+1)/2¹⁶) / w host1 12 0x6a2a -0.1058 host2 12 0xf3ba -0.0059 host3 12 0x6e78 -0.1010 host4 12 0x8486 -0.0792 bucket host2 (straw2), r = 3 winner: osd.4
Item Weight u = hash₃(x, id, r) & 0xffff draw ≈ log₂((u+1)/2¹⁶) / w osd.3 4 0x2947 -0.6582 osd.4 4 0xce92 -0.0774 osd.5 4 0x7ad3 -0.2649 5Up set, acting set and primary
raw (CRUSH) = [10,8,4]
up = [10,8,4] · acting = [10,8,4] · primary = osd.10CRUSH returns the raw set; the OSDMap drops the down OSDs from it (the up set). Without pg_temp and upmap the acting set is the up set, and its first member is the primary.
$ ceph osd map pool1 photos/2026/11/img_0001.jpg osdmap e1 pool 'pool1' (1) object 'photos/2026/11/img_0001.jpg' -> pg 1.755a2e85 (1.5) -> up ([10,8,4], p10) acting ([10,8,4], p10)
What moves when the map changes?
1000 sample objects (obj-0, obj-1, …) are placed with this pool and pg_num; then one change is applied and every replica is placed again, with each of the five algorithms.
| Algorithm | Replicas moved | Least needed | Objects affected |
|---|---|---|---|
| straw2 current | 31.7% +5.5% | 26.1% | 78.4% |
| straw | 31.7% +5.5% | 26.1% | 78.4% |
| list | 43.9% +15.8% | 28.1% | 92.5% |
| tree | 46.6% +21.8% | 24.8% | 94.0% |
| uniform | 76.2% +49.2% | 27.0% | 98.1% |
Object photos/2026/11/img_0001.jpg: before [10,8,4], after [10,8,0]
'Least needed' is what a perfect placement would move to reach the new per-OSD shares: the sum of what each OSD gains. No hierarchical placement reaches it exactly, because objects that enter or leave a host are drawn again inside it, and with several replicas a host that wins an earlier slot pushes the others along. What separates the algorithms is the rest (in orange): straw2 never moves data between two items whose weights did not change; uniform redraws everything when a bucket grows or shrinks (add a host) and ignores weights; list and tree depend on where the item sits (remove the second host, or an OSD in the middle of a host). Marking an OSD out costs the same with all five, since CRUSH only rejects it and draws again.
Follows:
src/common/ceph_hash.cc :: ceph_str_hash_rjenkinsthe object-name hashsrc/include/rados.h :: ceph_stable_mod; src/osd/osd_types.cc :: pg_pool_t::calc_pg_masksobject hash to PG while pg_num is not a power of twosrc/osd/osd_types.cc :: pg_pool_t::raw_pg_to_pps (FLAG_HASHPSPOOL)the PG's seed that enters CRUSHsrc/crush/hash.c :: crush_hash32_rjenkins1_2, _3, _4the Jenkins hash that CRUSH usessrc/crush/mapper.c :: crush_do_rule, crush_choose_firstn, is_outthe replicated (firstn) and EC (indep) choice loops with retriessrc/crush/mapper.c :: bucket_straw2_choose, generate_exponential_distribution, crush_lnstraw2: the largest ln(hash)/weight winssrc/crush/mapper.c :: bucket_straw_choose; builder.c :: crush_calc_straw (straw_calc_version 1)straw: the longest scaled straw wins; straw lengths depend on every weightsrc/crush/mapper.c :: bucket_list_choose, bucket_tree_choose, bucket_perm_choose; builder.c :: crush_make_bucketthe list, tree and uniform choices and how buckets are builtsrc/osd/OSDMap.cc :: _pg_to_raw_osds, _raw_to_up_osds, _pick_primaryraw set to up set (down OSDs are dropped or become NONE)src/crush/CrushWrapper.cc :: add_simple_rule_at; CrushWrapper.h :: set_tunables_jewelthe rule ceph osd pool create makes and the jewel tunablessrc/osdc/Striper.cc :: Striper::file_to_extents, get_num_objectsan image range to object extentssrc/librbd/ImageCtx.cc :: init_layout (format_string "%s.%016llx"); librbd/image/CreateRequest.cc :: create_image, validate_stripingdata object names, with and without a data pool, and the striping checkssrc/include/rbd_types.h; librbd/Utils.cc :: generate_image_id, id_obj_name, header_name; librbd/ObjectMap.cc :: object_map_namethe metadata object names and how image ids are madesrc/crush/mapper.c :: crush_choose_indep; CrushWrapper.cc :: add_simple_rule_at (indep)indep: positions filled in rounds, NONE for the empty onessrc/osd/ECUtil.h, ECUtil.cc :: stripe_info_t (ro_range_to_shards, object_size_to_shard_size); erasure-code/jerasure/ErasureCodeJerasure.cc :: get_chunk_sizeStripes, chunks and shard sizes in an erasure-coded poolsrc/mon/OSDMonitor.cc :: prepare_pool_size, prepare_pool_stripe_width; osd/osd_types.h :: spg_tAn erasure-coded pool's size, min_size and stripe_width, and shard names