Skip to content

Comments

rfc: A new tool to implement memory stress #25

Open
FingerLeader wants to merge 3 commits intochaos-mesh:mainfrom
FingerLeader:main
Open

rfc: A new tool to implement memory stress #25
FingerLeader wants to merge 3 commits intochaos-mesh:mainfrom
FingerLeader:main

Conversation

@FingerLeader
Copy link
Member

@FingerLeader FingerLeader commented Oct 29, 2021

Signed-off-by: FingerLeader wanxfinger@gmail.com

@FingerLeader
Copy link
Member Author

There is my implementation, PTAL at memStress.


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)```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data, err := syscall.Mmap(-1, 0, length, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_PRIVATE|syscall.MAP_ANONYMOUS)

Copy link
Member

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_ANONYMOUS

Copy link
Member Author

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_WRITE let us read and write the array data, so we can write some bytes in it to occupy memory page.
And the parameter syscall.MAP_PRIVATE makes the mapping not visible to other processes and are not carried through to the underlying file, syscall.MAP_ANONYMOUS makes 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.

Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants