Skip to documentation
SLOP

tiny.gpalloc.cache

Reference tiny.gpalloc cache

Defined in tiny.gpalloc.

API (33)

Actions

Public operations.

Types and contracts

Public types and contracts.

Values and defaults

Public values and defaults.

No direct callersNo direct callstiny.gpalloccache
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/gpalloc/src/cache/local.zig:19

zig
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

zig
pub fn cpuCountThreadCacheActiveLimit() usize {    return sys_thread.cpuCount();}
Called byCallsNo direct callstest sourcelib.gpalloc.src.allocatortest: default active thread-cache lim...cachedefaultThreadCacheActiveLimitcachecpuCountThreadCacheActiveLimit
Static calls · unresolved targets: 0 · external targets: 1.

Source: lib/gpalloc/src/cache/local.zig:121

zig
pub fn defaultThreadCacheActiveLimit() usize {    return cpuCountThreadCacheActiveLimit();}
Called byCallsprivate sourcelib.gpalloc.src.allocator.GpAllocatorresolveThreadCacheActiveLimittest sourcelib.gpalloc.src.allocatortest: default active thread-cache lim...cachecpuCountThreadCacheActiveLimitcachedefaultThreadCacheActiveLimit
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/gpalloc/src/cache/local.zig:40

zig
pub inline fn loadThreadCache() ?*ThreadCache {    return @ptrCast(@alignCast(tls.load()));}
Called byCallsNo direct callsprivate sourcelib.gpalloc.src.allocator.ActiveThreadCacheLi...allocateAndFreeprivate sourcelib.gpalloc.src.allocator.GpAllocatorcurrentThreadCacheprivate sourcelib.gpalloc.src.allocator.GpAllocatorcurrentThreadCacheSlowprivate sourcelib.gpalloc.src.allocator.GpAllocatorflushCurrentThreadCacheprivate sourcelib.gpalloc.src.allocator.GpAllocatorreleaseCurrentThreadCache+6 morecacheloadThreadCache
Static calls · unresolved targets: 0 · external targets: 1.

Source: lib/gpalloc/src/cache/local.zig:48

zig
pub inline fn loadThreadCacheForAllocFastPath() ?*ThreadCache {    return loadThreadCache();}
Called byCallsGpAllocatorrawAlloccacheloadThreadCachecacheloadThreadCacheForAllocFastPath
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/gpalloc/src/cache/local.zig:44

zig
pub inline fn loadThreadCacheForSmallFastPath() ?*ThreadCache {    return loadThreadCache();}
Called byCallsprivate sourcelib.gpalloc.src.allocator.GpAllocatorcurrentThreadCacheSmallFastPathGpAllocatorrawFreecacheloadThreadCachecacheloadThreadCacheForSmallFastPath
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/gpalloc/src/cache/local.zig:56

zig
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];}
Called byCallsprivate sourcelib.gpalloc.src.allocator.GpAllocatordrainLocalThreadCacheBinprivate sourcelib.gpalloc.src.allocator.GpAllocatorrefillThreadCacheBintest sourcelib.gpalloc.src.cache.localtest: thread-cache bins size local ov...private sourcelib.gpalloc.src.cache.localthreadExtraClassIndexcachelocalThreadCacheBinCount
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/gpalloc/src/cache/local.zig:67

zig
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);}
Called byCallsprivate sourcelib.gpalloc.src.allocator.GpAllocatorallocSmallThreadCachedprivate sourcelib.gpalloc.src.allocator.GpAllocatorallocSmallThreadCachedSlowprivate sourcelib.gpalloc.src.allocator.GpAllocatordrainLocalThreadCacheBinGpAllocatorrawAllocprivate sourcelib.gpalloc.src.cache.localthreadExtraClassIndexcachepopLocalThreadCacheBin
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/gpalloc/src/cache/local.zig:83

zig
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;}
Called byCallsprivate sourcelib.gpalloc.src.allocator.GpAllocatorfreeSmallThreadCachedprivate sourcelib.gpalloc.src.allocator.GpAllocatorfreeSmallThreadCachedSlowGpAllocatorrawFreeprivate sourcelib.gpalloc.src.allocator.GpAllocatorrefillThreadCacheBinprivate sourcelib.gpalloc.src.allocator.GpAllocatorreserveSmallBlocksForThreadCachetest sourcelib.gpalloc.src.cache.localtest: thread-cache bins size local ov...private sourcelib.gpalloc.src.cache.localthreadExtraClassIndexcachepushLocalThreadCacheBin
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/gpalloc/src/cache/local.zig:52

zig
pub inline fn storeThreadCache(cache: ?*ThreadCache) void {    tls.store(cache);}
Called byCallsNo direct callsprivate sourcelib.gpalloc.src.allocator.GpAllocatorcurrentThreadCacheSlowprivate sourcelib.gpalloc.src.allocator.GpAllocatorreleaseCurrentThreadCacheprivate sourcelib.gpalloc.src.allocator.GpAllocatorreleaseThreadCachecachestoreThreadCache
Static calls · unresolved targets: 0 · external targets: 1.

Source: lib/gpalloc/src/cache/pointer.zig:3

zig
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

zig
pub const capacity: u16 = 960;

Source: lib/gpalloc/src/cache/thread.zig:21

zig
pub fn classLimit(class_index: usize) u16 {    return class_limits[class_index];}
Called byCallsNo direct callstest sourcelib.gpalloc.src.cache.localtest: thread-cache bins size local ov...cachethreadRefillCounttest sourcelib.gpalloc.src.cache.threadtest: extra classes use extra slot ca...test sourcelib.gpalloc.src.cache.threadtest: preload class uses larger refil...test sourcelib.gpalloc.src.cache.threadtest: thread class limits match byte ...test sourcelib.gpalloc.src.cache.threadtest: thread refill counts match clas...cachethreadClassLimit
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/gpalloc/src/cache/thread.zig:60

zig
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

zig
pub fn extraCapacity(class_index: usize) u16 {    return if (extraClassIndex(class_index)) |extra_index| extra_class_capacities[extra_index] else 0;}
Called byCallstest sourcelib.gpalloc.src.cache.localtest: thread-cache bins size local ov...private sourcelib.gpalloc.src.cache.threadslotCapacitytest sourcelib.gpalloc.src.cache.threadtest: extra classes use extra slot ca...cachethreadExtraClassIndexcachethreadExtraCapacity
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/gpalloc/src/cache/thread.zig:46

zig
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;}
Called byCallsNo direct callsprivate sourcelib.gpalloc.src.cache.localbuildPreloadExtraClassLookupprivate sourcelib.gpalloc.src.cache.localthreadExtraClassIndexcachethreadExtraCapacitycachethreadRefillCounttest sourcelib.gpalloc.src.cache.threadtest: extra classes use extra slot ca...test sourcelib.gpalloc.src.cache.threadtest: thread refill counts match clas...cachethreadExtraClassIndex
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/gpalloc/src/cache/thread.zig:5

zig
pub const extra_bin_capacity: u16 = 1088;

Source: lib/gpalloc/src/cache/thread.zig:13

zig
pub const extra_class_capacities = [_]u16{ 1088, 405 };

Source: lib/gpalloc/src/cache/thread.zig:15

zig
pub const extra_class_refill_max: usize = 512;

Source: lib/gpalloc/src/cache/thread.zig:12

zig
pub const extra_class_sizes = [_]usize{ 32, 48 };

Source: lib/gpalloc/src/cache/thread.zig:16

zig
pub const fixed_class_count: usize = 20;

Source: lib/gpalloc/src/cache/thread.zig:11

zig
pub const preload_class_refill_max: usize = 512;

Source: lib/gpalloc/src/cache/thread.zig:10

zig
pub const preload_class_size: usize = 96;

Source: lib/gpalloc/src/cache/thread.zig:53

zig
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);}
Called byCallstest sourcelib.gpalloc.src.cache.threadtest: extra classes use extra slot ca...test sourcelib.gpalloc.src.cache.threadtest: preload class uses larger refil...test sourcelib.gpalloc.src.cache.threadtest: thread refill counts match clas...cachethreadClassLimitcachethreadExtraClassIndexcachethreadRefillCount
Static calls · unresolved targets: 0 · external targets: 1.

Source: lib/gpalloc/src/cache/thread.zig:7

zig
pub const refill_max: usize = 256;

Source: lib/gpalloc/src/cache/thread.zig:6

zig
pub const target_bytes: usize = 64 * 1024;

Source: lib/gpalloc/src/cache/thread.zig:9

zig
pub const tight_class_capacity: u16 = 512;

Source: lib/gpalloc/src/cache/thread.zig:8

zig
pub const tight_class_size: usize = 80;

Source: lib/gpalloc/src/cache/transfer.zig:4

zig
pub const capacity: u16 = 2048;

Source: lib/gpalloc/src/cache/transfer.zig:7

zig
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));}
Called byCallsNo direct callstest sourcelib.gpalloc.src.cache.transfertest: transfer class limits match byt...cachetransferClassLimit
Static calls · unresolved targets: 0 · external targets: 1.

Source: lib/gpalloc/src/cache/transfer.zig:5

zig
pub const target_bytes: usize = 2 * 1024 * 1024;

Source: lib/gpalloc/src/cache/root.zig

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

zig
pub const cache = @import("cache/root.zig");

Source: lib/gpalloc/src/cache/thread.zig:14

zig
pub const extra_class_count: usize = extra_class_sizes.len;

Complete caller list for cache.loadThreadCache

11 direct callers.

Audit

Definitions34
Public names34
Members7
Version26.7.0
Revisiondaab053ee433