-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
At file package that can wrap files with some helpers (#54)
* Add directfile package that satisfies io.Reader and io.ReaderAt * Add Close() * Add logging around requested bytes vs how many we're actually reading * Check for direct mode and skip all this logic if not direct * Add open with FADV_DONTNEED * Fix unix return * Fix linux * Make go happy about filenames * sdfkdjghdfg * Remove all the directio stuff and rename to file
- Loading branch information
1 parent
e7a4df2
commit 2639c76
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//go:build linux | ||
|
||
package file | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
// OpenFileFADVDONTNEED opens file with FADV_DONTNEED | ||
func OpenFileFADVDONTNEED(path string) (*os.File, error) { | ||
// Open the file | ||
file, err := os.Open(path) | ||
if err != nil { | ||
return nil, fmt.Errorf("error opening file: %w", err) | ||
} | ||
|
||
// File descriptor | ||
fd := int(file.Fd()) | ||
|
||
// Use FADV_DONTNEED to suggest not caching pages | ||
err = unix.Fadvise(fd, 0, 0, unix.FADV_DONTNEED) | ||
if err != nil { | ||
return nil, fmt.Errorf("error setting FADV_DONTNEED: %w", err) | ||
} | ||
|
||
return file, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//go:build !linux | ||
|
||
package file | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// OpenFileFADVDONTNEED opens file with FADV_DONTNEED | ||
func OpenFileFADVDONTNEED(path string) (*os.File, error) { | ||
return os.Open(path) | ||
} |