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,6 +187,7 @@ func (ms *MountState) readRequest() (req *request, code Status) { ...@@ -185,6 +187,7 @@ 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
} }
...@@ -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)
......
...@@ -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