Skip to main content

struct-layout-analysis

Measure and fix C struct layout in BIND 9 — pahole on the build's DWARF for sizes, padding holes, and cacheline boundaries, plus the house cacheline-padding idiom. Use when asked about struct size, padding, false sharing, or when adding/reordering members in hot structures.

소스 정보

저장소
isc-projects/bind9
최근 소스 활동
2026년 7월 14일 11:40
감지된 SKILL.md 언어
영어
스타
780
포크
187

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
struct-layout-analysis
description
Measure and fix C struct layout in BIND 9 — pahole on the build's DWARF for sizes, padding holes, and cacheline boundaries, plus the house cacheline-padding idiom. Use when asked about struct size, padding, false sharing, or when adding/reordering members in hot structures.
# Struct layout: measure with pahole, pad with a multiplier ## Measuring — pahole, never throwaway sizeof programs The developer build (`-Og -ggdb`) already carries DWARF; read it instead of compiling sizeof/offsetof snippets: ```sh pahole -C <struct_name> build/lib/dns/libdns*.so.p/<file>.c.o pahole --holes -C <struct_name> <object-or-binary> ``` pahole prints member offsets, padding holes, total size, and cacheline boundaries — complete layout information the compiler already computed, with no boilerplate to write. Any object file under `build/` or the final binary works as input. ## Padding to cachelines — union arm with a plain multiplier Pad a struct to a whole number of cache lines with a union arm sized by a plain multiplier, always paired with a static assert: ```c struct foo { union { struct { /* members */ }; uint8_t __padding[ISC_OS_CACHELINE_SIZE * 6]; }; }; STATIC_ASSERT(sizeof(struct foo) % ISC_OS_CACHELINE_SIZE == 0, "struct foo size must be a multiple of the cacheline size"); ``` Pick the smallest `n` that fits; when members outgrow the arm to a non-multiple size, the STATIC_ASSERT fires and prompts a bump of `n`. Do NOT use the enumerated-sizeof trailing formula `uint8_t __padding[CACHELINE - (sizeof(a) + sizeof(b) + ...) % CACHELINE]` (the historical qpzone style): it must enumerate every member's sizeof, so adding a member silently miscounts unless the formula is updated in lockstep. The multiplier form has no such coupling and is easier to read.
GitHub에서 보기