|
1 | | -package wal |
2 | | - |
3 | | -import ( |
4 | | - "runtime" |
| 1 | +//go:build !linux |
| 2 | +// +build !linux |
5 | 3 |
|
6 | | - "golang.org/x/sys/unix" |
7 | | -) |
| 4 | +package wal |
8 | 5 |
|
9 | | -// fadviseNoLinuxPageCache advises Linux to evict |
| 6 | +// fadviseNoLinuxPageCache does nothing if GOOS != "linux". |
| 7 | +// Otherwise, fadviseNoLinuxPageCache advises Linux to evict |
10 | 8 | // a file from Linux page cache. This calls unix.Fadvise which |
11 | 9 | // in turn calls posix_fadvise with POSIX_FADV_DONTNEED. |
12 | | -// If GOOS != "linux" then this function does nothing. |
13 | 10 | // CAUTION: If fsync=true, this will call unix.Fsync which |
14 | 11 | // can cause performance hit especially when used inside a loop. |
15 | 12 | func fadviseNoLinuxPageCache(fd uintptr, fsync bool) error { |
16 | | - return fadviseSegmentNoLinuxPageCache(fd, 0, 0, fsync) |
| 13 | + return nil |
17 | 14 | } |
18 | 15 |
|
19 | | -// fadviseSegmentNoLinuxPageCache advises Linux to evict the |
| 16 | +// fadviseNoLinuxPageCache does nothing if GOOS != "linux". |
| 17 | +// Otherwise, fadviseSegmentNoLinuxPageCache advises Linux to evict |
20 | 18 | // file segment from Linux page cache. This calls unix.Fadvise |
21 | 19 | // which in turn calls posix_fadvise with POSIX_FADV_DONTNEED. |
22 | 20 | // If GOOS != "linux" then this function does nothing. |
23 | 21 | // CAUTION: If fsync=true, this will call unix.Fsync which |
24 | 22 | // can cause performance hit especially when used inside a loop. |
25 | 23 | func fadviseSegmentNoLinuxPageCache(fd uintptr, off, len int64, fsync bool) error { |
26 | | - if runtime.GOOS != "linux" { |
27 | | - return nil |
28 | | - } |
29 | | - |
30 | | - // Optionally call fsync because dirty pages won't be evicted. |
31 | | - if fsync { |
32 | | - _ = unix.Fsync(int(fd)) // ignore error because this is optional |
33 | | - } |
34 | | - |
35 | | - // Fadvise under the hood calls posix_fadvise. |
36 | | - // posix_fadvise doc from man page says: |
37 | | - // "posix_fadvise - predeclare an access pattern for file data" |
38 | | - // "The advice applies to a (not necessarily existent) region |
39 | | - // starting at offset and extending for len bytes (or until |
40 | | - // the end of the file if len is 0) within the file referred |
41 | | - // to by fd. The advice is not binding; it merely constitutes |
42 | | - // an expectation on behalf of the application." |
43 | | - return unix.Fadvise(int(fd), off, len, unix.FADV_DONTNEED) |
| 24 | + return nil |
44 | 25 | } |
0 commit comments