Skip to content

Commit

Permalink
disk_block_cache: only do explicit compaction on desktop
Browse files Browse the repository at this point in the history
Issue: HOTPOT-2508
  • Loading branch information
strib committed Apr 22, 2020
1 parent 38e9970 commit 8871298
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
11 changes: 8 additions & 3 deletions go/kbfs/libkbfs/disk_block_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}),
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions go/kbfs/libkbfs/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 16 additions & 0 deletions go/kbfs/libkbfs/modes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8871298

Please sign in to comment.