Skip to content

Commit ae69c92

Browse files
authored
Allow setting pooling allocation in the C API (#10484)
* Allow setting pooling allocation in the C API * Formatting * Switch to object-style API * Delete function * Add wasmtime_ prefix * More documentation and minor fixes * Update doxygen config to exclude the WASMTIME_POOLING_ALLOCATION_CONFIG_PROP macro.
1 parent 42bb677 commit ae69c92

File tree

8 files changed

+447
-1
lines changed

8 files changed

+447
-1
lines changed

crates/c-api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ cranelift = ['wasmtime/cranelift']
5858
winch = ['wasmtime/winch']
5959
debug-builtins = ['wasmtime/debug-builtins']
6060
wat = ['dep:wat', 'wasmtime/wat']
61+
pooling-allocator = ["wasmtime/pooling-allocator"]
6162
# ... if you add a line above this be sure to change the other locations
6263
# marked WASMTIME_FEATURE_LIST

crates/c-api/artifact/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ default = [
3939
'cranelift',
4040
'winch',
4141
'debug-builtins',
42+
'pooling-allocator',
4243
# ... if you add a line above this be sure to change the other locations
4344
# marked WASMTIME_FEATURE_LIST
4445
]
@@ -60,5 +61,6 @@ gc-null = ["wasmtime-c-api/gc-null"]
6061
cranelift = ["wasmtime-c-api/cranelift"]
6162
winch = ["wasmtime-c-api/winch"]
6263
debug-builtins = ["wasmtime-c-api/debug-builtins"]
64+
pooling-allocator = ["wasmtime-c-api/pooling-allocator"]
6365
# ... if you add a line above this be sure to read the comment at the end of
6466
# `default`

crates/c-api/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const FEATURES: &[&str] = &[
2121
"WINCH",
2222
"DEBUG_BUILTINS",
2323
"WAT",
24+
"POOLING_ALLOCATOR",
2425
];
2526
// ... if you add a line above this be sure to change the other locations
2627
// marked WASMTIME_FEATURE_LIST

crates/c-api/cmake/features.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ feature(async ON)
4444
feature(cranelift ON)
4545
feature(winch ON)
4646
feature(debug-builtins ON)
47+
feature(pooling-allocator ON)
4748
# ... if you add a line above this be sure to change the other locations
4849
# marked WASMTIME_FEATURE_LIST

crates/c-api/doxygen.conf.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ EXCLUDE_SYMBOLS = assertions \
942942
WASMTIME_DECLARE_OWN \
943943
WASI_DECLARE_OWN \
944944
WASMTIME_CONFIG_PROP \
945+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP \
945946
own \
946947
wasm_*_enum
947948

crates/c-api/include/wasmtime/conf.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#cmakedefine WASMTIME_FEATURE_CRANELIFT
2727
#cmakedefine WASMTIME_FEATURE_WINCH
2828
#cmakedefine WASMTIME_FEATURE_DEBUG_BUILTINS
29+
#cmakedefine WASMTIME_FEATURE_POOLING_ALLOCATOR
2930
// ... if you add a line above this be sure to change the other locations
3031
// marked WASMTIME_FEATURE_LIST
3132

crates/c-api/include/wasmtime/config.h

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,228 @@ wasmtime_config_host_memory_creator_set(wasm_config_t *,
542542
*/
543543
WASMTIME_CONFIG_PROP(void, memory_init_cow, bool)
544544

545+
#ifdef WASMTIME_FEATURE_POOLING_ALLOCATOR
546+
547+
/**
548+
* \brief A type containing configuration options for the pooling allocator.
549+
*
550+
* For more information see the Rust documentation at
551+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html
552+
*/
553+
typedef struct wasmtime_pooling_allocation_config_t
554+
wasmtime_pooling_allocation_config_t;
555+
556+
/**
557+
* \brief Creates a new pooling allocation configuration object. Must be
558+
* deallocated with a call to wasmtime_pooling_allocation_config_delete.
559+
*/
560+
WASM_API_EXTERN wasmtime_pooling_allocation_config_t *
561+
wasmtime_pooling_allocation_config_new();
562+
563+
/**
564+
* \brief Deallocates a pooling allocation configuration object created with a
565+
* call to wasmtime_pooling_allocation_config_new.
566+
*/
567+
WASM_API_EXTERN void wasmtime_pooling_allocation_config_delete(
568+
wasmtime_pooling_allocation_config_t *);
569+
570+
#define WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(name, ty) \
571+
WASM_API_EXTERN void wasmtime_pooling_allocation_config_##name##_set( \
572+
wasmtime_pooling_allocation_config_t *, ty);
573+
574+
/**
575+
* \brief Configures the maximum number of “unused warm slots” to retain in the
576+
* pooling allocator.
577+
*
578+
* For more information see the Rust documentation at
579+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.max_unused_warm_slots.
580+
*/
581+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(max_unused_warm_slots, uint32_t)
582+
583+
/**
584+
* \brief The target number of decommits to do per batch.
585+
*
586+
* For more information see the Rust documentation at
587+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.decommit_batch_size.
588+
*/
589+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(decommit_batch_size, size_t)
590+
591+
#ifdef WASMTIME_FEATURE_ASYNC
592+
/**
593+
* \brief How much memory, in bytes, to keep resident for async stacks allocated
594+
* with the pooling allocator.
595+
*
596+
* For more information see the Rust documentation at
597+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.async_stack_keep_resident.
598+
*/
599+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(async_stack_keep_resident, size_t)
600+
#endif
601+
602+
/**
603+
* \brief How much memory, in bytes, to keep resident for each linear memory
604+
* after deallocation.
605+
*
606+
* For more information see the Rust documentation at
607+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.linear_memory_keep_resident.
608+
*/
609+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(linear_memory_keep_resident, size_t)
610+
611+
/**
612+
* \brief How much memory, in bytes, to keep resident for each table after
613+
* deallocation.
614+
*
615+
* For more information see the Rust documentation at
616+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.table_keep_resident.
617+
*/
618+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(table_keep_resident, size_t)
619+
620+
/**
621+
* \brief The maximum number of concurrent component instances supported
622+
* (default is 1000).
623+
*
624+
* For more information see the Rust documentation at
625+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.total_component_instances.
626+
*/
627+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(total_component_instances, uint32_t)
628+
629+
/**
630+
* \brief The maximum size, in bytes, allocated for a component instance’s
631+
* VMComponentContext metadata.
632+
*
633+
* For more information see the Rust documentation at
634+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.max_component_instance_size.
635+
*/
636+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(max_component_instance_size, size_t)
637+
638+
/**
639+
* \brief The maximum number of core instances a single component may contain
640+
* (default is unlimited).
641+
*
642+
* For more information see the Rust documentation at
643+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.max_core_instances_per_component.
644+
*/
645+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(max_core_instances_per_component,
646+
uint32_t)
647+
648+
/**
649+
* \brief The maximum number of Wasm linear memories that a single component may
650+
* transitively contain (default is unlimited).
651+
*
652+
* For more information see the Rust documentation at
653+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.max_memories_per_component.
654+
*/
655+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(max_memories_per_component, uint32_t)
656+
657+
/**
658+
* \brief The maximum number of tables that a single component may transitively
659+
* contain (default is unlimited).
660+
*
661+
* For more information see the Rust documentation at
662+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.max_tables_per_component.
663+
*/
664+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(max_tables_per_component, uint32_t)
665+
666+
/**
667+
* \brief The maximum number of concurrent Wasm linear memories supported
668+
* (default is 1000).
669+
*
670+
* For more information see the Rust documentation at
671+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.total_memories.
672+
*/
673+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(total_memories, uint32_t)
674+
675+
/**
676+
* \brief The maximum number of concurrent tables supported (default is 1000).
677+
*
678+
* For more information see the Rust documentation at
679+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.total_tables.
680+
*/
681+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(total_tables, uint32_t)
682+
683+
#ifdef WASMTIME_FEATURE_ASYNC
684+
/**
685+
* \brief The maximum number of execution stacks allowed for asynchronous
686+
* execution, when enabled (default is 1000).
687+
*
688+
* For more information see the Rust documentation at
689+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.total_stacks.
690+
*/
691+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(total_stacks, uint32_t)
692+
#endif
693+
694+
/**
695+
* \brief The maximum number of concurrent core instances supported (default is
696+
* 1000).
697+
*
698+
* For more information see the Rust documentation at
699+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.total_core_instances.
700+
*/
701+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(total_core_instances, uint32_t)
702+
703+
/**
704+
* \brief The maximum size, in bytes, allocated for a core instance’s VMContext
705+
* metadata.
706+
*
707+
* For more information see the Rust documentation at
708+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.max_core_instance_size.
709+
*/
710+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(max_core_instance_size, size_t)
711+
712+
/**
713+
* \brief The maximum number of defined tables for a core module (default is 1).
714+
*
715+
* For more information see the Rust documentation at
716+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.max_tables_per_module.
717+
*/
718+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(max_tables_per_module, uint32_t)
719+
720+
/**
721+
* \brief The maximum table elements for any table defined in a module (default
722+
* is 20000).
723+
*
724+
* For more information see the Rust documentation at
725+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.table_elements.
726+
*/
727+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(table_elements, size_t)
728+
729+
/**
730+
* \brief The maximum number of defined linear memories for a module (default is
731+
* 1).
732+
*
733+
* For more information see the Rust documentation at
734+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.max_memories_per_module.
735+
*/
736+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(max_memories_per_module, uint32_t)
737+
738+
/**
739+
* \brief The maximum byte size that any WebAssembly linear memory may grow to.
740+
*
741+
* For more information see the Rust documentation at
742+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.max_memory_size.
743+
*/
744+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(max_memory_size, size_t)
745+
746+
/**
747+
* \brief The maximum number of concurrent GC heaps supported (default is 1000).
748+
*
749+
* For more information see the Rust documentation at
750+
* https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html#method.total_gc_heaps.
751+
*/
752+
WASMTIME_POOLING_ALLOCATION_CONFIG_PROP(total_gc_heaps, uint32_t)
753+
754+
/**
755+
* \brief Sets the Wasmtime allocation strategy to use the pooling allocator. It
756+
* does not take ownership of the pooling allocation configuration object, which
757+
* must be deleted with a call to wasmtime_pooling_allocation_config_delete.
758+
*
759+
* For more information see the Rust documentation at
760+
* https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.allocation_strategy.
761+
*/
762+
WASM_API_EXTERN void wasmtime_pooling_allocation_strategy_set(
763+
wasm_config_t *, const wasmtime_pooling_allocation_config_t *);
764+
765+
#endif // WASMTIME_FEATURE_POOLING_ALLOCATOR
766+
545767
#ifdef __cplusplus
546768
} // extern "C"
547769
#endif

0 commit comments

Comments
 (0)