Don't expand COW-break on executable VMAs.

PiperOrigin-RevId: 241403847
Change-Id: I4631ca05734142da6e80cdfa1a1d63ed68aa05cc
This commit is contained in:
Jamie Liu 2019-04-01 14:46:28 -07:00 committed by Shentubot
parent a4b34e2637
commit b4006686d2
1 changed files with 17 additions and 1 deletions

View File

@ -318,7 +318,23 @@ func (mm *MemoryManager) getPMAsInternalLocked(ctx context.Context, vseg vmaIter
panic(fmt.Sprintf("pma %v needs to be copied for writing, but is not readable: %v", pseg.Range(), oldpma)) panic(fmt.Sprintf("pma %v needs to be copied for writing, but is not readable: %v", pseg.Range(), oldpma))
} }
} }
copyAR := pseg.Range().Intersect(maskAR) // The majority of copy-on-write breaks on executable pages
// come from:
//
// - The ELF loader, which must zero out bytes on the last
// page of each segment after the end of the segment.
//
// - gdb's use of ptrace to insert breakpoints.
//
// Neither of these cases has enough spatial locality to
// benefit from copying nearby pages, so if the vma is
// executable, only copy the pages required.
var copyAR usermem.AddrRange
if vseg.ValuePtr().effectivePerms.Execute {
copyAR = pseg.Range().Intersect(ar)
} else {
copyAR = pseg.Range().Intersect(maskAR)
}
// Get internal mappings from the pma to copy from. // Get internal mappings from the pma to copy from.
if err := pseg.getInternalMappingsLocked(); err != nil { if err := pseg.getInternalMappingsLocked(); err != nil {
return pstart, pseg.PrevGap(), err return pstart, pseg.PrevGap(), err