@@ -6,7 +6,7 @@ pub type Result<T> = core::result::Result<T, DirEntryError>;
66/// A buffer used to hold the bytes sent from the OS for `getdents` calls
77/// We only use a buffer for syscalls on linux/android because of stable ABI(because we don't need to use a buffer for `ReadDir`)
88#[ cfg( any( target_os = "linux" , target_os = "android" , target_os = "macos" ) ) ]
9- pub type SyscallBuffer = crate :: fs:: AlignedBuffer < u8 , { crate :: fs :: BUFFER_SIZE } > ;
9+ pub type SyscallBuffer = crate :: fs:: AlignedBuffer < u8 , { BUFFER_SIZE } > ;
1010
1111/// A safe abstraction around file descriptors for internal IO
1212#[ derive( Debug ) ]
@@ -43,3 +43,52 @@ impl FileDes {
4343 !self . is_open ( )
4444 }
4545}
46+
47+ #[ cfg( all( any( target_os = "linux" , target_os = "android" ) , not( debug_assertions) ) ) ]
48+ pub const BUFFER_SIZE : usize = 8 * 4096 ;
49+ /*
50+ λ sudo strace -f fd NOMATCHLOL / -HI 2>&1 | grep getdents | head
51+ [pid 18321] getdents64(3, 0x7ff8e4000cb0 /* 21 entries */, 32768) = 520
52+ [pid 18321] getdents64(3, 0x7ff8e4000cb0 /* 0 entries */, 32768) = 0
53+ [pid 18321] getdents64(3, 0x7ff8e4000cb0 /* 7 entries */, 32768) = 224
54+ [pid 18321] getdents64(3, 0x7ff8e4000cb0 /* 0 entries */, 32768) = 0
55+ [pid 18321] getdents64(3 <unfinished ...>
56+ [pid 18327] getdents64(4 <unfinished ...>
57+
58+
59+ λ sudo strace -f ls / 2>&1 | grep getdents | head
60+ getdents64(3, 0x557e625c37a0 /* 21 entries */, 32768) = 520
61+ getdents64(3, 0x557e625c37a0 /* 0 entries */, 32768) = 0
62+
63+
64+ */
65+
66+ #[ cfg( all( any( target_os = "linux" , target_os = "android" ) , debug_assertions) ) ]
67+ pub const BUFFER_SIZE : usize = 4096 ; // Crashes during testing due to parallel processes taking up too much stack
68+
69+ #[ cfg( all( target_os = "macos" , not( debug_assertions) ) ) ]
70+ pub const BUFFER_SIZE : usize = 0x2000 ; //readdir calls this value for buffer size, look at syscall tracing below (8192)
71+
72+ #[ cfg( all( target_os = "macos" , debug_assertions) ) ]
73+ pub const BUFFER_SIZE : usize = 0x1000 ; // Give a smaller size to avoid stack overflow when going on tests
74+
75+ /*
76+ /tmp/fdf_test getdirentries ❯ sudo dtruss fd -HI . 2>&1 | grep getdirentries | head ✘ INT alexc@alexcs-iMac 00:52:24
77+
78+
79+ getdirentries64(0x3, 0x7FD166808A00, 0x2000) = 896 0
80+ getdirentries64(0x3, 0x7FD166808A00, 0x2000) = 408 0
81+ getdirentries64(0x3, 0x7FD166808A00, 0x2000) = 288 0
82+
83+
84+ /tmp/fdf_test getdirentries ❯ sudo dtruss ls . -R 2>&1 | grep getdirentries | head alexc@alexcs-iMac 00:58:19
85+
86+ getdirentries64(0x3, 0x7FEE86013C00, 0x2000) = 896 0
87+ getdirentries64(0x3, 0x7FEE86013C00, 0x2000) = 104 0
88+ getdirentries64(0x3, 0x7FEE86013C00, 0x2000) = 1520 0
89+ getdirentries64(0x3, 0x7FEE86013C00, 0x2000) = 112 0
90+ getdirentries64(0x3, 0x7FEE86013C00, 0x2000) = 344 0
91+
92+ */
93+ #[ cfg( any( target_os = "linux" , target_os = "android" , target_os = "macos" ) ) ]
94+ const_assert ! ( BUFFER_SIZE >= 4096 , "Buffer size too small!" ) ;
0 commit comments