net/ceph/crush/mapper.c
Source file repositories/reference/linux-study-clean/net/ceph/crush/mapper.c
File Facts
- System
- Linux kernel
- Corpus path
net/ceph/crush/mapper.c- Extension
.c- Size
- 26626 bytes
- Lines
- 1099
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/string.hlinux/slab.hlinux/bug.hlinux/kernel.hlinux/crush/crush.hlinux/crush/hash.hlinux/crush/mapper.hcrush_compat.hcrush.hhash.hmapper.hcrush_ln_table.h
Detected Declarations
function crush_find_rulefunction bucket_perm_choosefunction bucket_uniform_choosefunction bucket_list_choosefunction heightfunction leftfunction rightfunction terminalfunction bucket_tree_choosefunction bucket_straw_choosefunction crush_lnfunction bucket_straw2_choosefunction crush_bucket_choosefunction is_outfunction crush_choose_firstnfunction crush_choose_indepfunction crush_init_workspacefunction crush_do_rule
Annotated Snippet
if (pr == 0) {
s = crush_hash32_3(bucket->hash, x, bucket->id, 0) %
bucket->size;
work->perm[0] = s;
work->perm_n = 0xffff; /* magic value, see below */
goto out;
}
for (i = 0; i < bucket->size; i++)
work->perm[i] = i;
work->perm_n = 0;
} else if (work->perm_n == 0xffff) {
/* clean up after the r=0 case above */
for (i = 1; i < bucket->size; i++)
work->perm[i] = i;
work->perm[work->perm[0]] = 0;
work->perm_n = 1;
}
/* calculate permutation up to pr */
for (i = 0; i < work->perm_n; i++)
dprintk(" perm_choose have %d: %d\n", i, work->perm[i]);
while (work->perm_n <= pr) {
unsigned int p = work->perm_n;
/* no point in swapping the final entry */
if (p < bucket->size - 1) {
i = crush_hash32_3(bucket->hash, x, bucket->id, p) %
(bucket->size - p);
if (i) {
unsigned int t = work->perm[p + i];
work->perm[p + i] = work->perm[p];
work->perm[p] = t;
}
dprintk(" perm_choose swap %d with %d\n", p, p+i);
}
work->perm_n++;
}
for (i = 0; i < bucket->size; i++)
dprintk(" perm_choose %d: %d\n", i, work->perm[i]);
s = work->perm[pr];
out:
dprintk(" perm_choose %d sz=%d x=%d r=%d (%d) s=%d\n", bucket->id,
bucket->size, x, r, pr, s);
return bucket->items[s];
}
/* uniform */
static int bucket_uniform_choose(const struct crush_bucket_uniform *bucket,
struct crush_work_bucket *work, int x, int r)
{
return bucket_perm_choose(&bucket->h, work, x, r);
}
/* list */
static int bucket_list_choose(const struct crush_bucket_list *bucket,
int x, int r)
{
int i;
for (i = bucket->h.size-1; i >= 0; i--) {
__u64 w = crush_hash32_4(bucket->h.hash, x, bucket->h.items[i],
r, bucket->h.id);
w &= 0xffff;
dprintk("list_choose i=%d x=%d r=%d item %d weight %x "
"sw %x rand %llx",
i, x, r, bucket->h.items[i], bucket->item_weights[i],
bucket->sum_weights[i], w);
w *= bucket->sum_weights[i];
w = w >> 16;
/*dprintk(" scaled %llx\n", w);*/
if (w < bucket->item_weights[i]) {
return bucket->h.items[i];
}
}
dprintk("bad list sums for bucket %d\n", bucket->h.id);
return bucket->h.items[0];
}
/* (binary) tree */
static int height(int n)
{
int h = 0;
while ((n & 1) == 0) {
h++;
n = n >> 1;
}
return h;
Annotation
- Immediate include surface: `linux/string.h`, `linux/slab.h`, `linux/bug.h`, `linux/kernel.h`, `linux/crush/crush.h`, `linux/crush/hash.h`, `linux/crush/mapper.h`, `crush_compat.h`.
- Detected declarations: `function crush_find_rule`, `function bucket_perm_choose`, `function bucket_uniform_choose`, `function bucket_list_choose`, `function height`, `function left`, `function right`, `function terminal`, `function bucket_tree_choose`, `function bucket_straw_choose`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.