# CephFS subtrees and MDS pinning

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

[Interactive lab](lab.html)CephFS subtrees and MDS pinning
In the book: [Chapter 6](06-cephfs.html#sec-06-2-5)
LabCephFS subtrees and MDS pinningSplit /home, /projects and /scratch over MDS ranks: change explicit pins and their inheritance, distributed ephemeral pins and random pins, and see which subtrees max_mds moves.**3**active ranks**8**dirfrags in /home**20 / 8**most / fewest directories**–**paths moved by the last editDirectories of the example tree on each rank; the number next to each path has that rank's colour. Orange means the path changed rank after the last edit.0`/` root0`/home` distributed parentuser01101*user02000*user03010*user04011*user05100*user06101*user07010*user08111*user09100*user10011*user11111*user12111*user13101*user14110*user15000*user16111*user17101*user18011*user19000*user20011*user21101*user22001*user23000*user24000*1`/projects` explicit pin1`/projects/alpha` inherited pin1`/projects/beta` inherited pin1`/projects/gamma` inherited pin0`/scratch` with parent0`/scratch/job001` with parent0`/scratch/job002` with parent0`/scratch/job003` with parent0`/scratch/job004` with parent0`/scratch/job005` with parent0`/scratch/job006` with parent0`/scratch/job007` with parent0`/scratch/job008` with parent0`/scratch/job009` with parent0`/scratch/job010` with parent0`/scratch/job011` with parent0`/scratch/job012` with parent`ceph fs set cephfs max_mds 3
setfattr -n ceph.dir.pin.distributed -v 1 /mnt/cephfs/home
setfattr -n ceph.dir.pin -v 1 /mnt/cephfs/projects
setfattr -n ceph.dir.pin.random -v 0.5 /mnt/cephfs/scratch`frag bits = ⌈log2(factor × max_mds)⌉ = 3 · child → frag by ceph_str_hash_rjenkins(name) · rank = hash_into_rank_bucket(ino(/home), frag) = jump_hash(rjhash64(rjhash64(ino) + rjhash64(frag)), max_mds)mds_export_ephemeral_random_max defaults to only 0.01; even ceph.dir.pin.random=0.5 selects no more than 1% of directories unless you change that cap. A closer explicit pin overrides an inherited pin. More max_mds needs enough standbys for the new ranks, and splitting dirfrags can cause more movement than the jump hash alone (chapter 6).Follows:`src/mds/MDCache.cc :: MDCache::hash_into_rank_bucket; src/include/hash.h :: rjhash64` rjhash64 and a jump consistent hash for the rank`src/mds/CInode.cc :: CInode::get_export_pin, get_ephemeral_rand, maybe_ephemeral_rand` the closest pin policy and the random probability`src/mds/MDBalancer.cc :: handle_export_pins; src/mds/MDCache.cc :: handle_mdsmap (export_ephemeral_dist_frag_bits)` exporting and the dirfrag split floor for distributed pins`src/include/ceph_frag.h :: ceph_frag_make, ceph_frag_contains_value; src/mds/CInode.cc :: hash_dentry_name` dentry name to its parent dirfrag`src/common/options/mds.yaml.in :: mds_export_ephemeral_distributed (true), mds_export_ephemeral_distributed_factor (2), mds_export_ephemeral_random (true), mds_export_ephemeral_random_max (0.01)` the ephemeral pin defaultsA fixed snapshot of the simulator; the interactive version is in the web edition's lab. [Interactive lab: CephFS subtrees and MDS pinning](lab-mdspin.html)The interactive version needs JavaScript; this is a fixed snapshot.
