From beb00ce17ed16233c36042d5691ce634b042328d Mon Sep 17 00:00:00 2001 From: Carsten Grohmann Date: Wed, 1 Mar 2023 22:29:15 +0100 Subject: [PATCH] Add MAX_ORDER constant --- OOMAnalyser.py | 27 +++++++++++++++++++++++++++ test.py | 6 ++++++ 2 files changed, 33 insertions(+) diff --git a/OOMAnalyser.py b/OOMAnalyser.py index 109c379..7ad6072 100644 --- a/OOMAnalyser.py +++ b/OOMAnalyser.py @@ -454,6 +454,22 @@ class BaseKernelConfig: @see: _gfp_create_reverse_lookup() """ + MAX_ORDER = -1 + """ + The kernel memory allocator divides physically contiguous memory + blocks into "zones", where each zone is a power of two number of + pages. This option selects the largest power of two that the kernel + keeps in the memory allocator. + + This config option is actually maximum order plus one. For example, + a value of 11 means that the largest free memory block is 2^10 pages. + + The value will be calculated dynamically based on the numbers of + orders in OOMAnalyser._extract_buddyinfo(). + + @see: OOMAnalyser._extract_buddyinfo(). + """ + pstable_items = [ "pid", "uid", @@ -3031,6 +3047,17 @@ class OOMAnalyser: size = size[:-2] # strip "kB" self.oom_result.details["_buddyinfo_pagesize_kb"] = int(size) + # MAX_ORDER is actually maximum order plus one. For example, + # a value of 11 means that the largest free memory block is 2^10 pages. + # __pragma__ ('jsiter') + max_order = 0 + for o in self.oom_result.details["_buddyinfo"]["DMA"]: + # JS: integer is sometimes a string :-/ + if (isinstance(o, str) and o.isdigit()) or isinstance(o, int): + max_order += 1 + # __pragma__ ('nojsiter') + self.oom_result.kconfig.MAX_ORDER = max_order + def _extract_watermarks(self): """ Extract memory watermark information from all zones diff --git a/test.py b/test.py index 35ae1bd..3dbba88 100755 --- a/test.py +++ b/test.py @@ -937,6 +937,12 @@ Hardware name: HP ProLiant DL385 G7, BIOS A18 12/08/2012 'Wrong watermark level for node %s in zone "%s" (got: %d, expect %d)' % (node, zone, level, except_level), ) + self.assertEqual( + analyser.oom_result.kconfig.MAX_ORDER, + 11, # This is a hard coded value as extracted from kernel 6.2.0 + "Unexpected number of chunk sizes (got: %s, expect: 11 (kernel 6.2.0))" + % analyser.oom_result.kconfig.MAX_ORDER, + ) if __name__ == "__main__":