Bug 11447

Summary: default section layout should be improved to reduce pagefaults
Product: binutils Reporter: Taras Glek <tglek>
Component: ldAssignee: unassigned
Status: RESOLVED INVALID    
Severity: normal CC: bug-binutils, ojab
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:
Attachments: Reorder .gnu.version, .dynstr and .dynsym

Description Taras Glek 2010-03-29 20:29:30 UTC
I graphed pagefaults on firefox startup which showed that there some bonus page
faults caused by the default section order. The main problem is backwards io
which always causes page faults.
For reference click the second rectange in
http://people.mozilla.com/~tglek/startup/systemtap_graphs/visualize.html?#ld_bug/log.txt.html
x-axis is file offset, y-axis is time

Log of the sections being read is in
http://people.mozilla.com/~tglek/startup/systemtap_graphs/ld_bug/report.txt

Fault #1: This likely can't fixed in ld, but mentioning it in case
Going through the log chronologically there the problems are:
.bss is being zeroed which causes copy-on-write io.  Then .dynamic is being
read. The fix should be in the dynamic linker to read .dynamic before memset.
This would allow binaries(where distance between .dynamic and .bss is smaller
than the kernel's readhead) to avoid the .bss pagefault. Perhaps .dynamic should
be the last section before .bss?
Alternatively ld could force .bss to point past the end of the file.

Fault #2
.gnu.version* should be in front of .dyn(sym|str)

Fault #3
.dynstr should be in front of .dynsym


Would be nice if .eh_frame* could be in front of .fini, but as far as I can tell
these have to be in different segments.
Comment 1 drow@false.org 2010-04-02 19:52:26 UTC
Subject: Re:  New: default section layout should be improved
 to reduce pagefaults

On Mon, Mar 29, 2010 at 08:29:31PM -0000, tglek at mozilla dot com wrote:
> Fault #2
> .gnu.version* should be in front of .dyn(sym|str)
> 
> Fault #3
> .dynstr should be in front of .dynsym

Why?  Both .gnu.version and .dynstr are referred to from .dynsym.
ISTM that it would be as easy to improve the loader if it's reading
them in a funny order.

Comment 2 Nick Clifton 2010-04-13 11:53:22 UTC
Created attachment 4719 [details]
Reorder .gnu.version, .dynstr and .dynsym
Comment 3 Nick Clifton 2010-04-13 11:56:04 UTC
Hi Taras,

  This sounds like a loader problem to me, rather than a binutils bug.  It is
relatively easy to rearrange the order of the .gnu.version, .dynstr and .dynsym
sections (see the uploaded patch), but I do not think that this is right way to
solve the problem.  If the loader is performing some backwards io to get at
those sections then I would suggest that it ought to be recoded to keep them in
memory after reading them for the first time.

Cheers
  Nick