25 lines
1.0 KiB
C
25 lines
1.0 KiB
C
|
|
// tiny_remote_bg.h - Background remote-drain coalescer (step API)
|
||
|
|
#pragma once
|
||
|
|
#include <stdatomic.h>
|
||
|
|
#include "hakmem_tiny.h"
|
||
|
|
#include "hakmem_tiny_remote_target.h"
|
||
|
|
|
||
|
|
// Drain up to `budget` remote-target slabs for a class.
|
||
|
|
// Coalesces remote queues into freelists under ownership, then advertises via Ready.
|
||
|
|
// tiny_remote_drain_locked is defined in hakmem_tiny_remote.inc within the same TU
|
||
|
|
static void tiny_remote_drain_locked(struct TinySlab* slab);
|
||
|
|
|
||
|
|
static inline void tiny_remote_bg_drain_step(int class_idx, int budget) {
|
||
|
|
if (budget <= 0) return;
|
||
|
|
for (int n = 0; n < budget; n++) {
|
||
|
|
TinySlab* slab = remote_target_pop(class_idx);
|
||
|
|
if (!slab) break;
|
||
|
|
// Drain under per-class lock (matches background loop semantics)
|
||
|
|
pthread_mutex_t* lock = &g_tiny_class_locks[class_idx].m;
|
||
|
|
pthread_mutex_lock(lock);
|
||
|
|
tiny_remote_drain_locked(slab);
|
||
|
|
pthread_mutex_unlock(lock);
|
||
|
|
// Note: Ready ring is Superslab-specific; TinySlab path does not push Ready hints.
|
||
|
|
}
|
||
|
|
}
|