def get_memory_banks_per_run(coreAssignment, cgroups): """Get an assignment of memory banks to runs that fits to the given coreAssignment, i.e., no run is allowed to use memory that is not local (on the same NUMA node) to one of its CPU cores.""" try: # read list of available memory banks allMems = set(cgroups.read_allowed_memory_banks()) result = [] for cores in coreAssignment: mems = set() for core in cores: coreDir = f"/sys/devices/system/cpu/cpu{core}/" mems.update(_get_memory_banks_listed_in_dir(coreDir)) allowedMems = sorted(mems.intersection(allMems)) logging.debug( "Memory banks for cores %s are %s, of which we can use %s.", cores, list(mems), allowedMems, ) result.append(allowedMems) assert len(result) == len(coreAssignment) if any(result) and os.path.isdir("/sys/devices/system/node/"): return result else: # All runs get the empty list of memory regions # because this system has no NUMA support return None except ValueError as e: sys.exit(f"Could not read memory information from kernel: {e}")
def get_memory_banks_per_run(coreAssignment, cgroups): """Get an assignment of memory banks to runs that fits to the given coreAssignment, i.e., no run is allowed to use memory that is not local (on the same NUMA node) to one of its CPU cores.""" try: # read list of available memory banks allMems = set(cgroups.read_allowed_memory_banks()) result = [] for cores in coreAssignment: mems = set() for core in cores: coreDir = '/sys/devices/system/cpu/cpu{0}/'.format(core) mems.update(_get_memory_banks_listed_in_dir(coreDir)) allowedMems = sorted(mems.intersection(allMems)) logging.debug("Memory banks for cores %s are %s, of which we can use %s.", cores, list(mems), allowedMems) result.append(allowedMems) assert len(result) == len(coreAssignment) if any(result) and os.path.isdir('/sys/devices/system/node/'): return result else: # All runs get the empty list of memory regions # because this system has no NUMA support return None except ValueError as e: sys.exit("Could not read memory information from kernel: {0}".format(e))