On 9/4/2020 7:35 PM, Stephen Hemminger wrote: > This is an improved version of the setup of huge pages > bases on earlier DPDK setup. Differences are: > * it autodetects NUMA vs non NUMA > * it allows setting different page sizes > recent kernels support multiple sizes. > * it accepts a parameter in bytes (not pages). > > If necessary the steps of clearing old settings and mounting/umounting > can be done individually.
Very handy, thanks. > > Signed-off-by: Stephen Hemminger <step...@networkplumber.org> > --- > v3 -- incorporate review feedback > add missing SPDX and env header > overengineer the memory prefix string code > add numa node argument > fix some pylint warnings > > v2 -- convert to python3 > <...> > +def is_numa(): > + '''Test if NUMA is necessary on this system''' > + return exists('/sys/devices/numa/node') - return exists('/sys/devices/numa/node') + return exists('/sys/devices/system/node') <...> > +def clear_numa_pages(): > + for path in glob.glob( > + '/sys/devices/system/node/node*/hugepages/hugepages-*'): > + with open(path + '/nr_hugepages', 'w') as f: > + f.write('\n0') - f.write('\n0') + f.write('0\n') <...> > +def mount_huge(pagesize):> + cmd = "mount -t hugetlbfs" > + if pagesize: > + cmd += ' -o pagesize={}'.format(pagesize) > + cmd += ' nodev {}'.format(HUGEDIR) > + os.system(cmd) What do you thing checking if mount point exist before 'cmd'? + if not exists(HUGEDIR): + os.system('mkdir -p ' + HUGEDIR) <...> > +def do_arg_actions(): > + '''do the actual action requested by the user''' > + global hugepagesize_kb > + > + if clear_flag: > + clear_pages() > + if unmount_flag: > + os.system("umount " + HUGEDIR) What do you think umount only if it is mounted, (to get rid of warning for --setup after -u), something like: + if not os.system("mount | grep -q " + HUGEDIR): + os.system("umount " + HUGEDIR)