Skip to content

INTERNAL: Unify elem_item struct layout across collection types#971

Merged
jhpark816 merged 1 commit into
naver:developfrom
zhy2on:internal/unify-elem-item-layout
May 13, 2026
Merged

INTERNAL: Unify elem_item struct layout across collection types#971
jhpark816 merged 1 commit into
naver:developfrom
zhy2on:internal/unify-elem-item-layout

Conversation

@zhy2on
Copy link
Copy Markdown
Collaborator

@zhy2on zhy2on commented May 13, 2026

🔗 Related Issue

⌨️ What I did

  • hash tree 공통 모듈 추출 전 collection elem_item 레이아웃 통일을 먼저 진행하였습니다.
  • btree, map에서 uint16_t로 사용하던 nbytes를 list, set에도 동일하게 적용하여 모든 elem_item의 nbytes 타입을 uint16_t로 통일하였습니다.
  • 암묵적 패딩 자리를 reserved 필드로 명시적으로 표현하였습니다.
  • elem_item의 필드 순서를 공통 필드(refcount, slabs_clsid, status) → 길이 필드(nbytes, nfield 등) → 포인터/해시 필드(next, hval) 순서로 통일하였습니다.
  • 작업 중 char value[]unsigned char data[] 선언 방식의 차이를 확인하였습니다.
    • list, set은 값 자체를 저장하는 용도로 대소 비교가 필요 없어 char value[]로 선언하였으며,
    • map, btree는 내부에서 field/bkey 비교가 필요하기 때문에 sign extension을 피하기 위해 unsigned char data[]로 선언하고 변수명도 data로 구분하고 있었습니다.
    • 이후 구현하는 element들도 경우에 맞게 선언하면 될 것 같습니다.

@zhy2on zhy2on self-assigned this May 13, 2026
Copy link
Copy Markdown
Collaborator

@jhpark816 jhpark816 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 완료


elem->refcount = 0;
elem->nbytes = nbytes;
elem->nbytes = (uint16_t)nbytes;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

질문입니다.
주어진 nbytes 값이 65536 이하임이 보장되나요?
list element 쪽도 마찬가지입니다.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memcached.c의 프로토콜 파싱 단계에서 vlen > settings.max_element_bytes 체크로 검증하고 있으며, settings.max_element_bytes는 엔진 초기화 시 MAXIMUM_MAX_ELEMENT_BYTES(32KB) 이하로 강제됩니다. 따라서 collection 내부까지 내려오는 nbytes는 항상 uint16_t 범위 내임이 보장됩니다.

  • 32 * 1024 = 32,768
  • uint16_t (0~65,535)
// item_base.h
#define MAXIMUM_MAX_ELEMENT_BYTES (32*1024)

@jhpark816 jhpark816 merged commit b5d548c into naver:develop May 13, 2026
1 check passed
@zhy2on zhy2on deleted the internal/unify-elem-item-layout branch May 15, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants