Skip to content

Commit 1f7c59b

Browse files
committed
refactor: document changes
1 parent 4969488 commit 1f7c59b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

lib/src/wasm/mod.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,11 +720,29 @@ lazy_static! {
720720
config.native_unwind_info(false);
721721

722722
config.cranelift_opt_level(wasmtime::OptLevel::SpeedAndSize);
723-
config.memory_reservation(0x1000000); // 16MB
723+
config.epoch_interruption(true);
724+
725+
// 16MB should be enough for each WASM module. Each module needs a
726+
// fixed amount of memory that is only a few KB long, plus a variable
727+
// amount that depends on the number of rules and patterns (1 bit per
728+
// rule and 1 bit per pattern). With 16MB there's enough space for
729+
// millions of rules and patterns. By default, this is 4GB in 64-bits
730+
// systems, which causes a reservation of 4GB of virtual address space
731+
// (not physical RAM) per module (and therefore per Scanner). In some
732+
// scenarios where virtual address space is limited (i.e: Docker
733+
// instances) this is problematic. See:
734+
// https://github.com/VirusTotal/yara-x/issues/292
735+
config.memory_reservation(0x1000000);
736+
737+
// WASM memory won't grow, there's no need to allocate space for
738+
// future grow.
724739
config.memory_reservation_for_growth(0);
725-
config.guard_before_linear_memory(false);
740+
741+
// As the memory can't grow, it won't move. By explicitly indicating
742+
// this, modules can be compiled with static knowledge the base pointer
743+
// of linear memory never changes to enable optimizations.
726744
config.memory_may_move(false);
727-
config.epoch_interruption(true);
745+
728746
config
729747
};
730748
pub(crate) static ref ENGINE: Engine = Engine::new(&CONFIG).unwrap();

0 commit comments

Comments
 (0)