@@ -720,11 +720,29 @@ lazy_static! {
720
720
config. native_unwind_info( false ) ;
721
721
722
722
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.
724
739
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.
726
744
config. memory_may_move( false ) ;
727
- config . epoch_interruption ( true ) ;
745
+
728
746
config
729
747
} ;
730
748
pub ( crate ) static ref ENGINE : Engine = Engine :: new( & CONFIG ) . unwrap( ) ;
0 commit comments