@@ -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 > ;
@@ -41,7 +36,7 @@ pub(crate) fn make_io_err(msg: String) -> io::Error {
41
36
#[ allow( unused_variables) ]
42
37
fn open_mmap (
43
38
full_path : & Path ,
44
- access_pattern_opt : Option < AccessPattern > ,
39
+ madvise_opt : Option < Advice > ,
45
40
) -> result:: Result < Option < Mmap > , OpenReadError > {
46
41
let file = File :: open ( full_path) . map_err ( |io_err| {
47
42
if io_err. kind ( ) == io:: ErrorKind :: NotFound {
@@ -65,11 +60,9 @@ fn open_mmap(
65
60
. map ( Some )
66
61
. map_err ( |io_err| OpenReadError :: wrap_io_error ( io_err, full_path. to_path_buf ( ) ) )
67
62
} ?;
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) ;
63
+ match ( & mmap_opt, madvise_opt) {
64
+ ( Some ( mmap) , Some ( madvise) ) => {
65
+ let _ = mmap. advise ( madvise) ;
73
66
}
74
67
_ => { }
75
68
}
@@ -94,15 +87,15 @@ pub struct CacheInfo {
94
87
struct MmapCache {
95
88
counters : CacheCounters ,
96
89
cache : HashMap < PathBuf , WeakArcBytes > ,
97
- access_pattern_opt : Option < AccessPattern > ,
90
+ madvise_opt : Option < Advice > ,
98
91
}
99
92
100
93
impl MmapCache {
101
- fn new ( access_pattern_opt : Option < AccessPattern > ) -> MmapCache {
94
+ fn new ( madvise_opt : Option < Advice > ) -> MmapCache {
102
95
MmapCache {
103
96
counters : CacheCounters :: default ( ) ,
104
97
cache : HashMap :: default ( ) ,
105
- access_pattern_opt ,
98
+ madvise_opt ,
106
99
}
107
100
}
108
101
@@ -136,7 +129,7 @@ impl MmapCache {
136
129
}
137
130
self . cache . remove ( full_path) ;
138
131
self . counters . miss += 1 ;
139
- let mmap_opt = open_mmap ( full_path, self . access_pattern_opt ) ?;
132
+ let mmap_opt = open_mmap ( full_path, self . madvise_opt ) ?;
140
133
Ok ( mmap_opt. map ( |mmap| {
141
134
let mmap_arc: ArcBytes = Arc :: new ( mmap) ;
142
135
let mmap_weak = Arc :: downgrade ( & mmap_arc) ;
@@ -174,10 +167,10 @@ impl MmapDirectoryInner {
174
167
fn new (
175
168
root_path : PathBuf ,
176
169
temp_directory : Option < TempDir > ,
177
- access_pattern_opt : Option < AccessPattern > ,
170
+ madvise_opt : Option < Advice > ,
178
171
) -> MmapDirectoryInner {
179
172
MmapDirectoryInner {
180
- mmap_cache : RwLock :: new ( MmapCache :: new ( access_pattern_opt ) ) ,
173
+ mmap_cache : RwLock :: new ( MmapCache :: new ( madvise_opt ) ) ,
181
174
_temp_directory : temp_directory,
182
175
watcher : FileWatcher :: new ( & root_path. join ( * META_FILEPATH ) ) ,
183
176
root_path,
@@ -199,9 +192,9 @@ impl MmapDirectory {
199
192
fn new (
200
193
root_path : PathBuf ,
201
194
temp_directory : Option < TempDir > ,
202
- access_pattern_opt : Option < AccessPattern > ,
195
+ madvise_opt : Option < Advice > ,
203
196
) -> MmapDirectory {
204
- let inner = MmapDirectoryInner :: new ( root_path, temp_directory, access_pattern_opt ) ;
197
+ let inner = MmapDirectoryInner :: new ( root_path, temp_directory, madvise_opt ) ;
205
198
MmapDirectory {
206
199
inner : Arc :: new ( inner) ,
207
200
}
@@ -230,17 +223,16 @@ impl MmapDirectory {
230
223
}
231
224
232
225
/// 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 > > (
226
+ pub fn open_with_madvise < P : AsRef < Path > > (
235
227
directory_path : P ,
236
- access_pattern : AccessPattern ,
228
+ madvise : Advice ,
237
229
) -> Result < MmapDirectory , OpenDirectoryError > {
238
- Self :: open_with_access_pattern_impl ( directory_path. as_ref ( ) , Some ( access_pattern ) )
230
+ Self :: open_with_access_pattern_impl ( directory_path. as_ref ( ) , Some ( madvise ) )
239
231
}
240
232
241
233
fn open_with_access_pattern_impl (
242
234
directory_path : & Path ,
243
- access_pattern_opt : Option < AccessPattern > ,
235
+ madvise_opt : Option < Advice > ,
244
236
) -> Result < MmapDirectory , OpenDirectoryError > {
245
237
let directory_path: & Path = directory_path. as_ref ( ) ;
246
238
if !directory_path. exists ( ) {
@@ -269,7 +261,7 @@ impl MmapDirectory {
269
261
directory_path,
270
262
) ) ) ;
271
263
}
272
- Ok ( MmapDirectory :: new ( canonical_path, None , access_pattern_opt ) )
264
+ Ok ( MmapDirectory :: new ( canonical_path, None , madvise_opt ) )
273
265
}
274
266
275
267
/// Joins a relative_path to the directory `root_path`
0 commit comments