The Comprehensive Ceph Guide
فارسیGet started

From object name to OSD

In the book: Chapter 2, Chapter 8, Chapter 13, Chapter 27, Chapter 28, Chapter 37

Lab

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.

  1. photos/2026/11/img_0001.jpgname
  2. 0x755a2e85rjenkins
  3. pg 1.5stable_mod
  4. x 0xf58b672dpps
  5. [10,8,4]up · straw2
1.5PG id
0xf58b672dx (pps)
[10,8,4]up set
osd.10primary
  1. 1Hash the object name

    ceph_str_hash_rjenkins("photos/2026/11/img_0001.jpg") (27 B, UTF-8) = 0x755a2e85 = 1968844421

    The 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.

  2. 2From the hash to a PG

    pg_num = 64 · pg_num_mask = 0x3f
    0x755a2e85 & 0x3f = 5 < 64 ⇒ ps = 5
    pgid = 1.5

    5 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).

  3. 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 = 4119553837

    With 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.

  4. 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.10

    bucket default (straw2), r = 0 winner: host4

    ItemWeightu = hash₃(x, id, r) & 0xffffdraw ≈ log₂((u+1)/2¹⁶) / w
    host1120x8451-0.0793
    host2120xab14-0.0485
    host3120x561f-0.1310
    host4120xd865-0.0202

    bucket host4 (straw2), r = 0 winner: osd.10

    ItemWeightu = hash₃(x, id, r) & 0xffffdraw ≈ log₂((u+1)/2¹⁶) / w
    osd.940x7431-0.2849
    osd.1040xd76a-0.0623
    osd.1140x4323-0.4827
    Replica 1 → osd.8

    bucket default (straw2), r = 1 winner: host3

    ItemWeightu = hash₃(x, id, r) & 0xffffdraw ≈ log₂((u+1)/2¹⁶) / w
    host1120x66bf-0.1098
    host2120xecce-0.0094
    host3120xf3e0-0.0058
    host4120xc1f1-0.0334

    bucket host3 (straw2), r = 1 winner: osd.8

    ItemWeightu = hash₃(x, id, r) & 0xffffdraw ≈ log₂((u+1)/2¹⁶) / w
    osd.640xdc72-0.0539
    osd.740x602c-0.3531
    osd.840xebe4-0.0295
    Replica 2 → osd.4

    bucket default (straw2), r = 2 winner: host4

    ItemWeightu = hash₃(x, id, r) & 0xffffdraw ≈ log₂((u+1)/2¹⁶) / w
    host1120xb671-0.0407
    host2120xaa01-0.0492
    host3120x25f6-0.2295
    host4120xb747-0.0402

    ✗ host4 was already chosen (a collision); try again with r=3.

    bucket default (straw2), r = 3 winner: host2

    ItemWeightu = hash₃(x, id, r) & 0xffffdraw ≈ log₂((u+1)/2¹⁶) / w
    host1120x6a2a-0.1058
    host2120xf3ba-0.0059
    host3120x6e78-0.1010
    host4120x8486-0.0792

    bucket host2 (straw2), r = 3 winner: osd.4

    ItemWeightu = hash₃(x, id, r) & 0xffffdraw ≈ log₂((u+1)/2¹⁶) / w
    osd.340x2947-0.6582
    osd.440xce92-0.0774
    osd.540x7ad3-0.2649
  5. 5Up set, acting set and primary

    raw (CRUSH) = [10,8,4]
    up = [10,8,4] · acting = [10,8,4] · primary = osd.10

    CRUSH 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.

AlgorithmReplicas movedLeast neededObjects affected
straw2 current31.7% +5.5%26.1%78.4%
straw31.7% +5.5%26.1%78.4%
list43.9% +15.8%28.1%92.5%
tree46.6% +21.8%24.8%94.0%
uniform76.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 names
A fixed snapshot of the simulator; the interactive version is in the web edition's lab. Interactive lab: From object name to OSD