Skip to contentSkip to conversation

utils: Add ionice option to prunedir

PATCH In review Richard Purdie 2 participants 3 messages Sep 19, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils: Add ionice option to prunedir

Autobuilder type infrastructure can benefit from deletion of certain files as background IO due to the way Linux filesystem priority works.

We have problems where build directories as part of oe-selftest being delete starves the running tasks of IO to the point builds take much longer to compelte.

Having this option of running the deletion at "idle" helps a lot with that.

---
 lib/bb/utils.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
lib/bb/utils.py +7 -4
index 3e90b6a306..d035949b3d 100644
@@ -677,7 +677,7 @@ def _check_unsafe_delete_path(path):
         return True
     return False
 
-def remove(path, recurse=False):
+def remove(path, recurse=False, ionice=False):
     """Equivalent to rm -f or rm -rf"""
     if not path:
         return
@@ -686,7 +686,10 @@ def remove(path, recurse=False):
             if _check_unsafe_delete_path(path):
                 raise Exception('bb.utils.remove: called with dangerous path "%s" and recurse=True, refusing to delete!' % path)
         # shutil.rmtree(name) would be ideal but its too slow
-        subprocess.check_call(['rm', '-rf'] + glob.glob(path))
+        cmd = []
+        if ionice:
+            cmd = ['ionice', '-c', '3']
+        subprocess.check_call(cmd + ['rm', '-rf'] + glob.glob(path))
         return
     for name in glob.glob(path):
         try:
@@ -695,12 +698,12 @@ def remove(path, recurse=False):
             if exc.errno != errno.ENOENT:
                 raise
 
-def prunedir(topdir):
+def prunedir(topdir, ionice=False):
     # Delete everything reachable from the directory named in 'topdir'.
     # CAUTION:  This is dangerous!
     if _check_unsafe_delete_path(topdir):
         raise Exception('bb.utils.prunedir: called with dangerous path "%s", refusing to delete!' % topdir)
-    remove(topdir, recurse=True)
+    remove(topdir, recurse=True, ionice=ionice)
 
 #
 # Could also use return re.compile("(%s)" % "|".join(map(re.escape, suffixes))).sub(lambda mo: "", var)
Signature · 1 line
2.20.1
#1 lore raw
Quoted 29 lines · Richard Purdie

Autobuilder type infrastructure can benefit from deletion of certain files as background IO due to the way Linux filesystem priority works.

We have problems where build directories as part of oe-selftest being delete starves the running tasks of IO to the point builds take much longer to compelte.

Having this option of running the deletion at "idle" helps a lot with that.

---
 lib/bb/utils.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
lib/bb/utils.py +1 -1
index 3e90b6a306..d035949b3d 100644
@@ -677,7 +677,7 @@ def _check_unsafe_delete_path(path):
         return True
     return False
 
-def remove(path, recurse=False):
+def remove(path, recurse=False, ionice=False):
     """Equivalent to rm -f or rm -rf"""
     if not path:
         return

lib/bb/utils.py def remove(path, recurse=False): · line 691

Quoted 7 lines
lib/bb/utils.py +3 -1
@@ -686,7 +686,10 @@ def remove(path, recurse=False):
             if _check_unsafe_delete_path(path):
                 raise Exception('bb.utils.remove: called with dangerous path "%s" and recurse=True, refusing to delete!' % path)
         # shutil.rmtree(name) would be ideal but its too slow
-        subprocess.check_call(['rm', '-rf'] + glob.glob(path))
+        cmd = []
+        if ionice:
+            cmd = ['ionice', '-c', '3']

Would allowing folks to configure the ionice value apply here?

- armin

Quoted 19 lines
lib/bb/utils.py +3 -2
+        subprocess.check_call(cmd + ['rm', '-rf'] + glob.glob(path))
         return
     for name in glob.glob(path):
         try:
@@ -695,12 +698,12 @@ def remove(path, recurse=False):
             if exc.errno != errno.ENOENT:
                 raise
 
-def prunedir(topdir):
+def prunedir(topdir, ionice=False):
     # Delete everything reachable from the directory named in 'topdir'.
     # CAUTION:  This is dangerous!
     if _check_unsafe_delete_path(topdir):
         raise Exception('bb.utils.prunedir: called with dangerous path "%s", refusing to delete!' % topdir)
-    remove(topdir, recurse=True)
+    remove(topdir, recurse=True, ionice=ionice)
 
 #
 # Could also use return re.compile("(%s)" % "|".join(map(re.escape, suffixes))).sub(lambda mo: "", var)
#2 lore raw
Quoted 29 lines · akuster
Quoted 27 lines · Richard Purdie

Autobuilder type infrastructure can benefit from deletion of certain files as
background IO due to the way Linux filesystem priority works.

We have problems where build directories as part of oe-selftest being
delete starves the running tasks of IO to the point builds take much
longer to compelte.

Having this option of running the deletion at "idle" helps a lot with
that.

---
 lib/bb/utils.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
lib/bb/utils.py +0 -0
index 3e90b6a306..d035949b3d 100644
@@ -677,7 +677,7 @@ def _check_unsafe_delete_path(path):
         return True
     return False
 
Quoted 15 lines
Quoted 6 lines
lib/bb/utils.py +1 -1
-def remove(path, recurse=False):
+def remove(path, recurse=False, ionice=False):
     """Equivalent to rm -f or rm -rf"""
     if not path:
         return

lib/bb/utils.py def remove(path, recurse=False): · line 692

Quoted 8 lines
lib/bb/utils.py +3 -1
@@ -686,7 +686,10 @@ def remove(path, recurse=False):
             if _check_unsafe_delete_path(path):
                 raise Exception('bb.utils.remove: called with
 dangerous path "%s" and recurse=True, refusing to delete!' % path)
         # shutil.rmtree(name) would be ideal but its too slow
-        subprocess.check_call(['rm', '-rf'] + glob.glob(path))
+        cmd = []
+        if ionice:
+            cmd = ['ionice', '-c', '3']

Would allowing folks to configure the ionice value apply here?

Its a good question, there isn't usually a lot of choice since a process can only "degrade" its priority, not increase it. I'd prefer to leave this as is and extend if anyone ever really needs it.

(3 means 'idle' which matches what the autobuilder does for file deletion in general)

Cheers,

Richard