[dpdk-dev] [v3 PATCH] usertools: show valid hugepage sizes if user requests an invalid hugepage size

Burakov, Anatoly anatoly.burakov at intel.com
Wed Feb 10 18:41:21 CET 2021


On 10-Feb-21 6:16 AM, Sarosh Arif wrote:
> If user requests a hugepage size which is not supported by the system,
> currently user gets an error message saying that the requested size
> is not a valid system huge page size. In addition to this if we display
> the valid hugepage sizes it will be convenient for the user to request
> the right size next time.
> 
> Signed-off-by: Sarosh Arif <sarosh.arif at emumba.com>
> ---
> v2:
> pass string in sys.exit() to remove pylint warning
> v3:
> modify get_valid_page_sizes()
> ---
> 
>   usertools/dpdk-hugepages.py | 11 ++++++++---
>   1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/usertools/dpdk-hugepages.py b/usertools/dpdk-hugepages.py
> index 70432f9cd..57ae9f391 100755
> --- a/usertools/dpdk-hugepages.py
> +++ b/usertools/dpdk-hugepages.py
> @@ -43,6 +43,12 @@ def is_numa():
>       return os.path.exists('/sys/devices/system/node')
>   
>   
> +def get_valid_page_sizes(path):
> +    '''Extract valid hugepage sizes'''
> +    dir = os.path.dirname(path)
> +    pg_sizes = (d.split("-")[1] for d in os.listdir(dir))
> +    return " ".join(pg_sizes)
> +
>   def get_hugepages(path):
>       '''Read number of reserved pages'''
>       with open(path + '/nr_hugepages') as nr_hugepages:
> @@ -59,9 +65,8 @@ def set_hugepages(path, pages):
>       except PermissionError:
>           sys.exit('Permission denied: need to be root!')
>       except FileNotFoundError:
> -        filename = os.path.basename(path)
> -        size = filename[10:]
> -        sys.exit('{} is not a valid system huge page size'.format(size))
> +        sys.exit("Invalid page size. Valid page sizes: {}".format(
> +                                get_valid_page_sizes(path)))

Nitpicking, but i think this indentation wouldn't be OK with a PEP-8 
style checker. This should be better:

sys.exit("Invalid page size. Valid page sizes: {}"
          .format(get_validpage_sizes(path))

(note the alignment of .format with the quote)

Otherwise, LGTM

Acked-by: Anatoly Burakov <anatoly.burakov at intel.com>

>       if get_hugepages(path) != pages:
>           sys.exit('Unable to reserve required pages.')
>   
> 


-- 
Thanks,
Anatoly


More information about the dev mailing list