mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Ensure pgalloc.MemoryFile.fileSize is always chunk-aligned.
findAvailableLocked() may return a non-aligned FileRange.End after expansion since it may round FileRange.Start down to a hugepage boundary. PiperOrigin-RevId: 315520321
This commit is contained in:
@@ -393,16 +393,17 @@ func (f *MemoryFile) Allocate(length uint64, kind usage.MemoryKind) (platform.Fi
|
||||
return platform.FileRange{}, syserror.ENOMEM
|
||||
}
|
||||
|
||||
// Expand the file if needed. Note that findAvailableRange will
|
||||
// appropriately double the fileSize when required.
|
||||
// Expand the file if needed.
|
||||
if int64(fr.End) > f.fileSize {
|
||||
if err := f.file.Truncate(int64(fr.End)); err != nil {
|
||||
// Round the new file size up to be chunk-aligned.
|
||||
newFileSize := (int64(fr.End) + chunkMask) &^ chunkMask
|
||||
if err := f.file.Truncate(newFileSize); err != nil {
|
||||
return platform.FileRange{}, err
|
||||
}
|
||||
f.fileSize = int64(fr.End)
|
||||
f.fileSize = newFileSize
|
||||
f.mappingsMu.Lock()
|
||||
oldMappings := f.mappings.Load().([]uintptr)
|
||||
newMappings := make([]uintptr, f.fileSize>>chunkShift)
|
||||
newMappings := make([]uintptr, newFileSize>>chunkShift)
|
||||
copy(newMappings, oldMappings)
|
||||
f.mappings.Store(newMappings)
|
||||
f.mappingsMu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user