Skip to content

Commit 33ac19e

Browse files
committed
Remove all the directio stuff and rename to file
1 parent 819e744 commit 33ac19e

File tree

6 files changed

+42
-209
lines changed

6 files changed

+42
-209
lines changed

pkg/directfile/alignedbuffer.go

-17
This file was deleted.

pkg/directfile/directfile.go

-125
This file was deleted.

pkg/directfile/file_linux.go

-49
This file was deleted.

pkg/directfile/file_nodirect.go

-18
This file was deleted.

pkg/file/file_linux.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//go:build linux
2+
3+
package file
4+
5+
import (
6+
"fmt"
7+
"os"
8+
9+
"golang.org/x/sys/unix"
10+
)
11+
12+
// OpenFileFADVDONTNEED opens file with FADV_DONTNEED
13+
func OpenFileFADVDONTNEED(path string) (*os.File, error) {
14+
// Open the file
15+
file, err := os.Open(path)
16+
if err != nil {
17+
return nil, fmt.Errorf("error opening file: %w", err)
18+
}
19+
20+
// File descriptor
21+
fd := int(file.Fd())
22+
23+
// Use FADV_DONTNEED to suggest not caching pages
24+
err = unix.Fadvise(fd, 0, 0, unix.FADV_DONTNEED)
25+
if err != nil {
26+
return nil, fmt.Errorf("error setting FADV_DONTNEED: %w", err)
27+
}
28+
29+
return file, nil
30+
}

pkg/file/file_notlinux.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build !linux
2+
3+
package file
4+
5+
import (
6+
"os"
7+
)
8+
9+
// OpenFileFADVDONTNEED opens file with FADV_DONTNEED
10+
func OpenFileFADVDONTNEED(path string) (*os.File, error) {
11+
return os.Open(path)
12+
}

0 commit comments

Comments
 (0)