Automated rollback of changelist 633961720

PiperOrigin-RevId: 636602151
This commit is contained in:
Jamie Liu
2024-05-23 10:50:10 -07:00
committed by gVisor bot
parent 74f22885dc
commit 56ab580ccb
4 changed files with 2 additions and 45 deletions
-29
View File
@@ -222,11 +222,6 @@ type MemoryFileOpts struct {
// RestoreID is an opaque string used to reassociate the MemoryFile with its
// replacement during restore.
RestoreID string
// EnforceMaximumAllocatable is a flag that governs whether the MemoryFile
// will be limited in size of total allocations by
// usage.MaximumAllocatableBytes.
EnforceMaximumAllocatable bool
}
// DelayedEvictionType is the type of MemoryFileOpts.DelayedEviction.
@@ -544,11 +539,6 @@ func (f *MemoryFile) allocate(length uint64, opts *AllocOpts) (memmap.FileRange,
f.mu.Lock()
defer f.mu.Unlock()
if !f.hasSpaceToAllocate(length) {
log.Debugf("Enforcing memory limit on allocation of size %d, max is %d, already have %d", length, usage.MaximumAllocatableBytes, f.usageExpected)
return memmap.FileRange{}, linuxerr.ENOMEM
}
// Align hugepage-and-larger allocations on hugepage boundaries to try
// to take advantage of hugetmpfs.
alignment := uint64(hostarch.PageSize)
@@ -593,25 +583,6 @@ func (f *MemoryFile) allocate(length uint64, opts *AllocOpts) (memmap.FileRange,
return fr, nil
}
func (f *MemoryFile) hasSpaceToAllocate(length uint64) bool {
if f.opts.EnforceMaximumAllocatable && usage.MaximumAllocatableBytes != 0 && ((f.usageExpected+length) > usage.MaximumAllocatableBytes || (f.usageExpected+length) < f.usageExpected) {
// f.usageExpected is not guaranteed to be correct because it is
// updated only when f.UpdateUsage is called periodically.
// To eliminate false-positives double check against the exact
// measure; we don't care as much about false-negatives, which
// helps avoid a host-syscall via f.TotalUsage in the happy-path.
exactUsage, err := f.TotalUsage()
if err != nil {
log.Warningf("Failed to fetch total usage for memory file: %v", err)
return false
}
if (exactUsage+length) > usage.MaximumAllocatableBytes || (exactUsage+length) < exactUsage {
return false
}
}
return true
}
// findAvailableRange returns an available range in the usageSet.
//
// Note that scanning for available slots takes place from end first backwards,
+1 -3
View File
@@ -427,9 +427,7 @@ func createMemoryFile() (*pgalloc.MemoryFile, error) {
return nil, fmt.Errorf("error creating memfd: %v", err)
}
memfile := os.NewFile(uintptr(fd), memfileName)
mf, err := pgalloc.NewMemoryFile(memfile, pgalloc.MemoryFileOpts{
EnforceMaximumAllocatable: true,
})
mf, err := pgalloc.NewMemoryFile(memfile, pgalloc.MemoryFileOpts{})
if err != nil {
memfile.Close()
return nil, fmt.Errorf("error creating pgalloc.MemoryFile: %v", err)
-5
View File
@@ -374,11 +374,6 @@ var (
// MaximumTotalMemoryBytes is the maximum reported total system memory.
// The 0 value indicates no maximum.
MaximumTotalMemoryBytes uint64
// MaximumAllocatableBytes is the maximum allowed to be allocated from a
// single memory file. Usually this is the same as
// MaximumTotalMemoryBytes.
MaximumAllocatableBytes uint64
)
// TotalMemory returns the "total usable memory" available.
+1 -8
View File
@@ -513,9 +513,6 @@ func New(args Args) (*Loader, error) {
// As per tmpfs(5), the default size limit is 50% of total physical RAM.
// See mm/shmem.c:shmem_default_max_blocks().
tmpfs.SetDefaultSizeLimit(args.TotalHostMem / 2)
// Set a generous but sane on maximum allowable size for memory
// file allocates.
usage.MaximumAllocatableBytes = args.TotalHostMem
}
if args.TotalMem > 0 {
@@ -523,8 +520,6 @@ func New(args Args) (*Loader, error) {
// use /proc/meminfo can make allocations based on this limit.
usage.MinimumTotalMemoryBytes = args.TotalMem
usage.MaximumTotalMemoryBytes = args.TotalMem
// Reset max allocatable to TotalMem because it's smaller than TotalHostMem.
usage.MaximumAllocatableBytes = args.TotalMem
log.Infof("Setting total memory to %.2f GB", float64(args.TotalMem)/(1<<30))
}
@@ -738,9 +733,7 @@ func createMemoryFile() (*pgalloc.MemoryFile, error) {
// We can't enable pgalloc.MemoryFileOpts.UseHostMemcgPressure even if
// there are memory cgroups specified, because at this point we're already
// in a mount namespace in which the relevant cgroupfs is not visible.
mf, err := pgalloc.NewMemoryFile(memfile, pgalloc.MemoryFileOpts{
EnforceMaximumAllocatable: true,
})
mf, err := pgalloc.NewMemoryFile(memfile, pgalloc.MemoryFileOpts{})
if err != nil {
_ = memfile.Close()
return nil, fmt.Errorf("error creating pgalloc.MemoryFile: %w", err)