diff --git a/go/kbfs/libkbfs/disk_block_cache.go b/go/kbfs/libkbfs/disk_block_cache.go index 14a32a3a0ca8..7fdc3c5a2ce7 100644 --- a/go/kbfs/libkbfs/disk_block_cache.go +++ b/go/kbfs/libkbfs/disk_block_cache.go @@ -282,8 +282,8 @@ func newDiskBlockCacheLocalFromStorage( }, tlfSizes: map[tlf.ID]uint64{}, tlfLastUnrefs: map[tlf.ID]kbfsmd.Revision{}, - compactCh: make(chan struct{}), - useCh: make(chan struct{}), + compactCh: make(chan struct{}, 1), + useCh: make(chan struct{}, 1), startedCh: startedCh, startErrCh: startErrCh, shutdownCh: make(chan struct{}), @@ -313,7 +313,12 @@ func newDiskBlockCacheLocalFromStorage( close(startedCh) }() - go cache.compactLoop() + // Only do background compaction on desktop for now, because on + // mobile we'd probably cause issues if we try to do it while + // backgrounded. + if mode.DiskCacheCompactionEnabled() { + go cache.compactLoop() + } return cache, nil } diff --git a/go/kbfs/libkbfs/interfaces.go b/go/kbfs/libkbfs/interfaces.go index 0f192c1cf2fd..56a47ca8082f 100644 --- a/go/kbfs/libkbfs/interfaces.go +++ b/go/kbfs/libkbfs/interfaces.go @@ -2074,6 +2074,9 @@ type InitMode interface { // DelayInitialConnect indicates whether the initial connection to KBFS // servers should be delayed. DelayInitialConnect() bool + // DiskCacheCompactionEnabled indicates whether the local disk + // block cache should trigger compaction automatically. + DiskCacheCompactionEnabled() bool ldbutils.DbWriteBufferSizeGetter } diff --git a/go/kbfs/libkbfs/modes.go b/go/kbfs/libkbfs/modes.go index db0595fd05f4..7ce22a1f1483 100644 --- a/go/kbfs/libkbfs/modes.go +++ b/go/kbfs/libkbfs/modes.go @@ -207,6 +207,10 @@ func (md modeDefault) DbWriteBufferSize() int { return 10 * opt.MiB // 10 MB } +func (md modeDefault) DiskCacheCompactionEnabled() bool { + return true +} + // Minimal mode: type modeMinimal struct { @@ -389,6 +393,10 @@ func (mm modeMinimal) DbWriteBufferSize() int { return 1 * opt.KiB // 1 KB } +func (mm modeMinimal) DiskCacheCompactionEnabled() bool { + return false +} + // Single op mode: type modeSingleOp struct { @@ -483,6 +491,10 @@ func (mso modeSingleOp) IsSingleOp() bool { return true } +func (mso modeSingleOp) DiskCacheCompactionEnabled() bool { + return false +} + // Single-op mode with QR: type modeSingleOpWithQR struct { @@ -623,6 +635,10 @@ func (mc modeConstrained) DbWriteBufferSize() int { return 100 * opt.KiB // 100 KB } +func (mc modeConstrained) DiskCacheCompactionEnabled() bool { + return false +} + // Memory limited mode type modeMemoryLimited struct {