Commit 1b34b381 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Test for read buffers too.

parent 9a0103bf
...@@ -41,6 +41,7 @@ type MountState struct { ...@@ -41,6 +41,7 @@ type MountState struct {
reqPool []*request reqPool []*request
readPool [][]byte readPool [][]byte
reqReaders int reqReaders int
outstandingReadBufs int
} }
func (ms *MountState) KernelSettings() raw.InitIn { func (ms *MountState) KernelSettings() raw.InitIn {
...@@ -168,6 +169,7 @@ func (ms *MountState) readRequest() (req *request, code Status) { ...@@ -168,6 +169,7 @@ func (ms *MountState) readRequest() (req *request, code Status) {
} else { } else {
dest = make([]byte, ms.opts.MaxWrite + 4096) dest = make([]byte, ms.opts.MaxWrite + 4096)
} }
ms.outstandingReadBufs++
ms.reqReaders++ ms.reqReaders++
ms.reqMu.Unlock() ms.reqMu.Unlock()
...@@ -185,18 +187,19 @@ func (ms *MountState) readRequest() (req *request, code Status) { ...@@ -185,18 +187,19 @@ func (ms *MountState) readRequest() (req *request, code Status) {
ms.reqMu.Lock() ms.reqMu.Lock()
if !gobbled { if !gobbled {
ms.outstandingReadBufs--
ms.readPool = append(ms.readPool, dest) ms.readPool = append(ms.readPool, dest)
dest = nil dest = nil
} }
ms.reqReaders-- ms.reqReaders--
ms.reqMu.Unlock() ms.reqMu.Unlock()
return req, OK return req, OK
} }
func (ms *MountState) returnRequest(req *request) { func (ms *MountState) returnRequest(req *request) {
ms.recordStats(req) ms.recordStats(req)
if req.bufferPoolOutputBuf != nil { if req.bufferPoolOutputBuf != nil {
ms.buffers.FreeBuffer(req.bufferPoolOutputBuf) ms.buffers.FreeBuffer(req.bufferPoolOutputBuf)
req.bufferPoolOutputBuf = nil req.bufferPoolOutputBuf = nil
...@@ -206,6 +209,7 @@ func (ms *MountState) returnRequest(req *request) { ...@@ -206,6 +209,7 @@ func (ms *MountState) returnRequest(req *request) {
ms.reqMu.Lock() ms.reqMu.Lock()
if req.bufferPoolOutputBuf != nil { if req.bufferPoolOutputBuf != nil {
ms.readPool = append(ms.readPool, req.bufferPoolInputBuf) ms.readPool = append(ms.readPool, req.bufferPoolInputBuf)
ms.outstandingReadBufs--
req.bufferPoolInputBuf = nil req.bufferPoolInputBuf = nil
} }
ms.reqPool = append(ms.reqPool, req) ms.reqPool = append(ms.reqPool, req)
...@@ -241,12 +245,12 @@ func (ms *MountState) loop() { ...@@ -241,12 +245,12 @@ func (ms *MountState) loop() {
req, errNo := ms.readRequest() req, errNo := ms.readRequest()
switch errNo { switch errNo {
case OK: case OK:
case ENOENT: case ENOENT:
continue continue
case ENODEV: case ENODEV:
// unmount // unmount
break exit break exit
default: // some other error? default: // some other error?
log.Printf("Failed to read from fuse conn: %v", errNo) log.Printf("Failed to read from fuse conn: %v", errNo)
break break
} }
...@@ -257,7 +261,7 @@ func (ms *MountState) loop() { ...@@ -257,7 +261,7 @@ func (ms *MountState) loop() {
go ms.handleRequest(req) go ms.handleRequest(req)
} }
} }
func (ms *MountState) handleRequest(req *request) { func (ms *MountState) handleRequest(req *request) {
defer ms.returnRequest(req) defer ms.returnRequest(req)
......
...@@ -44,8 +44,8 @@ func TestMemoryPressure(t *testing.T) { ...@@ -44,8 +44,8 @@ func TestMemoryPressure(t *testing.T) {
// Wait for FS to get ready. // Wait for FS to get ready.
os.Lstat(dir) os.Lstat(dir)
var wg sync.WaitGroup var wg sync.WaitGroup
for i := 0; i < 10 * _MAX_READERS; i++ { for i := 0; i < 10 * _MAX_READERS; i++ {
wg.Add(1) wg.Add(1)
go func(x int) { go func(x int) {
...@@ -58,9 +58,12 @@ func TestMemoryPressure(t *testing.T) { ...@@ -58,9 +58,12 @@ func TestMemoryPressure(t *testing.T) {
}(i) }(i)
} }
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
created := state.buffers.createdBuffers created := state.buffers.createdBuffers + state.outstandingReadBufs
t.Logf("Have %d read bufs", state.outstandingReadBufs)
if created > 2 * _MAX_READERS { if created > 2 * _MAX_READERS {
t.Errorf("created %d buffers, max reader %d", created, _MAX_READERS) t.Errorf("created %d buffers, max reader %d", created, _MAX_READERS)
} }
wg.Wait() wg.Wait()
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment