def create_container_with_specific_mems_cpus(name, mems, cpus): need_fake_numa() os.mkdir(full_path(name)) utils.write_one_line(cpuset_attr(name, 'mem_hardwall'), '1') utils.write_one_line(mems_path(name), ','.join(map(str, mems))) utils.write_one_line(cpus_path(name), ','.join(map(str, cpus))) logging.debug('container %s has %d cpus and %d nodes totalling %s bytes', name, len(cpus), len(get_mem_nodes(name)), utils.human_format(container_bytes(name)) )
def create_container_with_specific_mems_cpus(name, mems, cpus): need_fake_numa() os.mkdir(full_path(name)) utils.write_one_line(cpuset_attr(name, 'mem_hardwall'), '1') utils.write_one_line(mems_path(name), ','.join(map(str, mems))) utils.write_one_line(cpus_path(name), ','.join(map(str, cpus))) logging.debug('container %s has %d cpus and %d nodes totalling %s bytes', name, len(cpus), len(get_mem_nodes(name)), utils.human_format(container_bytes(name)))
def create_container_via_memcg(name, parent, bytes, cpus): # create container via direct memcg cgroup writes os.mkdir(full_path(name)) nodes = utils.read_one_line(mems_path(parent)) utils.write_one_line(mems_path(name), nodes) # inherit parent's nodes utils.write_one_line(memory_path(name)+'.limit_in_bytes', str(bytes)) utils.write_one_line(cpus_path(name), ','.join(map(str, cpus))) logging.debug('Created container %s directly via memcg,' ' has %d cpus and %s bytes', name, len(cpus), utils.human_format(container_bytes(name)))
def create_container_via_memcg(name, parent, bytes, cpus): # create container via direct memcg cgroup writes os.mkdir(full_path(name)) nodes = utils.read_one_line(mems_path(parent)) utils.write_one_line(mems_path(name), nodes) # inherit parent's nodes utils.write_one_line(memory_path(name) + '.limit_in_bytes', str(bytes)) utils.write_one_line(cpus_path(name), ','.join(map(str, cpus))) logging.debug( 'Created container %s directly via memcg,' ' has %d cpus and %s bytes', name, len(cpus), utils.human_format(container_bytes(name)))
def discover_container_style(): global super_root_path, cpuset_prefix global mem_isolation_on, fake_numa_containers global node_mbytes, root_container_bytes if super_root_path != '': return # already looked up if os.path.exists('/dev/cgroup/tasks'): # running on 2.6.26 or later kernel with containers on: super_root_path = '/dev/cgroup' cpuset_prefix = 'cpuset.' if get_boot_numa(): mem_isolation_on = fake_numa_containers = True else: # memcg containers IFF compiled-in & mounted & non-fakenuma boot fake_numa_containers = False mem_isolation_on = os.path.exists( '/dev/cgroup/memory.limit_in_bytes') # TODO: handle possibility of where memcg is mounted as its own # cgroup hierarchy, separate from cpuset?? elif os.path.exists('/dev/cpuset/tasks'): # running on 2.6.18 kernel with containers on: super_root_path = '/dev/cpuset' cpuset_prefix = '' mem_isolation_on = fake_numa_containers = get_boot_numa() != '' else: # neither cpuset nor cgroup filesystem active: super_root_path = None cpuset_prefix = 'no_cpusets_or_cgroups_exist' mem_isolation_on = fake_numa_containers = False logging.debug('mem_isolation: %s', mem_isolation_on) logging.debug('fake_numa_containers: %s', fake_numa_containers) if fake_numa_containers: node_mbytes = int(mbytes_per_mem_node()) elif mem_isolation_on: # memcg-style containers # For now, limit total of all containers to using just 98% of system's # visible total ram, to avoid oom events at system level, and avoid # page reclaim overhead from going above kswapd highwater mark. system_visible_pages = utils.memtotal() >> 2 usable_pages = int(system_visible_pages * 0.98) root_container_bytes = usable_pages << 12 logging.debug('root_container_bytes: %s', utils.human_format(root_container_bytes))