Maps file region into memory, reusing existing mapping if available. @param fd file descriptor to map @param mmapCacheKey unique value that is safe to use as a key for caching the map. FD is not good enough since a FD can be closed after the mapping is created and OS c
(int fd, long mmapCacheKey, long len, long offset, int flags, int memoryTag)
| 89 | * @param flags memory mapping flags, e.g., Files.MAP_RO for read-only |
| 90 | */ |
| 91 | public long cacheMmap(int fd, long mmapCacheKey, long len, long offset, int flags, int memoryTag) { |
| 92 | if (len < 1) { |
| 93 | throw CairoException.critical(0) |
| 94 | .put("could not mmap file, invalid len [len=").put(len) |
| 95 | .put(", offset=").put(offset) |
| 96 | .put(", fd=").put(fd) |
| 97 | .put(", memoryTag=").put(memoryTag) |
| 98 | .put(']'); |
| 99 | } |
| 100 | if (offset != 0 || mmapCacheKey == 0 || !Files.FS_CACHE_ENABLED || flags == Files.MAP_RW) { |
| 101 | return mmap0(fd, len, offset, flags, memoryTag); |
| 102 | } |
| 103 | |
| 104 | if (Files.ASYNC_MUNMAP_ENABLED) { |
| 105 | return cacheMmapOptimistic(fd, mmapCacheKey, len, memoryTag); |
| 106 | } else { |
| 107 | return cacheMmapPessimistic(fd, mmapCacheKey, len, memoryTag); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Returns number of times cached memory mappings were reused. |
no test coverage detected