-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speedup page class attributes accesses with shared lru_cache #1528
Open
Abyss-W4tcher
wants to merge
1
commit into
volatilityfoundation:develop
Choose a base branch
from
Abyss-W4tcher:page_instances_shared_lrucache
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+24
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -2545,7 +2566,8 @@ def pageflags_enum(self) -> Dict: | |
|
||
return pageflags_enum | ||
|
||
@functools.cached_property | ||
@property | ||
@functools.lru_cache | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method doesn't need to be a property at all, it only uses self to find the kernel, if anything this should be a LinuxUtility that takes in a kernel, or live somewhere else, there's no benefit to it living here. |
||
def _intel_vmemmap_start(self) -> int: | ||
"""Determine the start of the struct page array, for Intel systems. | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redefining these is bad (see main comments).