-
Notifications
You must be signed in to change notification settings - Fork 22
rfc: A new tool to implement memory stress #25
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
Open
FingerLeader
wants to merge
3
commits into
chaos-mesh:main
Choose a base branch
from
FingerLeader:main
base: main
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.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Self-made Memory Stress Program | ||
|
|
||
| ## Summary | ||
|
|
||
| Create a program to replace stress-ng to realize mem stress. | ||
|
|
||
| ## Motivation | ||
|
|
||
| Because stress-ng realize memory stress by applying read and write pressure instead of occupying memory space, which will affect CPU performance, a program purely takes up memory space is need to generate a memory StressChaos. | ||
|
|
||
| ## Detailed design | ||
|
|
||
| Using `syscall.Mmap()` to allocate memory space directly, so that uncertain footprint can be avoided. And write 1 byte on every virtual memory page of the space we allocated can achieve our goal. | ||
|
|
||
| ```data, err := syscall.Mmap(-1, 0, length, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_PRIVATE|syscall.MAP_ANONYMOUS)``` | ||
|
|
||
| Furthermore, users can specify time to let the memory allocation increase linearly, so they can simulate a memory leak. The program will write certain numbers of pages in a time interval longer than 100ms , which can reduce the impact of the delay of `time.Sleep()`. | ||
|
|
||
| ## Alternatives | ||
|
|
||
| - stress-ng will obviously increase the usage of CPU. | ||
| - Allocating memory space by using `make()` will cause uncertain footprint. And GC may be triggered under certain situation. | ||
|
|
||
| ## Unresolved questions | ||
|
|
||
| - The program itself takes about 68MB | ||
| - It takes time to allocate big memory (over a giga bytes) without the parameter `--time`. For example, it will take 3.5s to allocate 12GB memory space. | ||
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.
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.
Can you add more introduction about
syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_PRIVATE|syscall.MAP_ANONYMOUSThere 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.
The parameter
syscall.PROT_READ|syscall.PROT_WRITElet us read and write the arraydata, so we can write some bytes in it to occupy memory page.And the parameter
syscall.MAP_PRIVATEmakes the mapping not visible to other processes and are not carried through to the underlying file,syscall.MAP_ANONYMOUSmakes the mapping won't be backed by any file. Therefore, the allocated memory will not leave any mark or be accessed.You can get more information at https://man7.org/linux/man-pages/man2/mmap.2.html.
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.
You need to add this introduction on RFC