Files
hakmem/core/box/free_remote_box.c
Moe Charm (CI) 25d963a4aa Code Cleanup: Remove false positives, redundant validations, and reduce verbose logging
Following the C7 stride upgrade fix (commit 23c0d9541), this commit performs
comprehensive cleanup to improve code quality and reduce debug noise.

## Changes

### 1. Disable False Positive Checks (tiny_nextptr.h)
- **Disabled**: NXT_MISALIGN validation block with `#if 0`
- **Reason**: Produces false positives due to slab base offsets (2048, 65536)
  not being stride-aligned, causing all blocks to appear "misaligned"
- **TODO**: Reimplement to check stride DISTANCE between consecutive blocks
  instead of absolute alignment to stride boundaries

### 2. Remove Redundant Geometry Validations

**hakmem_tiny_refill_p0.inc.h (P0 batch refill)**
- Removed 25-line CARVE_GEOMETRY_FIX validation block
- Replaced with NOTE explaining redundancy
- **Reason**: Stride table is now correct in tiny_block_stride_for_class(),
  defense-in-depth validation adds overhead without benefit

**ss_legacy_backend_box.c (legacy backend)**
- Removed 18-line LEGACY_FIX_GEOMETRY validation block
- Replaced with NOTE explaining redundancy
- **Reason**: Shared_pool validates geometry at acquisition time

### 3. Reduce Verbose Logging

**hakmem_shared_pool.c (sp_fix_geometry_if_needed)**
- Made SP_FIX_GEOMETRY logging conditional on `!HAKMEM_BUILD_RELEASE`
- **Reason**: Geometry fixes are expected during stride upgrades,
  no need to log in release builds

### 4. Verification
- Build:  Successful (LTO warnings expected)
- Test:  10K iterations (1.87M ops/s, no crashes)
- NXT_MISALIGN false positives:  Eliminated

## Files Modified
- core/tiny_nextptr.h - Disabled false positive NXT_MISALIGN check
- core/hakmem_tiny_refill_p0.inc.h - Removed redundant CARVE validation
- core/box/ss_legacy_backend_box.c - Removed redundant LEGACY validation
- core/hakmem_shared_pool.c - Made SP_FIX_GEOMETRY logging debug-only

## Impact
- **Code clarity**: Removed 43 lines of redundant validation code
- **Debug noise**: Reduced false positive diagnostics
- **Performance**: Eliminated overhead from redundant geometry checks
- **Maintainability**: Single source of truth for geometry validation

🧹 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 23:00:24 +09:00

39 lines
1.7 KiB
C

#include <stdio.h>
#include <stdatomic.h>
#include "free_remote_box.h"
#include "free_publish_box.h"
#include "hakmem_tiny.h"
#include "hakmem_tiny_integrity.h" // HAK_CHECK_CLASS_IDX
int tiny_free_remote_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* ptr, uint32_t my_tid) {
extern _Atomic uint64_t g_free_remote_box_calls;
atomic_fetch_add_explicit(&g_free_remote_box_calls, 1, memory_order_relaxed);
if (!(ss && ss->magic == SUPERSLAB_MAGIC)) return 0;
if (slab_idx < 0 || slab_idx >= ss_slabs_capacity(ss)) return 0;
(void)my_tid;
// BUGFIX: Decrement used BEFORE remote push to maintain visibility consistency
// Remote push uses memory_order_release, so drainer must see updated used count
uint8_t cls_raw = meta ? meta->class_idx : 0xFFu;
HAK_CHECK_CLASS_IDX((int)cls_raw, "tiny_free_remote_box");
if (__builtin_expect(cls_raw >= TINY_NUM_CLASSES, 0)) {
static _Atomic int g_remote_push_cls_oob = 0;
if (atomic_fetch_add_explicit(&g_remote_push_cls_oob, 1, memory_order_relaxed) == 0) {
fprintf(stderr,
"[REMOTE_PUSH_CLASS_OOB] ss=%p slab_idx=%d meta=%p cls=%u ptr=%p\n",
(void*)ss, slab_idx, (void*)meta, (unsigned)cls_raw, ptr);
}
return 0;
}
meta->used--;
int transitioned = ss_remote_push(ss, slab_idx, ptr); // ss_active_dec_one() called inside
// ss_active_dec_one(ss); // REMOVED: Already called inside ss_remote_push()
if (transitioned) {
// Phase 12: use per-slab class for publish metadata
uint8_t cls = (meta && meta->class_idx < TINY_NUM_CLASSES) ? meta->class_idx : 0;
tiny_free_publish_remote_transition((int)cls, ss, slab_idx);
return 1;
}
return 0;
}