<div dir="auto"><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 28, 2024, 8:44 PM Alan Modra <<a href="mailto:amodra@gmail.com">amodra@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, Jun 27, 2024 at 10:27:59PM -0700, H.J. Lu wrote:<br>
> Use _bfd_elf_link_m[un]map_section_content to mmap in SHT_GROUP section.<br>
> When mmap is used, data to link the 3.0GB clang executable in LLVM 19<br>
> debug build on Linux/x86-64 with 32GB RAM is:<br>
<br>
I don't believe any of the SHT_GROUP sections will use mmap.<br>
alan@squeak:~/src/llvm-project/build$ find . -name \*.o | xargs readelf -SW | egrep 'GROUP +[0-9a-f]+ [0-9a-f]+ 0{0,3}[^0]'<br>
  [200] .group            GROUP           0000000000000000 0008e4 0001ec 04     4986 3413  4<br>
  [236] .group            GROUP           0000000000000000 000a94 000274 04     5502 2821  4<br>
<br>
So my clang debug build only has one object with SHT_GROUP bigger<br>
than 512 bytes, far smaller than the 16k mmap threshold.  I'll only<br>
believe this is worth doing if you can show a group in real code that<br>
is large enough to actually use mmap.<br>
<br>
Likely you're using different compilers to me.  I just used the system<br>
compiler and linker on my Ubuntu-24.04 amd box.<br>
g++ (Ubuntu 13.2.0-23ubuntu4) 13.2.0<br>
GNU ld (GNU Binutils for Ubuntu) 2.42<br>
<br>
Here's the two biggest file in bin/<br>
-rwxrwxr-x 1 alan alan 4162474976 Jun 28 20:42 clang-19<br>
-rwxrwxr-x 1 alan alan 4256936064 Jun 28 20:55 clang-repl<br>
<br>
Please try with something like<br>
  if (ghdr->bfd_section->mmapped_p)<br>
    abort ();<br>
to prove the point.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">It isn't about the SHT_GROUP section size.  Since kernel will allocate at least</div><div dir="auto">1 page for its I/O even if its size is 4 bytes, mmap is more efficient.  It</div><div dir="auto">improves performance for parallel link.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
>                 malloc        mmap            improvement<br>
> user            42.15         42.18           -0.07%<br>
> system                  7.32          7.41            -1.2%<br>
> total           50.22         49.88           0.68%<br>
> context switches  4933                799             83.8%<br>
> major page faults 487         26              94.7%<br>
> <br>
>       * elf.c (process_sht_group_entries): Replace<br>
>       bfd_malloc_and_get_section and free with<br>
>       _bfd_elf_mmap_section_contents and<br>
>       _bfd_elf_munmap_section_contents.<br>
> <br>
> Signed-off-by: H.J. Lu <<a href="mailto:hjl.tools@gmail.com" target="_blank" rel="noreferrer">hjl.tools@gmail.com</a>><br>
> ---<br>
>  bfd/elf.c | 8 +++++---<br>
>  1 file changed, 5 insertions(+), 3 deletions(-)<br>
> <br>
> diff --git a/bfd/elf.c b/bfd/elf.c<br>
> index 8bb296f9637..cefb92d2595 100644<br>
> --- a/bfd/elf.c<br>
> +++ b/bfd/elf.c<br>
> @@ -607,7 +607,8 @@ process_sht_group_entries (bfd *abfd,<br>
>    unsigned char *contents;<br>
>  <br>
>    /* Read the raw contents.  */<br>
> -  if (!bfd_malloc_and_get_section (abfd, ghdr->bfd_section, &contents))<br>
> +  if (!_bfd_elf_mmap_section_contents (abfd, ghdr->bfd_section,<br>
> +                                    &contents))<br>
>      {<br>
>        _bfd_error_handler<br>
>       /* xgettext:c-format */<br>
> @@ -663,7 +664,8 @@ process_sht_group_entries (bfd *abfd,<br>
>                 gname = group_signature (abfd, ghdr);<br>
>                 if (gname == NULL)<br>
>                   {<br>
> -                   free (contents);<br>
> +                   _bfd_elf_munmap_section_contents<br>
> +                     (ghdr->bfd_section, contents);<br>
>                     return false;<br>
>                   }<br>
>               }<br>
> @@ -693,7 +695,7 @@ process_sht_group_entries (bfd *abfd,<br>
>           }<br>
>       }<br>
>      }<br>
> -  free (contents);<br>
> +  _bfd_elf_munmap_section_contents (ghdr->bfd_section, contents);<br>
>    return true;<br>
>  }<br>
>  <br>
> -- <br>
> 2.45.2<br>
<br>
-- <br>
Alan Modra<br>
</blockquote></div></div></div>