-
Notifications
You must be signed in to change notification settings - Fork 895
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 JNI directly for posix_fadvise #3824
Conversation
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.
Great job!
Please fix the failed check:
|
Codecov Report
@@ Coverage Diff @@
## master #3824 +/- ##
=============================================
+ Coverage 41.40% 60.45% +19.04%
- Complexity 4034 5851 +1817
=============================================
Files 473 473
Lines 40963 40963
Branches 5240 5241 +1
=============================================
+ Hits 16962 24764 +7802
+ Misses 22160 13981 -8179
- Partials 1841 2218 +377
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
LOG.info("Unable to link C library. Native methods will be disabled."); | ||
} catch (NoSuchMethodError e) { | ||
LOG.warn("Obsolete version of JNA present; unable to register C library"); | ||
nativeIO = new NativeIOImpl(); |
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.
We should check if nativeIO.posix_fdavise
works or not. new NativeIOImpl()
din't ensure posix_fdavise
work
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.
@horizonzy I also found this when I run unit tests on mac os.
We don't need to check whether nativeIO.posix_fdavise is valid, because in use, once an error occurs, we will close posix_fdavise, so we can just check whether the library is normal, this is the error I encountered.
I have submit a PR: #3832
public static void bestEffortRemoveFromPageCache(int fd, long offset, long len) {
if (!fadvisePossible || fd < 0) {
return;
}
try {
NATIVE_IO.posix_fadvise(fd, offset, len, POSIX_FADV_DONTNEED);
} catch (Exception e) {
log.warn("Failed to perform posix_fadvise: {}", e.getMessage());
fadvisePossible = false;
}
}
* Use JNI directly for posix_fadvise * Fixed checkstyle * fixed checkstyle * Fixed jni function name
Motivation
For calling
posix_fadvise
, we are using JNA which is a wrapper on top of JNI. While JNA is convenient because it's dynamically creating a stub for accessing native methods, it's also very inefficient compared to direct JNI access.Since we already have JNI modules, we should add
posix_fadvise
there and remove the dependency on JNA.