Skip to content
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

Use MemAvailable when it's available on Linux 3.14+ kernel #71

Merged
merged 1 commit into from
May 11, 2017

Conversation

monicasarbu
Copy link

@monicasarbu monicasarbu commented May 5, 2017

Use MemAvailable when it's available on Linux 3.14+ kernel, otherwise calculate it as free memory plus the caches and buffers.

(Fixes elastic/beats#4202)

self.ActualFree = self.Free + kern
}
self.Used = self.Total - self.ActualFree
self.ActualUsed = self.Used
Copy link
Author

Choose a reason for hiding this comment

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

Leave actual memory usage like this for now, equal with the memory usage.

kern := buffers + cached
self.ActualFree = self.Free + kern
self.ActualUsed = self.Used - kern
if self.ActualFree > 0.0 {
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to unit test this pretty easily by simulating the contents of the /proc/meminfo file.

With the current data structure it might not be possible to detect the difference between MemAvailable: 0 kB and MemAvailable not present. You don't want to fallback to the secondary calculation when MemAvailable: 0 kB so you might need to refactor.

if self.ActualFree > 0.0 { doesn't look right?

Copy link
Author

Choose a reason for hiding this comment

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

That's a good point. I would need to refactor the code to be able to distinguish between MemAvailable: 0kB and MemAvailable not present.

@monicasarbu monicasarbu force-pushed the use_memavailable_on_linux branch 2 times, most recently from 3b1eb28 to 61712b4 Compare May 5, 2017 22:49
meminfoContents := `
MemTotal: 500184 kB
MemFree: 31360 kB
MemAvailable: 414168 kB
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add a test case for when MemAvailable: 0 kB.

Copy link
Author

Choose a reason for hiding this comment

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

Sure.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@andrewkroh
Copy link
Member

We need a CHANGELOG entry too.

@monicasarbu monicasarbu force-pushed the use_memavailable_on_linux branch 3 times, most recently from 88d2e9e to 34de5a6 Compare May 10, 2017 11:51
@monicasarbu
Copy link
Author

@andrewkroh Ready for the final review.

Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

LGTM. Just need to move the changelog entry.

CHANGELOG.md Outdated
@@ -33,6 +33,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
privileges in a process token.
- Added utility code for interfacing with linux NETLINK_INET_DIAG. #60
- Added `ProcEnv` for getting a process's environment variables. #61
- Read `MemAvailable` value for kernel 3.14+
Copy link
Member

Choose a reason for hiding this comment

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

This should be up in the "unreleased" section.

Copy link
Author

Choose a reason for hiding this comment

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

Done, thanks for noticing it.

@andrewkroh andrewkroh merged commit be03232 into elastic:master May 11, 2017
andrewkroh pushed a commit to elastic/beats that referenced this pull request May 16, 2017
Update deps to include the latest changes from the elastic/gosigar#71 which includes a change to use `MemAvailable` on Linux.

This closes #4202.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants