diff --git a/internal/goofys.go b/internal/goofys.go index de5281ab..f35588eb 100644 --- a/internal/goofys.go +++ b/internal/goofys.go @@ -529,10 +529,11 @@ func (fs *Goofys) FDCloser() { } // Try to reclaim some clean buffers -func (fs *Goofys) FreeSomeCleanBuffers(size int64) (int64, bool) { +func (fs *Goofys) FreeSomeCleanBuffers(origSize int64) (int64, bool) { freed := int64(0) haveDirty := false // Free at least 5 MB + size := origSize if size < 5*1024*1024 { size = 5*1024*1024 } @@ -640,7 +641,7 @@ func (fs *Goofys) FreeSomeCleanBuffers(size int64) (int64, bool) { } } } - } else { + } else if inode.fs.partNum(buf.offset+buf.length-1) != inode.fs.partNum(inode.lastWriteEnd) { haveDirty = true } if del >= 0 { @@ -658,7 +659,7 @@ func (fs *Goofys) FreeSomeCleanBuffers(size int64) (int64, bool) { break } } - if haveDirty { + if freed < origSize && haveDirty { fs.bufferPool.mu.Unlock() atomic.AddInt32(&fs.wantFree, 1) fs.WakeupFlusherAndWait(true) diff --git a/internal/goofys_test.go b/internal/goofys_test.go index dbe7983e..cabb9706 100644 --- a/internal/goofys_test.go +++ b/internal/goofys_test.go @@ -628,11 +628,8 @@ func (s *GoofysTest) TestMultipartWriteAndTruncate(t *C) { } func (s *GoofysTest) TestReadWriteMinimumMemory(t *C) { - if _, ok := s.cloud.(*ADLv1); ok { - s.fs.bufferPool.max = 20*1024*1024 - } else { - s.fs.bufferPool.max = 10*1024*1024 - } + // First part is fixed for "header hack", last part is "still written to" + s.fs.bufferPool.max = 20*1024*1024 s.testWriteFile(t, "testLargeFile", 21*1024*1024, 128*1024) }