Files
2nd/10_Wiki/Topic_Programming/DevOps_and_Security/Cheneys Algorithm.md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

4.6 KiB
Raw Blame History

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-cheneys-algorithm Cheney's Algorithm 10_Wiki/Topics verified self
Cheney GC
Semi-space Collector
Copying GC
none A 0.9 applied
gc
memory
algorithm
runtime
2026-05-10 pending
language framework
C/Rust runtime/GC

Cheney's Algorithm

매 한 줄

"매 stop-and-copy GC 의 BFS-style two-finger traversal". 1970년 C.J. Cheney 가 제시한 copying garbage collector 의 표준 algorithm — recursion 없이 queue-style 로 live object 를 from-space 에서 to-space 로 evacuate. 매 modern V8/SpiderMonkey young generation, OCaml minor heap, MLton 의 baseline.

매 핵심

매 semi-space 구조

  • Heap 을 두 개의 equal-sized region 으로 split: from-space, to-space.
  • Allocation 은 from-space 의 bump pointer 만 증가.
  • GC 시 live object 를 to-space 로 copy 후 role swap.

매 two pointers

  • scan: to-space 에서 아직 children 추적 안 한 boundary.
  • free: to-space 의 next allocation slot.
  • scan == free 이면 traversal 종료.

매 응용

  1. V8 young-gen scavenger (Node.js, Chrome).
  2. OCaml minor heap collection.
  3. SBCL, MLton 의 default GC.

💻 패턴

Core Cheney loop (C)

void* to_space; size_t scan, free_;

void* copy(void* obj) {
    if (is_forwarded(obj)) return forward_addr(obj);
    size_t sz = size_of(obj);
    void* dst = (char*)to_space + free_;
    memcpy(dst, obj, sz);
    set_forward(obj, dst);
    free_ += sz;
    return dst;
}

void cheney_gc(void** roots, size_t n) {
    free_ = scan = 0;
    for (size_t i = 0; i < n; i++) roots[i] = copy(roots[i]);
    while (scan < free_) {
        void* obj = (char*)to_space + scan;
        for_each_pointer_field(obj, p) { *p = copy(*p); }
        scan += size_of(obj);
    }
    swap(from_space, to_space);
}

Forwarding pointer trick

// Object header overlap: live header OR forwarding pointer.
struct header { uintptr_t tag_or_fwd; };
#define IS_FWD(h) ((h)->tag_or_fwd & 1)
#define FWD_PTR(h) ((void*)((h)->tag_or_fwd & ~1))
#define SET_FWD(h, dst) ((h)->tag_or_fwd = (uintptr_t)(dst) | 1)

Allocation (post-GC)

void* alloc(size_t sz) {
    if (free_ + sz > SEMI_SIZE) cheney_gc(roots, n_roots);
    if (free_ + sz > SEMI_SIZE) abort(); // OOM
    void* p = (char*)to_space + free_;
    free_ += sz;
    return p;
}

V8-style scavenger (simplified)

void Scavenger::Process() {
    while (!worklist_.empty()) {
        HeapObject obj = worklist_.Pop();
        obj->IterateBody(this);  // visits each pointer field
    }
}
void Scavenger::VisitPointer(Object** slot) {
    HeapObject obj = HeapObject::cast(*slot);
    if (Heap::InFromSpace(obj)) {
        HeapObject target = EvacuateObject(obj);
        *slot = target;
    }
}

Generational tweak

// Young gen uses Cheney; old gen uses mark-sweep.
// Promotion: if object survives N scavenges, copy to old-gen instead of to-space.
if (age(obj) >= PROMOTION_THRESHOLD) dst = old_gen_alloc(sz);
else dst = (char*)to_space + free_;

매 결정 기준

상황 Approach
Short-lived allocation 多 Cheney (semi-space) — fast bump alloc
Large heap, low live ratio Cheney 우수 (cost ∝ live, not heap)
Mostly-live mature data Mark-sweep / mark-compact
Real-time constraints Incremental / concurrent GC (Shenandoah, ZGC)
Memory tight (mobile) Mark-sweep (no 2× overhead)

기본값: Young generation 에 Cheney, old generation 에 mark-compact (generational hypothesis).

🔗 Graph

🤖 LLM 활용

언제: GC 설명, runtime internals 분석, language implementation 설계 시. 언제 X: Application-level memory tuning (use language-specific profiler 대신).

안티패턴

  • Naive recursive copy: stack overflow 가능 — Cheney 의 queue 방식 사용.
  • Forgetting forward check: 동일 object 두 번 copy → 데이터 corrupt.
  • Pointer 누락: stack/register/global root scan 빠짐 → dangling pointer.
  • Pinning ignored: native pointer 가 from-space object 가리키는 동안 GC → crash.

🧪 검증 / 중복

  • Verified (Cheney 1970 CACM paper, V8/SpiderMonkey source).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — Cheney GC algorithm 의 BFS copy + V8 scavenger 패턴