MCPcopy Create free account
hub / github.com/google/gvisor / HasUniqueRef

Method HasUniqueRef

pkg/sentry/pgalloc/pgalloc.go:1149–1168  ·  view source on GitHub ↗

HasUniqueRef returns true if all pages in the given range have exactly one reference. A return value of false is inherently racy, but if the caller holds a reference on the given range and is preventing other goroutines from copying it, then a return value of true is not racy. Preconditions: At lea

(fr memmap.FileRange)

Source from the content-addressed store, hash-verified

1147//
1148// Preconditions: At least one reference must be held on all pages in fr.
1149func (f *MemoryFile) HasUniqueRef(fr memmap.FileRange) bool {
1150 hasUniqueRef := true
1151 f.mu.Lock()
1152 defer f.mu.Unlock()
1153 f.forEachChunk(fr, func(chunk *chunkInfo, chunkFR memmap.FileRange) bool {
1154 unfree := &f.unfreeSmall
1155 if chunk.huge {
1156 unfree = &f.unfreeHuge
1157 }
1158 unfree.VisitFullRange(fr, func(ufseg unfreeIterator) bool {
1159 if ufseg.ValuePtr().refs != 1 {
1160 hasUniqueRef = false
1161 return false
1162 }
1163 return true
1164 })
1165 return hasUniqueRef
1166 })
1167 return hasUniqueRef
1168}
1169
1170// IncRef implements memmap.File.IncRef.
1171func (f *MemoryFile) IncRef(fr memmap.FileRange, memCgID uint32) {

Callers 1

Calls 5

forEachChunkMethod · 0.95
VisitFullRangeMethod · 0.80
ValuePtrMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected