aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-06-24 12:50:51 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2019-06-24 12:50:51 +0200
commit3568a5ed6ffec6b8a36e9497cc777b5059f7794d (patch)
tree2942d4f9a3d32d16208aaf7c27e908f394705524 /vespajlib
parentd3fc7d9efbf656ec9a5623084fc91be0c79789e8 (diff)
Drop file continously from cache as we read it.
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/io/NativeIO.java23
1 files changed, 16 insertions, 7 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/io/NativeIO.java b/vespajlib/src/main/java/com/yahoo/io/NativeIO.java
index f69bdb4e3dd..109b7ff7943 100644
--- a/vespajlib/src/main/java/com/yahoo/io/NativeIO.java
+++ b/vespajlib/src/main/java/com/yahoo/io/NativeIO.java
@@ -54,19 +54,28 @@ public class NativeIO {
}
/**
- * Will hint the OS that this is will not be accessed again and should hence be dropped from the buffer cache.
+ * Will hint the OS that data read so far will not be accessed again and should hence be dropped from the buffer cache.
* @param fd The file descriptor to drop from buffer cache.
*/
- public void dropFileFromCache(FileDescriptor fd) {
- try {
- fd.sync();
- } catch (SyncFailedException e) {
- logger.warning("Sync failed while dropping cache: " + e.getMessage());
+ public void dropPartialFileFromCache(FileDescriptor fd, long offset, long len, boolean sync) {
+ if (sync) {
+ try {
+ fd.sync();
+ } catch (SyncFailedException e) {
+ logger.warning("Sync failed while dropping cache: " + e.getMessage());
+ }
}
if (initialized) {
- posix_fadvise(getNativeFD(fd), 0, 0, POSIX_FADV_DONTNEED);
+ posix_fadvise(getNativeFD(fd), offset, len, POSIX_FADV_DONTNEED);
}
}
+ /**
+ * Will hint the OS that this is will not be accessed again and should hence be dropped from the buffer cache.
+ * @param fd The file descriptor to drop from buffer cache.
+ */
+ public void dropFileFromCache(FileDescriptor fd) {
+ dropPartialFileFromCache(fd, 0, 0, true);
+ }
/**
* Will hint the OS that this is will not be accessed again and should hence be dropped from the buffer cache.