From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 3E1BD3857810 for ; Wed, 13 Mar 2024 16:08:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3E1BD3857810 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3E1BD3857810 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710346102; cv=none; b=GWHWUfhhtrSXAGKYIJ0jZSSY9/yWGt9PWLPowt/LQN8iIdeuipSmgdPNO9yuB/qA4VgM98ZsjQkhEIi00JF17dzVLIrt+5iAXPGBdKIwq8sNBY2uwK727hpui7XTwlg0JcCa7PgfdFu5rITt59WTFPmwDNTvx0qpwcLVnJI7r0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710346102; c=relaxed/simple; bh=7LJ2EmzbszuFQUl9uxOp5KdDAZ/6P+WFSTDea1Whwks=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Yz4wIabIa1CeZuNXf4VncS0PbY/6mfD9D0eiXn6eK5nxxVBlWqGkiLRKmtUIv5o9QHJ63saSWqikxJMtZyfHFRs+10mOB4bF2e7wln2Y+yI3dM0YCj4J06rhKZEl43U0QmSNCILuvhmBui+TLwyEG+Svo6vrgkNLMRl94kcMQRA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6e622b46f45so51915b3a.1 for ; Wed, 13 Mar 2024 09:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710346099; x=1710950899; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uQTBXTZcdbruE/1fEeLC5IeoZvEJqSMaG6ukEWrXp1U=; b=XEo7Aj2Qwdxd9fHg3qxQZ1hBMDggxy4DHIPt2+nbZjbma+1AyNb/fQ8hjoMm7zSjSn ndyrgt74D/Omg/jmDLIs4wmm/CSmmzPjUHXn8w8Pt3k0ZZZXk7ZjLrkzVQbad9WqfZ8X hCX4mCJ856X1q4kgK2hYoDioRWCKrmVxT3qYrt9YvSq9uYCpL8r3RNFxTepxMFkIDqyz Wzf0yCSI7dNdR/6U+zHX/Zl54EiY0FHZgy56yX6+1pbfZUFGT29N1jEh0vKptwMJAGpm +pk7EgYdt/mlaTvBxAvN83qm2G5UC6vkhDiepdufmEuir6bEUMmM7XhVSKKgZB84m1PQ rkLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710346099; x=1710950899; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uQTBXTZcdbruE/1fEeLC5IeoZvEJqSMaG6ukEWrXp1U=; b=JlUnIHFtJ//TZKqsRPDDzV1FotqjKODCEvHsgW4dlZrJrtTfrM5/4tj9F4KU5z1a+9 sFYIQg6AlHrV1FK9BPdg9i+cTmTNK+eAchJT7bPRik8lxflQYc17LztCOqRZH+dWa2Ik 60cD8KdL74O6GCXr412Pu2E6YI1HlTAjimoqw4ffsKFbHKoXmsxRGNmnvVCPAgPKws5/ TV6RiQgz2WaN+kycPQ/j7573rUmwPg0n92pkjalQ35lFXYjm3s9zMw26IidDeTSLxdxg ahpQ2o8AhJmF+tJjfmxiaKNnAu9EP96XMFgaA3n1ovXOPqurngqBMMo34KrAMGbfg4oc TBnw== X-Gm-Message-State: AOJu0YxxdrhMuEv5RH0qcaU+uMR/PU0t1/Ev90QxRiRxyKzW8JdatUo0 yyvKreK+jTV7VvRH85cI6+WSDamUzQNrQKCs7mfKA958hNE/+mwv X-Google-Smtp-Source: AGHT+IGuoVv/fLOk7XYA621+BjQBr6itm2EmVyu9SZfGKmpYVMXwPSWj8TWK71kZJpI2/ASxZ45ptQ== X-Received: by 2002:a05:6a21:170f:b0:1a3:2d92:de05 with SMTP id nv15-20020a056a21170f00b001a32d92de05mr4287385pzb.62.1710346099059; Wed, 13 Mar 2024 09:08:19 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.58.89.72]) by smtp.gmail.com with ESMTPSA id l4-20020a63f304000000b005dc5289c4edsm8044000pgh.64.2024.03.13.09.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 09:08:16 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 35006740050; Wed, 13 Mar 2024 09:08:15 -0700 (PDT) From: "H.J. Lu" To: binutils@sourceware.org Cc: goldstein.w.n@gmail.com, sam@gentoo.org, amodra@gmail.com Subject: [PATCH v9 0/6] elf: Use mmap to map in section contents Date: Wed, 13 Mar 2024 09:08:09 -0700 Message-ID: <20240313160815.665818-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3011.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_ABUSEAT,RCVD_IN_DNSWL_NONE,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Changes in v9: 1. Use MAP_FAILED for mmap failure. Changes in v8: 1. Rebase against master branch. 2. Add _bfd_elf_link_mmap_section_contents and _bfd_elf_link_munmap_section_contents. Changes in v7: 1. Don't add the --keep-memory linker option. Changes in v6: 1. Add the --keep-memory linker option and always cache symbol and relocation tables for --keep-memory. 2. Always keep symbol table and relocation info for eh_frame to speedup the Rust binary build by ~300x: https://sourceware.org/bugzilla/show_bug.cgi?id=31466 Changes in v5: 1. Drop 2 patches which have been merged onto master branch. 2. Rename _bfd_elf_mmap_section to _bfd_elf_mmap_section_contents. 3. Rename _bfd_mmap_readonly_tracked, _bfd_mmap_readonly_untracked, _bfd_munmap_readonly_untracked, _bfd_mmap_read_untracked to _bfd_mmap_readonly_persistent, _bfd_mmap_readonly_temporary, _bfd_munmap_readonly_temporary and _bfd_mmap_read_temporary. 4. Drop the setup_group change. 5. Fix a typo. 6. Update comments. Changes in v4: 1. Change don't cache symbol nor relocation tables with mmap to opt-in. Changes in v3: 1. Fix non-mmap build. 2. Change the argument name of bfd_mmap_local from flags to prot since its values are PROT_XXX. Changes in v2: 1. Don't hard-code BFD_JUMP_TABLE_COPY in bfd so that elf-bfd.h can be included in libbfd.c. 2. Change the --with-mmap default to true. 3. Check USE_MMAP instead of HAVE_MMAP. 4. Remove the asize parameter to _bfd_mmap_readonly_tracked. 5. Add contents_addr and contents_size to bfd_elf_section_data. 6. Rename _bfd_link_keep_memory to _bfd_elf_link_keep_memory. --- We can use mmap to map in ELF section contents, instead of copying them into memory by hand. We don't need to cache symbol nor relocation tables if they are mapped in. Data to link the 3.5GB clang executable in LLVM 17 debug build on Linux/x86-64 with 32GB RAM is: stdio mmap improvement user 86.73 87.02 -0.3% system 9.55 9.21 3.6% total 100.40 97.66 0.7% maximum set(GB) 17.34 13.14 24% page faults 4047667 3042877 25% and data to link the 275M cc1plus executable in GCC 14 stage 1 build is: user 5.41 5.44 -0.5% system 0.80 0.76 5% total 6.25 6.26 -0.2% maximum set(MB) 1323 968 27% page faults 323451 236371 27% Data shows that these won't improve the single copy linker performance. But they improve the overall system performance when linker is used by reducing linker memory usage and page faults. They allow more parallel linker jobs on LLVM debug build. Here is a quote from Noah Goldstein: "on a large project they are an extremely large speedup". H.J. Lu (6): elf: Use mmap to map in read-only sections elf: Add _bfd_elf_m[un]map_section_contents elf: Use mmap to map in symbol and relocation tables elf: Don't cache symbol nor relocation tables with mmap elf: Always keep symbol table and relocation info for eh_frame elf: Add _bfd_elf_link_m[un]map_section_contents bfd/bfd-in2.h | 24 ++++- bfd/bfd.c | 17 ++++ bfd/bfdwin.c | 8 +- bfd/cache.c | 7 +- bfd/compress.c | 2 +- bfd/elf-bfd.h | 33 ++++++ bfd/elf-eh-frame.c | 4 +- bfd/elf-sframe.c | 4 +- bfd/elf.c | 236 +++++++++++++++++++++++++++++++++++-------- bfd/elf32-i386.c | 8 +- bfd/elf64-x86-64.c | 12 +-- bfd/elfcode.h | 7 +- bfd/elflink.c | 188 +++++++++++++++++++++++++---------- bfd/elfxx-target.h | 6 +- bfd/elfxx-x86.c | 8 +- bfd/elfxx-x86.h | 1 + bfd/libbfd-in.h | 33 +++++- bfd/libbfd.c | 243 ++++++++++++++++++++++++++++++++++++++++++++- bfd/libbfd.h | 33 +++++- bfd/linker.c | 35 ------- bfd/lynx-core.c | 2 +- bfd/opncls.c | 21 ++++ bfd/section.c | 9 +- bfd/sysdep.h | 4 + 24 files changed, 770 insertions(+), 175 deletions(-) -- 2.44.0