@@ -8,12 +8,6 @@ use std::{fmt, result};
8
8
9
9
use common:: StableDeref ;
10
10
use fs4:: FileExt ;
11
-
12
- #[ cfg( feature = "madvise" ) ]
13
- use crate :: AccessPattern ;
14
- #[ cfg( not( feature = "madvise" ) ) ]
15
- type AccessPattern = ( ) ;
16
-
17
11
use memmap2:: Mmap ;
18
12
use serde:: { Deserialize , Serialize } ;
19
13
use tempfile:: TempDir ;
@@ -27,6 +21,7 @@ use crate::directory::{
27
21
AntiCallToken , Directory , DirectoryLock , FileHandle , Lock , OwnedBytes , TerminatingWrite ,
28
22
WatchCallback , WatchHandle , WritePtr ,
29
23
} ;
24
+ use crate :: Advice ;
30
25
31
26
pub type ArcBytes = Arc < dyn Deref < Target = [ u8 ] > + Send + Sync + ' static > ;
32
27
pub type WeakArcBytes = Weak < dyn Deref < Target = [ u8 ] > + Send + Sync + ' static > ;
@@ -38,10 +33,9 @@ pub(crate) fn make_io_err(msg: String) -> io::Error {
38
33
39
34
/// Returns `None` iff the file exists, can be read, but is empty (and hence
40
35
/// cannot be mmapped)
41
- #[ allow( unused_variables) ]
42
36
fn open_mmap (
43
37
full_path : & Path ,
44
- access_pattern_opt : Option < AccessPattern > ,
38
+ madvice_opt : Option < Advice > ,
45
39
) -> result:: Result < Option < Mmap > , OpenReadError > {
46
40
let file = File :: open ( full_path) . map_err ( |io_err| {
47
41
if io_err. kind ( ) == io:: ErrorKind :: NotFound {
@@ -65,11 +59,9 @@ fn open_mmap(
65
59
. map ( Some )
66
60
. map_err ( |io_err| OpenReadError :: wrap_io_error ( io_err, full_path. to_path_buf ( ) ) )
67
61
} ?;
68
- #[ cfg( feature = "madvise" ) ]
69
- match ( & mmap_opt, access_pattern_opt) {
70
- ( Some ( mmap) , Some ( access_pattern) ) => {
71
- use madvise:: AdviseMemory ;
72
- let _ = mmap. advise_memory_access ( access_pattern) ;
62
+ match ( & mmap_opt, madvice_opt) {
63
+ ( Some ( mmap) , Some ( madvice) ) => {
64
+ let _ = mmap. advise ( madvice) ;
73
65
}
74
66
_ => { }
75
67
}
@@ -94,15 +86,15 @@ pub struct CacheInfo {
94
86
struct MmapCache {
95
87
counters : CacheCounters ,
96
88
cache : HashMap < PathBuf , WeakArcBytes > ,
97
- access_pattern_opt : Option < AccessPattern > ,
89
+ madvice_opt : Option < Advice > ,
98
90
}
99
91
100
92
impl MmapCache {
101
- fn new ( access_pattern_opt : Option < AccessPattern > ) -> MmapCache {
93
+ fn new ( madvice_opt : Option < Advice > ) -> MmapCache {
102
94
MmapCache {
103
95
counters : CacheCounters :: default ( ) ,
104
96
cache : HashMap :: default ( ) ,
105
- access_pattern_opt ,
97
+ madvice_opt ,
106
98
}
107
99
}
108
100
@@ -136,7 +128,7 @@ impl MmapCache {
136
128
}
137
129
self . cache . remove ( full_path) ;
138
130
self . counters . miss += 1 ;
139
- let mmap_opt = open_mmap ( full_path, self . access_pattern_opt ) ?;
131
+ let mmap_opt = open_mmap ( full_path, self . madvice_opt ) ?;
140
132
Ok ( mmap_opt. map ( |mmap| {
141
133
let mmap_arc: ArcBytes = Arc :: new ( mmap) ;
142
134
let mmap_weak = Arc :: downgrade ( & mmap_arc) ;
@@ -174,10 +166,10 @@ impl MmapDirectoryInner {
174
166
fn new (
175
167
root_path : PathBuf ,
176
168
temp_directory : Option < TempDir > ,
177
- access_pattern_opt : Option < AccessPattern > ,
169
+ madvice_opt : Option < Advice > ,
178
170
) -> MmapDirectoryInner {
179
171
MmapDirectoryInner {
180
- mmap_cache : RwLock :: new ( MmapCache :: new ( access_pattern_opt ) ) ,
172
+ mmap_cache : RwLock :: new ( MmapCache :: new ( madvice_opt ) ) ,
181
173
_temp_directory : temp_directory,
182
174
watcher : FileWatcher :: new ( & root_path. join ( * META_FILEPATH ) ) ,
183
175
root_path,
@@ -199,9 +191,9 @@ impl MmapDirectory {
199
191
fn new (
200
192
root_path : PathBuf ,
201
193
temp_directory : Option < TempDir > ,
202
- access_pattern_opt : Option < AccessPattern > ,
194
+ madvice_opt : Option < Advice > ,
203
195
) -> MmapDirectory {
204
- let inner = MmapDirectoryInner :: new ( root_path, temp_directory, access_pattern_opt ) ;
196
+ let inner = MmapDirectoryInner :: new ( root_path, temp_directory, madvice_opt ) ;
205
197
MmapDirectory {
206
198
inner : Arc :: new ( inner) ,
207
199
}
@@ -230,17 +222,16 @@ impl MmapDirectory {
230
222
}
231
223
232
224
/// Opens a MmapDirectory in a directory, with a given access pattern.
233
- #[ cfg( feature = "madvise" ) ]
234
- pub fn open_with_access_pattern < P : AsRef < Path > > (
225
+ pub fn open_with_madvice < P : AsRef < Path > > (
235
226
directory_path : P ,
236
- access_pattern : AccessPattern ,
227
+ madvice : Advice ,
237
228
) -> Result < MmapDirectory , OpenDirectoryError > {
238
- Self :: open_with_access_pattern_impl ( directory_path. as_ref ( ) , Some ( access_pattern ) )
229
+ Self :: open_with_access_pattern_impl ( directory_path. as_ref ( ) , Some ( madvice ) )
239
230
}
240
231
241
232
fn open_with_access_pattern_impl (
242
233
directory_path : & Path ,
243
- access_pattern_opt : Option < AccessPattern > ,
234
+ madvice_opt : Option < Advice > ,
244
235
) -> Result < MmapDirectory , OpenDirectoryError > {
245
236
let directory_path: & Path = directory_path. as_ref ( ) ;
246
237
if !directory_path. exists ( ) {
@@ -269,7 +260,7 @@ impl MmapDirectory {
269
260
directory_path,
270
261
) ) ) ;
271
262
}
272
- Ok ( MmapDirectory :: new ( canonical_path, None , access_pattern_opt ) )
263
+ Ok ( MmapDirectory :: new ( canonical_path, None , madvice_opt ) )
273
264
}
274
265
275
266
/// Joins a relative_path to the directory `root_path`
0 commit comments