From adf70c80b292bbf73aaf49725464a50ef2c2facc Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 31 Dec 2024 06:28:15 -0300 Subject: src/dedo.go: Remove Tx.WriteFlag option Thrashing is an OS issue, not an application one. The OS should be the one tweaking the page cache to prevent it. If the OS is not doing it by itself, one needs to tweak their system's page cache size and configuration. --- src/dedo.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/dedo.go b/src/dedo.go index c4a5532..ead56b8 100644 --- a/src/dedo.go +++ b/src/dedo.go @@ -291,14 +291,6 @@ type Tx struct { pages map[pgid]*page stats TxStats commitHandlers []func() - - // WriteFlag specifies the flag for write-related methods like WriteTo(). - // Tx opens the database file with the specified flag to copy the data. - // - // By default, the flag is unset, which works well for mostly in-memory - // workloads. For databases that are much larger than available RAM, - // set the flag to syscall.O_DIRECT to avoid trashing the page cache. - WriteFlag int } // TxStats represents statistics about the actions performed by the transaction. @@ -3766,12 +3758,11 @@ func (tx *Tx) Copy(w io.Writer) error { // WriteTo writes the entire database to a writer. // If err == nil then exactly tx.Size() bytes will be written into the writer. func (tx *Tx) WriteTo(w io.Writer) (n int64, err error) { - // Attempt to open reader with WriteFlag - f, err := os.OpenFile(tx.db.path, os.O_RDONLY|tx.WriteFlag, 0) + f, err := os.OpenFile(tx.db.path, os.O_RDONLY, 0) if err != nil { return 0, err } - defer func() { _ = f.Close() }() + defer f.Close() // Generate a meta page. We use the same page data for both meta pages. buf := make([]byte, tx.db.pageSize) -- cgit v1.2.3