slab_size

The `slab_size` directive sets the size for memory allocation slabs used in the Proxy-Wasm module, optimizing memory management for Wasm modules.

Syntaxslab_size size;
Defaultnone
Context
Arguments1

Description

The slab_size directive configures the slab allocator's memory management for Proxy-Wasm modules in NGINX. By specifying a slab size, administrators can control how chunks of memory are allocated for WebAssembly instances, which can lead to improved performance and reduced fragmentation of memory in the server's runtime environment. This is particularly beneficial when running multiple Wasm modules or filters that may create several instances, as it allows for more efficient use of available memory resources.

When slab_size is set, NGINX allocates memory in predefined "slabs" of the specified size, which optimizes allocation speeds and reduces memory overhead. Slabs help in managing memory chunks that are of a similar size, thus enabling quicker allocation and deallocation. Suitable slab sizes can minimize waste and maximize throughput, especially under load conditions where rapid instantiation of Wasm functions or modules may occur. This can have a marked impact on the overall performance of proxy operations or dynamic processing done via the Wasm layer.

Essentially, the directive accepts a single argument representing the size in bytes, allowing users to tailor the configuration to match their expected application size and usage patterns. Administrators should test different slab sizes based on expected workloads to determine the optimal setting for their particular use case.

Config Example

wasm {
    slab_size 16k;
}

Make sure the slab size is appropriate for your workload; too small may lead to frequent allocations, while too large may waste memory.

Changing the slab size may require restarting the NGINX service to take effect.

Test performance impacts before and after changing the slab size in production.

← Back to all directives