tiny.gpalloc.cache
Defined in tiny.gpalloc.
API (33)
Actions
Public operations.
PointerBinThreadCache.resetcpuCountThreadCacheActiveLimitdefaultThreadCacheActiveLimitloadThreadCacheloadThreadCacheForAllocFastPathloadThreadCacheForSmallFastPathlocalThreadCacheBinCountpopLocalThreadCacheBinpushLocalThreadCacheBinstoreThreadCachethreadClassLimitthreadDrainCountthreadExtraCapacitythreadExtraClassIndexthreadRefillCounttransferClassLimit
Types and contracts
Public types and contracts.
Values and defaults
Public values and defaults.
refill_maxtarget_bytesthread_capacitythread_extra_bin_capacitythread_extra_class_capacitiesthread_extra_class_countthread_extra_class_refill_maxthread_extra_class_sizesthread_fixed_class_countthread_preload_class_refill_maxthread_preload_class_sizethread_tight_class_capacitythread_tight_class_sizetransfer_capacitytransfer_target_bytes
Source
Source: lib/gpalloc/src/cache/local.zig:19
pub const ThreadCache = struct { owner: ?*anyopaque = null, storage_owner: ?*anyopaque = null, next_retained: ?*ThreadCache = null, bins: [thread.fixed_class_count]ThreadCacheBin = @as([thread.fixed_class_count]ThreadCacheBin, @splat(.{})), extra_bins: [thread.extra_class_count]ExtraThreadCacheBin = @as([thread.extra_class_count]ExtraThreadCacheBin, @splat(.{})), linked_heads: [linked_class_count]?*FreeNode = @as([linked_class_count]?*FreeNode, @splat(null)), linked_counts: [linked_class_count]u16 = @as([linked_class_count]u16, @splat(0)), pub fn reset(cache: *ThreadCache, owner: *anyopaque) void { cache.owner = owner; cache.storage_owner = owner; cache.next_retained = null; for (&cache.bins) |*bin| bin.count = 0; for (&cache.extra_bins) |*bin| bin.count = 0; @memset(&cache.linked_heads, null); @memset(&cache.linked_counts, 0); }};Source: lib/gpalloc/src/cache/local.zig:117
pub fn cpuCountThreadCacheActiveLimit() usize { return sys_thread.cpuCount();}Source: lib/gpalloc/src/cache/local.zig:121
pub fn defaultThreadCacheActiveLimit() usize { return cpuCountThreadCacheActiveLimit();}Source: lib/gpalloc/src/cache/local.zig:40
pub inline fn loadThreadCache() ?*ThreadCache { return @ptrCast(@alignCast(tls.load()));}Source: lib/gpalloc/src/cache/local.zig:48
pub inline fn loadThreadCacheForAllocFastPath() ?*ThreadCache { return loadThreadCache();}Source: lib/gpalloc/src/cache/local.zig:44
pub inline fn loadThreadCacheForSmallFastPath() ?*ThreadCache { return loadThreadCache();}Source: lib/gpalloc/src/cache/local.zig:56
pub inline fn localThreadCacheBinCount(cache: *const ThreadCache, class_index: usize) usize { if (class_index < thread.fixed_class_count) { var count: usize = cache.bins[class_index].count; if (threadExtraClassIndex(class_index)) |extra_index| { count += cache.extra_bins[extra_index].count; } return count; } return cache.linked_counts[class_index - thread.fixed_class_count];}Source: lib/gpalloc/src/cache/local.zig:67
pub inline fn popLocalThreadCacheBin(cache: *ThreadCache, class_index: usize) ?[*]u8 { if (class_index < thread.fixed_class_count) { if (cache.bins[class_index].pop()) |ptr| return ptr; if (threadExtraClassIndex(class_index)) |extra_index| { if (cache.extra_bins[extra_index].pop()) |ptr| return ptr; } return null; } const linked_index = class_index - thread.fixed_class_count; const node = cache.linked_heads[linked_index] orelse return null; cache.linked_heads[linked_index] = node.next; cache.linked_counts[linked_index] -= 1; return @ptrCast(node);}Source: lib/gpalloc/src/cache/local.zig:83
pub inline fn pushLocalThreadCacheBin( cache: *ThreadCache, class_index: usize, ptr: [*]u8, cache_limit: u16,) bool { if (class_index < thread.fixed_class_count) { const base_limit = @min(thread.capacity, cache_limit); if (cache.bins[class_index].push(ptr, base_limit)) return true; const extra_limit = cache_limit - base_limit; if (extra_limit == 0) return false; const extra_index = threadExtraClassIndex(class_index) orelse return false; return cache.extra_bins[extra_index].push(ptr, extra_limit); } const linked_index = class_index - thread.fixed_class_count; const count = cache.linked_counts[linked_index]; if (count >= cache_limit) return false; const node: *FreeNode = @ptrCast(@alignCast(ptr)); node.* = .{ .next = cache.linked_heads[linked_index] }; cache.linked_heads[linked_index] = node; cache.linked_counts[linked_index] = count + 1; return true;}Source: lib/gpalloc/src/cache/local.zig:52
pub inline fn storeThreadCache(cache: ?*ThreadCache) void { tls.store(cache);}Source: lib/gpalloc/src/cache/pointer.zig:3
pub fn PointerBin(comptime capacity: u16) type { return struct { count: usize = 0, items: [capacity][*]u8 = undefined, const Self = @This(); pub fn pop(bin: *Self) ?[*]u8 { if (bin.count == 0) return null; bin.count -= 1; return bin.items[bin.count]; } pub fn push(bin: *Self, ptr: [*]u8, limit: usize) bool { std.debug.assert(limit <= capacity); if (bin.count >= limit) return false; bin.items[bin.count] = ptr; bin.count += 1; return true; } };}Source: lib/gpalloc/src/cache/thread.zig:4
pub const capacity: u16 = 960;Source: lib/gpalloc/src/cache/thread.zig:21
pub fn classLimit(class_index: usize) u16 { return class_limits[class_index];}Source: lib/gpalloc/src/cache/thread.zig:60
pub fn drainCount(cache_limit: u16) usize { return @max(@as(usize, 1), @as(usize, cache_limit) / 2);}Source: lib/gpalloc/src/cache/thread.zig:42
pub fn extraCapacity(class_index: usize) u16 { return if (extraClassIndex(class_index)) |extra_index| extra_class_capacities[extra_index] else 0;}Source: lib/gpalloc/src/cache/thread.zig:46
pub fn extraClassIndex(class_index: usize) ?usize { inline for (extra_class_indices, 0..) |extra_class_index, extra_index| { if (class_index == extra_class_index) return extra_index; } return null;}Source: lib/gpalloc/src/cache/thread.zig:5
pub const extra_bin_capacity: u16 = 1088;Source: lib/gpalloc/src/cache/thread.zig:13
pub const extra_class_capacities = [_]u16{ 1088, 405 };Source: lib/gpalloc/src/cache/thread.zig:15
pub const extra_class_refill_max: usize = 512;Source: lib/gpalloc/src/cache/thread.zig:12
pub const extra_class_sizes = [_]usize{ 32, 48 };Source: lib/gpalloc/src/cache/thread.zig:16
pub const fixed_class_count: usize = 20;Source: lib/gpalloc/src/cache/thread.zig:11
pub const preload_class_refill_max: usize = 512;Source: lib/gpalloc/src/cache/thread.zig:10
pub const preload_class_size: usize = 96;Source: lib/gpalloc/src/cache/thread.zig:53
pub fn refillCount(class_index: usize) usize { const cache_limit = classLimit(class_index); if (extraClassIndex(class_index) != null) return @min(extra_class_refill_max, cache_limit); if (size_class.size(class_index) == preload_class_size) return @min(preload_class_refill_max, cache_limit); return @min(refill_max, cache_limit);}Source: lib/gpalloc/src/cache/thread.zig:7
pub const refill_max: usize = 256;Source: lib/gpalloc/src/cache/thread.zig:6
pub const target_bytes: usize = 64 * 1024;Source: lib/gpalloc/src/cache/thread.zig:9
pub const tight_class_capacity: u16 = 512;Source: lib/gpalloc/src/cache/thread.zig:8
pub const tight_class_size: usize = 80;Source: lib/gpalloc/src/cache/transfer.zig:4
pub const capacity: u16 = 2048;Source: lib/gpalloc/src/cache/transfer.zig:7
pub fn classLimit(class_index: usize) u16 { const class_size = size_class.size(class_index); const by_bytes = @max(@as(usize, 1), target_bytes / class_size); return @intCast(@min(capacity, by_bytes));}Source: lib/gpalloc/src/cache/transfer.zig:5
pub const target_bytes: usize = 2 * 1024 * 1024;Source: lib/gpalloc/src/cache/root.zig
const local = @import("local.zig");const pointer = @import("pointer.zig");const thread = @import("thread.zig");const transfer = @import("transfer.zig");pub const thread_capacity = thread.capacity;pub const thread_extra_bin_capacity = thread.extra_bin_capacity;pub const transfer_capacity = transfer.capacity;pub const target_bytes = thread.target_bytes;pub const transfer_target_bytes = transfer.target_bytes;pub const refill_max = thread.refill_max;pub const thread_tight_class_size = thread.tight_class_size;pub const thread_tight_class_capacity = thread.tight_class_capacity;pub const thread_preload_class_size = thread.preload_class_size;pub const thread_preload_class_refill_max = thread.preload_class_refill_max;pub const thread_extra_class_sizes = thread.extra_class_sizes;pub const thread_extra_class_capacities = thread.extra_class_capacities;pub const thread_extra_class_count = thread.extra_class_count;pub const thread_extra_class_refill_max = thread.extra_class_refill_max;pub const thread_fixed_class_count = thread.fixed_class_count;pub const PointerBin = pointer.PointerBin;pub const ThreadCache = local.ThreadCache;pub const cpuCountThreadCacheActiveLimit = local.cpuCountThreadCacheActiveLimit;pub const defaultThreadCacheActiveLimit = local.defaultThreadCacheActiveLimit;pub const loadThreadCache = local.loadThreadCache;pub const loadThreadCacheForAllocFastPath = local.loadThreadCacheForAllocFastPath;pub const loadThreadCacheForSmallFastPath = local.loadThreadCacheForSmallFastPath;pub const localThreadCacheBinCount = local.localThreadCacheBinCount;pub const popLocalThreadCacheBin = local.popLocalThreadCacheBin;pub const pushLocalThreadCacheBin = local.pushLocalThreadCacheBin;pub const storeThreadCache = local.storeThreadCache;pub const threadClassLimit = thread.classLimit;pub const threadDrainCount = thread.drainCount;pub const threadExtraCapacity = thread.extraCapacity;pub const threadExtraClassIndex = thread.extraClassIndex;pub const threadRefillCount = thread.refillCount;pub const transferClassLimit = transfer.classLimit;Source: lib/gpalloc/src/root.zig:38
pub const cache = @import("cache/root.zig");Source: lib/gpalloc/src/cache/thread.zig:14
pub const extra_class_count: usize = extra_class_sizes.len;Complete caller list for cache.loadThreadCache
11 direct callers.
lib.gpalloc.src.allocator.ActiveThreadCacheLimitWorker.allocateAndFree[function] — private source atlib/gpalloc/src/allocator.zig:1055in nearest public ownerlib.gpalloc.src.allocatorlib.gpalloc.src.allocator.GpAllocator.currentThreadCache[method] — private source atlib/gpalloc/src/allocator.zig:602in nearest public ownerlib.gpalloc.src.allocatorlib.gpalloc.src.allocator.GpAllocator.currentThreadCacheSlow[method] — private source atlib/gpalloc/src/allocator.zig:616in nearest public ownerlib.gpalloc.src.allocatorlib.gpalloc.src.allocator.GpAllocator.flushCurrentThreadCache[method] — private source atlib/gpalloc/src/allocator.zig:634in nearest public ownerlib.gpalloc.src.allocatorlib.gpalloc.src.allocator.GpAllocator.releaseCurrentThreadCache[method] — private source atlib/gpalloc/src/allocator.zig:640in nearest public ownerlib.gpalloc.src.allocatorlib.gpalloc.src.allocator.GpAllocator.releaseThreadCache[method] — private source atlib/gpalloc/src/allocator.zig:659in nearest public ownerlib.gpalloc.src.allocatorlib.gpalloc.src.allocator.test_active_thread-cache_limit_falls_back_to_central_bins[function] — test source atlib/gpalloc/src/allocator.zig:1577in nearest public ownerlib.gpalloc.src.allocatorlib.gpalloc.src.allocator.test_public_thread-cache_flush_releases_heap-owned_cache_storage[function] — test source atlib/gpalloc/src/allocator.zig:1537in nearest public ownerlib.gpalloc.src.allocatorlib.gpalloc.src.allocator.threadCacheExitDestructor[function] — private source atlib/gpalloc/src/allocator.zig:87in nearest public ownerlib.gpalloc.src.allocatortiny.gpalloc.cache.loadThreadCacheForAllocFastPath[function] atlib/gpalloc/src/cache/local.zig:48tiny.gpalloc.cache.loadThreadCacheForSmallFastPath[function] atlib/gpalloc/src/cache/local.zig:44
Audit
| Definitions | 34 |
|---|---|
| Public names | 34 |
| Members | 7 |
| Version | 26.7.0 |
| Revision | daab053ee433 |