Skip to contentSkip to conversation

cooker/siggen: Empty siggen cache during parsing

PATCH In review Richard Purdie 2 participants 3 messages Feb 17, 2020 – Feb 18, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cooker/siggen: Empty siggen cache during parsing

When parsing recipes its apparent the memory usage of bitbake rises linearly with number of recipes parsed. It shouldn't.

Using tracemalloc (thanks for the tip Joshua Lock) it was clear that the dependency information left behind in siggen was the culprit. Add a new method to allow us to drop this information. We don't need it after the recipe has been parsed and hashes calculated (at runtime its different but only the currently executing task would be in memory).

This should give signficant memory usage improvements for bitbake and that in turn should help speed on more constrained systems, as well as when used in multiconfig environments.

---
 lib/bb/cooker.py |  3 ++-
 lib/bb/siggen.py | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
lib/bb/cooker.py +2 -1
index 1124332186..a05630d52d 100644
@@ -1940,7 +1940,8 @@ class Parser(multiprocessing.Process):
                 except IndexError:
                     break
                 result = self.parse(*job)
-
+                # Clear the siggen cache after parsing to control memory usage, its huge
+                bb.parse.siggen.postparsing_clean_cache()
             try:
                 self.results.put(result, timeout=0.25)
             except queue.Full:
lib/bb/siggen.py +11 -0
index ffd8fcaf36..c2d0c736cf 100644
@@ -51,6 +51,9 @@ class SignatureGenerator(object):
     def finalise(self, fn, d, varient):
         return
 
+    def postparsing_clean_cache(self):
+        return
+
     def get_unihash(self, tid):
         return self.taskhash[tid]
 
@@ -188,6 +191,14 @@ class SignatureGeneratorBasic(SignatureGenerator):
         for task in taskdeps:
             d.setVar("BB_BASEHASH_task-%s" % task, self.basehash[fn + ":" + task])
 
+    def postparsing_clean_cache(self):
+        #
+        # After parsing we can remove some things from memory to reduce our memory footprint
+        #
+        self.gendeps = {}
+        self.lookupcache = {}
+        self.taskdeps = {}
+
     def rundep_check(self, fn, recipename, task, dep, depname, dataCache):
         # Return True if we should keep the dependency, False to drop it
         # We only manipulate the dependencies for packages not in the whitelist
Signature · 1 line
2.25.0
#1 lore raw
Quoted 2 lines · Richard Purdie

When parsing recipes its apparent the memory usage of bitbake rises linearly with number of recipes parsed. It shouldn't.

This seems back port worthy to 1.44, 1.42

- armin

Quoted 60 lines

Using tracemalloc (thanks for the tip Joshua Lock) it was clear that the dependency information left behind in siggen was the culprit. Add a new method to allow us to drop this information. We don't need it after the recipe has been parsed and hashes calculated (at runtime its different but only the currently executing task would be in memory).

This should give signficant memory usage improvements for bitbake and that in turn should help speed on more constrained systems, as well as when used in multiconfig environments.

---
 lib/bb/cooker.py |  3 ++-
 lib/bb/siggen.py | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
lib/bb/cooker.py +2 -1
index 1124332186..a05630d52d 100644
@@ -1940,7 +1940,8 @@ class Parser(multiprocessing.Process):
                 except IndexError:
                     break
                 result = self.parse(*job)
-
+                # Clear the siggen cache after parsing to control memory usage, its huge
+                bb.parse.siggen.postparsing_clean_cache()
             try:
                 self.results.put(result, timeout=0.25)
             except queue.Full:
lib/bb/siggen.py +11 -0
index ffd8fcaf36..c2d0c736cf 100644
@@ -51,6 +51,9 @@ class SignatureGenerator(object):
     def finalise(self, fn, d, varient):
         return
 
+    def postparsing_clean_cache(self):
+        return
+
     def get_unihash(self, tid):
         return self.taskhash[tid]
 
@@ -188,6 +191,14 @@ class SignatureGeneratorBasic(SignatureGenerator):
         for task in taskdeps:
             d.setVar("BB_BASEHASH_task-%s" % task, self.basehash[fn + ":" + task])
 
+    def postparsing_clean_cache(self):
+        #
+        # After parsing we can remove some things from memory to reduce our memory footprint
+        #
+        self.gendeps = {}
+        self.lookupcache = {}
+        self.taskdeps = {}
+
     def rundep_check(self, fn, recipename, task, dep, depname, dataCache):
         # Return True if we should keep the dependency, False to drop it
         # We only manipulate the dependencies for packages not in the whitelist
#2 lore raw
Quoted 6 lines · On Tue, 2020-02-18 at 07:44 -0800, akuster808 wrote:
Quoted 3 lines · Richard Purdie

When parsing recipes its apparent the memory usage of bitbake rises linearly
with number of recipes parsed. It shouldn't.

This seems back port worthy to 1.44, 1.42

Yes, I did it already! :)

(With my bitbake maintainer hat on)

Cheers,

Richard