Skip to content

Commit

Permalink
speedup page attributes accesses with shared lru_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Abyss-W4tcher committed Jan 4, 2025
1 parent cedc0b0 commit 8e0b261
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions volatility3/framework/symbols/linux/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2525,7 +2525,28 @@ def i_pages(self):


class page(objects.StructType):
@functools.cached_property
def __eq__(self, other):
"""Share @property's in a "vmlinux->[*pages]" lru_cache,
as thousands of page objects can be instantiated in
a single plugin run. Observed benchmarks noted
30x faster _intel_vmemmap_start accesses after first call.
The properties are in fact kernel-wide constants, and do not need
to be re-calculated on each instantiation.
Doc: https://stackoverflow.com/a/69780424
Use functools.cached_property to ignore this behaviour, as it was
observed to not call __hash__ and __eq__.
"""
return isinstance(other, page) and self.__hash__() == other.__hash__()

# Use the vmlinux to identify cache pools.
def __hash__(self):
return linux.LinuxUtilities.get_module_from_volobj_type(
self._context, self
).__hash__()

@property
@functools.lru_cache
def pageflags_enum(self) -> Dict:
"""Returns 'pageflags' enumeration key/values
Expand All @@ -2545,7 +2566,8 @@ def pageflags_enum(self) -> Dict:

return pageflags_enum

@functools.cached_property
@property
@functools.lru_cache
def _intel_vmemmap_start(self) -> int:
"""Determine the start of the struct page array, for Intel systems.
Expand Down

0 comments on commit 8e0b261

Please sign in to comment.