def setUp(self): ''' Sets all the reqd parameter and also mounts the tmpfs to be used in test. ''' # Set params as per available memory in system self.mem_path = self.params.get("t_dir", default=os.path.join( data_dir.get_tmp_dir(), 'thp_space')) free_mem = self.params.get("mem_size", default=memory.meminfo.MemFree.m) self.dd_timeout = self.params.get("dd_timeout", default=900) self.thp_split = None try: memory.read_from_vmstat("thp_split_page") self.thp_split = "thp_split_page" except IndexError: self.thp_split = "thp_split" # Set block size as hugepage size * 2 self.block_size = memory.meminfo.Hugepagesize.m * 2 self.count = free_mem // self.block_size # Mount device as per free memory size if not os.path.exists(self.mem_path): os.makedirs(self.mem_path) self.device = Partition(device="none", mountpoint=self.mem_path) self.device.mount(mountpoint=self.mem_path, fstype="tmpfs", args='-o size=%dM' % free_mem)
def setUp(self): ''' Sets all the reqd parameter and also mounts the tmpfs to be used in test. ''' # Set params as per available memory in system self.mem_path = os.path.join(data_dir.get_tmp_dir(), 'thp_space') free_mem = int(memory.freememtotal() / 1024) self.dd_timeout = 900 self.thp_split = None try: memory.read_from_vmstat("thp_split_page") self.thp_split = "thp_split_page" except IndexError: self.thp_split = "thp_split" # Set block size as hugepage size * 2 self.block_size = (memory.get_huge_page_size() / 1024) * 2 self.count = free_mem / self.block_size # Mount device as per free memory size if not os.path.exists(self.mem_path): os.makedirs(self.mem_path) self.device = Partition(device="none", mountpoint=self.mem_path) self.device.mount(mountpoint=self.mem_path, fstype="tmpfs", args='-o size=%dM' % free_mem)
def test(self): ''' Enables THP , Runs the dd workload and checks whether THP has been allocated. ''' # Enables THP try: memory.set_thp_value("enabled", "always") except Exception as details: self.fail("Failed %s" % details) # Read thp values before stressing the system thp_alloted_before = int(memory.read_from_vmstat("thp_fault_alloc")) thp_split_before = int(memory.read_from_vmstat(self.thp_split)) thp_collapse_alloc_before = int( memory.read_from_vmstat("thp_collapse_alloc")) # Start Stresssing the System self.log.info('Stress testing using dd command') for iterator in range(self.count): stress_cmd = 'dd if=/dev/zero of=%s/%d bs=%dM count=1'\ % (self.mem_path, iterator, self.block_size) if (process.system(stress_cmd, timeout=self.dd_timeout, verbose=False, ignore_status=True, shell=True)): self.fail('dd command failed %s' % stress_cmd) # Read thp values after stressing the system thp_alloted_after = int(memory.read_from_vmstat("thp_fault_alloc")) thp_split_after = int(memory.read_from_vmstat(self.thp_split)) thp_collapse_alloc_after = int( memory.read_from_vmstat("thp_collapse_alloc")) # Check whether THP is Used or not if thp_alloted_after <= thp_alloted_before: e_msg = "Thp usage count has not increased\n" e_msg += "Before Stress:%d\nAfter stress:%d" % (thp_alloted_before, thp_alloted_after) self.fail(e_msg) else: thp_fault_alloc = thp_alloted_after - thp_alloted_before thp_split = thp_split_after - thp_split_before thp_collapse_alloc = (thp_collapse_alloc_after - thp_collapse_alloc_before) self.log.info("\nTest statistics, changes during test run:") self.log.info( "thp_fault_alloc=%d\nthp_split=%d\n" "thp_collapse_alloc=%d\n", thp_fault_alloc, thp_split, thp_collapse_alloc)
def test(self): ''' Enables THP , Runs the dd workload and checks whether THP has been allocated. ''' # Enables THP try: memory.set_thp_value("enabled", "always") except Exception as details: self.fail("Failed %s" % details) # Read thp values before stressing the system thp_alloted_before = int(memory.read_from_vmstat("thp_fault_alloc")) thp_split_before = int(memory.read_from_vmstat("thp_split_page")) thp_collapse_alloc_before = int(memory.read_from_vmstat ("thp_collapse_alloc")) # Start Stresssing the System self.log.info('Stress testing using dd command') for iterator in range(self.count): stress_cmd = 'dd if=/dev/zero of=%s/%d bs=%dM count=1'\ % (self.mem_path, iterator, self.block_size) if(process.system(stress_cmd, timeout=self.dd_timeout, verbose=False, ignore_status=True, shell=True)): self.fail('dd command failed %s' % stress_cmd) # Read thp values after stressing the system thp_alloted_after = int(memory.read_from_vmstat("thp_fault_alloc")) thp_split_after = int(memory.read_from_vmstat("thp_split_page")) thp_collapse_alloc_after = int(memory.read_from_vmstat ("thp_collapse_alloc")) # Check whether THP is Used or not if thp_alloted_after <= thp_alloted_before: e_msg = "Thp usage count has not increased\n" e_msg += "Before Stress:%d\nAfter stress:%d" % (thp_alloted_before, thp_alloted_after) self.fail(e_msg) else: thp_fault_alloc = thp_alloted_after - thp_alloted_before thp_split = thp_split_after - thp_split_before thp_collapse_alloc = (thp_collapse_alloc_after - thp_collapse_alloc_before) self.log.info("\nTest statistics, changes during test run:") self.log.info("thp_fault_alloc=%d\nthp_split=%d\n" "thp_collapse_alloc=%d\n", thp_fault_alloc, thp_split, thp_collapse_alloc)