Skip to contentSkip to conversation

usertools: show an error message if unable to reserve requested hugepages

PATCH Superseded Sarosh Arif 3 participants 8 messages Nov 30, 2020 – Feb 5, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usertools: show an error message if unable to reserve requested hugepages

Sometimes the system is unable to reserve the requested hugepages because enough space is not available in the RAM. In that case, currently the script displays no error message hence the user can be under the delusion that the hugepages he requested are all successfully reserved. This patch displays an error message if the pages reserved are different from the requested pages and shows the actual pages reserved.

---
 usertools/dpdk-hugepages.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
usertools/dpdk-hugepages.py +6 -1
index 1be100ca3..3f6e62c8f 100755
@@ -62,7 +62,10 @@ def set_hugepages(path, pages):
         filename = os.path.basename(path)
         size = filename[10:]
         sys.exit('{} is not a valid system huge page size'.format(size))
-
+    if get_hugepages(path) != pages:
+        print("Unable to reserve required pages. The pages reserved are:")
+        show_pages()
+        args.show = False
 
 def show_numa_pages():
     '''Show huge page reservations on Numa system'''
@@ -232,6 +235,8 @@ def main():
         '--setup',
         metavar='SIZE',
         help='setup huge pages by doing clear, unmount, reserve and mount')
+
+    global args
     args = parser.parse_args()
 
     if args.setup:
Signature · 1 line
2.25.1
#1 lore raw
Quoted 8 lines · On Mon, 30 Nov 2020 17:45:33 +0500 Sarosh Arif <[email protected]> wrote:

Sometimes the system is unable to reserve the requested hugepages because enough space is not available in the RAM. In that case, currently the script displays no error message hence the user can be under the delusion that the hugepages he requested are all successfully reserved. This patch displays an error message if the pages reserved are different from the requested pages and shows the actual pages reserved.

This is ok, but this code was written to go through python lint cleanly. This patch introduces new warnings:

usertools/dpdk-hugepages.py:239:4: W0601: Global variable 'args' undefined at the module level (global-variable-undefined) usertools/dpdk-hugepages.py:239:4: C0103: Constant name "args" doesn't conform to UPPER_CASE naming style (invalid-name)

#2 lore raw

PATCH v2 1/1 usertools: show an error message if unable to reserve requested hugepages

In reply to Sarosh Arif

Sometimes the system is unable to reserve the requested hugepages because enough space is not available in the RAM. In that case, currently the script displays no error message hence the user can be under the delusion that the hugepages he requested are all successfully reserved. This patch displays an error message if the pages reserved are different from the requested pages and shows the actual pages reserved.

---
v2:
use a global variable SHOW_HUGEPAGES to remove linter warnings

---
 usertools/dpdk-hugepages.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
usertools/dpdk-hugepages.py +10 -1
index 1be100ca3..83332c096 100755
@@ -16,6 +16,8 @@
 # systemd mount point for huge pages
 HUGE_MOUNT = "/dev/hugepages"
 
+# show hugepages flag
+SHOW_HUGEPAGES = False
 
 def fmt_memsize(kb):
     '''Format memory size in kB into conventional format'''
@@ -62,6 +64,10 @@ def set_hugepages(path, pages):
         filename = os.path.basename(path)
         size = filename[10:]
         sys.exit('{} is not a valid system huge page size'.format(size))
+    if get_hugepages(path) != pages:
+        print("Unable to reserve required pages. The pages reserved are:")
+        global SHOW_HUGEPAGES
+        SHOW_HUGEPAGES = True
 
 
 def show_numa_pages():
@@ -233,6 +239,9 @@ def main():
         metavar='SIZE',
         help='setup huge pages by doing clear, unmount, reserve and mount')
     args = parser.parse_args()
+
+    global SHOW_HUGEPAGES
+    SHOW_HUGEPAGES = args.show
 
     if args.setup:
         args.clear = True
@@ -260,7 +269,7 @@ def main():
             int(reserve_kb / pagesize_kb), pagesize_kb, node=args.node)
     if args.mount:
         mount_huge(pagesize_kb, HUGE_MOUNT)
-    if args.show:
+    if SHOW_HUGEPAGES:
         show_pages()
         print()
         show_mount()
Signature · 1 line
2.25.1
#3 lore raw

usertools/dpdk-hugepages.py def set_hugepages(path, pages): · line 70

Quoted 4 lines · On Thu, 17 Dec 2020 16:16:16 +0500 Sarosh Arif <[email protected]> wrote:
usertools/dpdk-hugepages.py +4 -0
+    if get_hugepages(path) != pages:
+        print("Unable to reserve required pages. The pages reserved are:")
+        global SHOW_HUGEPAGES
+        SHOW_HUGEPAGES = True

Please don't add global's to this script.

The script is close to being clean according to pylint, and globals are considered bad style and shouldn't be used.

I would just exit if huge pages could not be setup.
The script should leave it up to the user to do another query about status if they care about what the result is.

#4 lore raw
Quoted 10 lines · Stephen Hemminger

usertools/dpdk-hugepages.py def set_hugepages(path, pages): · line 70

Quoted 4 lines · On Thu, 17 Dec 2020 16:16:16 +0500 Sarosh Arif <[email protected]> wrote:
usertools/dpdk-hugepages.py +4 -0
+    if get_hugepages(path) != pages:
+        print("Unable to reserve required pages. The pages reserved are:")
+        global SHOW_HUGEPAGES
+        SHOW_HUGEPAGES = True
Quoted 6 lines

Please don't add global's to this script.

The script is close to being clean according to pylint, and globals are considered bad style and shouldn't be used.

I would just exit if huge pages could not be setup.

How about if we just print a warning message such as "Unable to reserve required pages" before exiting, in case the pages are not reserved due to lack of space in RAM? Then leave it upon the user to query how many pages are actually reserved.

Quoted 3 lines

The script should leave it up to the user to do another query about status if they care about what the result is.

#5 lore raw
Quoted 17 lines · On Thu, 7 Jan 2021 13:06:35 +0500 Sarosh Arif <[email protected]> wrote:
Quoted 15 lines · Stephen Hemminger

usertools/dpdk-hugepages.py def set_hugepages(path, pages): · line 70

Quoted 4 lines · On Thu, 17 Dec 2020 16:16:16 +0500 Sarosh Arif <[email protected]> wrote:
usertools/dpdk-hugepages.py +4 -0
+    if get_hugepages(path) != pages:
+        print("Unable to reserve required pages. The pages reserved are:")
+        global SHOW_HUGEPAGES
+        SHOW_HUGEPAGES = True  

Please don't add global's to this script.

The script is close to being clean according to pylint, and globals are considered bad style and shouldn't be used.

Quoted 9 lines
Quoted 1 line

I would just exit if huge pages could not be setup.

How about if we just print a warning message such as "Unable to reserve required pages" before exiting, in case the pages are not reserved due to lack of space in RAM? Then leave it upon the user to query how many pages are actually reserved.

Quoted 3 lines

The script should leave it up to the user to do another query about status if they care about what the result is.

Just call sys.exit with a message that is all that is needed.

Or maybe trapping other write errors to sysfs here. Probably the kernel has already tried to report the error, but the try/except code is not seeing it.

#6 lore raw

PATCH v3 1/1 usertools: show an error message if unable to reserve requested hugepages

In reply to Sarosh Arif

Sometimes the system is unable to reserve the requested hugepages because enough space is not available in the RAM. In that case, currently the script displays no error message hence the user can be under the delusion that the hugepages requested are all successfully reserved. This patch displays an error message if the pages reserved are different from the requested pages.

---
v2:
use a global variable SHOW_HUGEPAGES to remove linter warnings v3:
only print an error message if unable to reserve hugepages.

---
 usertools/dpdk-hugepages.py | 2 ++
 1 file changed, 2 insertions(+)
usertools/dpdk-hugepages.py +2 -0
index 1be100ca3..1523be20a 100755
@@ -62,6 +62,8 @@ def set_hugepages(path, pages):
         filename = os.path.basename(path)
         size = filename[10:]
         sys.exit('{} is not a valid system huge page size'.format(size))
+    if get_hugepages(path) != pages:
+        sys.exit("Unable to reserve required pages.")
 
 
 def show_numa_pages():
Signature · 1 line
2.25.1
#7 lore raw

08/01/2021 10:06, Sarosh Arif:

Quoted 14 lines

Sometimes the system is unable to reserve the requested hugepages because enough space is not available in the RAM. In that case, currently the script displays no error message hence the user can be under the delusion that the hugepages requested are all successfully reserved. This patch displays an error message if the pages reserved are different from the requested pages.

---
v2:
use a global variable SHOW_HUGEPAGES to remove linter warnings v3:
only print an error message if unable to reserve hugepages.
---

usertools/dpdk-hugepages.py def set_hugepages(path, pages): · line 66

Quoted 2 lines
usertools/dpdk-hugepages.py +2 -0
+    if get_hugepages(path) != pages:
+        sys.exit("Unable to reserve required pages.")

Replaced double quotes by simple ones.

Applied, thanks.