-
Notifications
You must be signed in to change notification settings - Fork 53
Fallback to /proc/PID/mem when process_vm_readv not in kernel #240
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
Fallback to /proc/PID/mem when process_vm_readv not in kernel #240
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #240 +/- ##
==========================================
- Coverage 82.73% 82.66% -0.07%
==========================================
Files 46 46
Lines 6272 6300 +28
Branches 461 467 +6
==========================================
+ Hits 5189 5208 +19
- Misses 1083 1092 +9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
3ef98d2
to
61713f1
Compare
Hey @godlygeek, did you have any feedback for my PR? |
Kernels may build with the CONFIG_CROSS_MEMORY_ATTACH configuration option not set, in this case process_vm_readv returns ENOSYS. The /proc/PID/mem file in the proc(5) filesystem serves the same purpose but is less efficient as the data must transfer through the kernel. We use this as a fallback. Signed-off-by: Daniel Golding <goldingd89@gmail.com>
61713f1
to
0f0199f
Compare
This should both be a bit faster, and makes the error reporting a bit simpler. And incidentally this fixes a file descriptor leak as well. Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
Add an environment variable to force reads from `/proc/PID/mem` instead of using `process_vm_readv` in order to give us a way to exercise both paths on the same kernel. Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
Sorry for the delay @cakemanny, just circling back to this now. What you had looked pretty good to me, and I very much appreciate how readable the diff was. I didn't like the need to fall back to Instead of hopping from the highest level interface to the lowest level one just to get the failure reason, we can do everything with a medium-level interface that gives us everything we need - switching to the C style stdio functions lets us get the cause of any errors (they're guaranteed to set errno), while still letting us work at a slightly higher level of abstraction than the raw syscall wrappers. I also added an environment variable to force us down the /proc/PID/mem path even on kernels that do support Since I made some non-trivial changes here, I'm not going to merge this until either @sarahmonod or @pablogsal check my work. |
Ah, and also, if you still have access to the system that was compiled without I can't imagine why they wouldn't, since my new test is exercising everything except the |
Resolves #238
Describe your changes
I've added an alternative implementation of
ProcessMemoryManager::readChunk
that uses the relevant/proc/PID/mem
file and is fallen back to whenprocess_vm_readv
fails withENOSYS
.Once the
/proc/PID/mem
file is open, subsequent reads are done only from there.Testing performed
On my dev instance where my kernel does have
CONFIG_CROSS_MEMORY_ATTACH
set, I did various tests with small source changes. Such as forcing the fallback implementation to always be used.Details
I also checked what the various errors might look like, say if the file didn't exist
Once I was pretty happy that it wasn't too awful, I spun up a flatcar VM and tested the happy path there.
Details (Probably too many)
Per https://www.flatcar.org/docs/latest/setup/releases/verify-images/
Additional context
I've not written any C++ for about 14 years, so I've probably missed out on some cleverer or prettier ways of doing this.