@@ -243,7 +243,10 @@ def __init__(
243243 self .vcpus_count = None
244244 self .mem_size_bytes = None
245245
246- self ._numa_node = numa_node
246+ self ._pre_cmd = []
247+ if numa_node :
248+ node_str = str (numa_node )
249+ self .add_pre_cmd ([["numactl" , "-N" , node_str , "-m" , node_str ]])
247250
248251 # MMDS content from file
249252 self .metadata_file = None
@@ -552,6 +555,13 @@ def pin_threads(self, first_cpu):
552555
553556 return first_cpu + self .vcpus_count + 2
554557
558+ def add_pre_cmd (self , pre_cmd ):
559+ """Prepends commands to the command line to launch the microVM
560+
561+ For example, this can be used to pin the VM to a NUMA node or to trace the VM with strace.
562+ """
563+ self ._pre_cmd = pre_cmd + self ._pre_cmd
564+
555565 def spawn (
556566 self ,
557567 log_file = "fc.log" ,
@@ -600,10 +610,11 @@ def spawn(
600610 # Checking the timings requires DEBUG level log messages
601611 self .time_api_requests = False
602612
603- cmd = [str (self .jailer_binary_path )] + self .jailer .construct_param_list ()
604- if self ._numa_node is not None :
605- node = str (self ._numa_node )
606- cmd = ["numactl" , "-N" , node , "-m" , node ] + cmd
613+ cmd = [
614+ * self ._pre_cmd ,
615+ str (self .jailer_binary_path ),
616+ * self .jailer .construct_param_list (),
617+ ]
607618
608619 # When the daemonize flag is on, we want to clone-exec into the
609620 # jailer rather than executing it via spawning a shell.
0 commit comments