# From object name to OSD

*HTML: https://book.ceph-s3.ir/en/lab-placement.html*
*Licence: CC BY-NC-SA 4.0. Author: Ramin Najarbashi.*

[Interactive lab](lab.html)From object name to OSD
In the book: [Chapter 2](02-block-device-rbd.html#sec-02-2-1), [Chapter 8](08-under-the-hood.html#sec-08-6-1), [Chapter 13](13-erasure-coding.html), [Chapter 27](27-low-ec-math.html#sec-27-4), [Chapter 28](28-low-crush-bits.html), [Chapter 37](37-spec-rbd-layout-striping-objectmap.html)
LabFrom object name to OSDType 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.jpg**name**0x755a2e85**rjenkins**pg 1.5**stable_mod**x 0xf58b672d**pps**[10,8,4]**up · straw2**1.5**PG id**0xf58b672d**x (pps)**[10,8,4]**up set**osd.10**primary1Hash the object nameceph_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 PGpg_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 3`The 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.10bucket default (straw2), r = 0 winner: host4ItemWeightu = hash₃(x, id, r) & 0xffffdraw ≈ log₂((u+1)/2¹⁶) / whost1120x8451-0.0793host2120xab14-0.0485host3120x561f-0.1310host4120xd865-0.0202bucket host4 (straw2), r = 0 winner: osd.10ItemWeightu = hash₃(x, id, r) & 0xffffdraw ≈ log₂((u+1)/2¹⁶) / wosd.940x7431-0.2849osd.1040xd76a-0.0623osd.1140x4323-0.4827Replica 1 → osd.8bucket default (straw2), r = 1 winner: host3ItemWeightu = hash₃(x, id, r) & 0xffffdraw ≈ log₂((u+1)/2¹⁶) / whost1120x66bf-0.1098host2120xecce-0.0094host3120xf3e0-0.0058host4120xc1f1-0.0334bucket host3 (straw2), r = 1 winner: osd.8ItemWeightu = hash₃(x, id, r) & 0xffffdraw ≈ log₂((u+1)/2¹⁶) / wosd.640xdc72-0.0539osd.740x602c-0.3531osd.840xebe4-0.0295Replica 2 → osd.4bucket default (straw2), r = 2 winner: host4ItemWeightu = hash₃(x, id, r) & 0xffffdraw ≈ log₂((u+1)/2¹⁶) / whost1120xb671-0.0407host2120xaa01-0.0492host3120x25f6-0.2295host4120xb747-0.0402✗ host4 was already chosen (a collision); try again with r=3.bucket default (straw2), r = 3 winner: host2ItemWeightu = hash₃(x, id, r) & 0xffffdraw ≈ log₂((u+1)/2¹⁶) / whost1120x6a2a-0.1058host2120xf3ba-0.0059host3120x6e78-0.1010host4120x8486-0.0792bucket host2 (straw2), r = 3 winner: osd.4ItemWeightu = hash₃(x, id, r) & 0xffffdraw ≈ log₂((u+1)/2¹⁶) / wosd.340x2947-0.6582osd.440xce92-0.0774osd.540x7ad3-0.26495Up set, acting set and primaryraw (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.Changeadd an OSD to the last hostadd a host with three OSDschange an OSD's weightmark an OSD outremove an OSD from the mapremove the second hostconvert every bucket to another algorithmSample objects100010000AlgorithmReplicas movedLeast neededObjects affectedstraw2 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_rjenkins` the object-name hash`src/include/rados.h :: ceph_stable_mod; src/osd/osd_types.cc :: pg_pool_t::calc_pg_masks` object hash to PG while pg_num is not a power of two`src/osd/osd_types.cc :: pg_pool_t::raw_pg_to_pps (FLAG_HASHPSPOOL)` the PG's seed that enters CRUSH`src/crush/hash.c :: crush_hash32_rjenkins1_2, _3, _4` the Jenkins hash that CRUSH uses`src/crush/mapper.c :: crush_do_rule, crush_choose_firstn, is_out` the replicated (firstn) and EC (indep) choice loops with retries`src/crush/mapper.c :: bucket_straw2_choose, generate_exponential_distribution, crush_ln` straw2: the largest ln(hash)/weight wins`src/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 weight`src/crush/mapper.c :: bucket_list_choose, bucket_tree_choose, bucket_perm_choose; builder.c :: crush_make_bucket` the list, tree and uniform choices and how buckets are built`src/osd/OSDMap.cc :: _pg_to_raw_osds, _raw_to_up_osds, _pick_primary` raw set to up set (down OSDs are dropped or become NONE)`src/crush/CrushWrapper.cc :: add_simple_rule_at; CrushWrapper.h :: set_tunables_jewel` the rule ceph osd pool create makes and the jewel tunables`src/osdc/Striper.cc :: Striper::file_to_extents, get_num_objects` an image range to object extents`src/librbd/ImageCtx.cc :: init_layout (format_string "%s.%016llx"); librbd/image/CreateRequest.cc :: create_image, validate_striping` data object names, with and without a data pool, and the striping checks`src/include/rbd_types.h; librbd/Utils.cc :: generate_image_id, id_obj_name, header_name; librbd/ObjectMap.cc :: object_map_name` the metadata object names and how image ids are made`src/crush/mapper.c :: crush_choose_indep; CrushWrapper.cc :: add_simple_rule_at (indep)` indep: positions filled in rounds, NONE for the empty ones`src/osd/ECUtil.h, ECUtil.cc :: stripe_info_t (ro_range_to_shards, object_size_to_shard_size); erasure-code/jerasure/ErasureCodeJerasure.cc :: get_chunk_size` Stripes, chunks and shard sizes in an erasure-coded pool`src/mon/OSDMonitor.cc :: prepare_pool_size, prepare_pool_stripe_width; osd/osd_types.h :: spg_t` An erasure-coded pool's size, min_size and stripe_width, and shard namesA fixed snapshot of the simulator; the interactive version is in the web edition's lab. [Interactive lab: From object name to OSD](lab-placement.html)The interactive version needs JavaScript; this is a fixed snapshot.
