From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB5D83A4F47 for ; Tue, 10 Mar 2026 03:12:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773112354; cv=none; b=HTNh4qYTCGb126cpbQoya4JKyyFZGlWSm5Acl2RfjSex3ffLLD630m3sumIYNmwYRMs2O8/qzauDGhh0T6CJeMrvZCGVwRH7Sv7h26ZJ0rxpgT3zZ97q/LLjKQkpb/CFFC6s0b6I/3dMsQwM39OZPBy8V3aRliVDiQXhM/+8sm4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773112354; c=relaxed/simple; bh=FxuCb/kIbOwsma/01qsnWR92rq/SuGv9xfzQZP1zw7s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=WqHXIrgnXHBB4nt3E9EUxiR2ZAdpLW2Ti0sEAj24ToGjT1T28tuVs3d4rSrN3hvpIh2wChotyEgN6I67xwUjtgSoGqCUWv3CZ81rqloIweDm1zKU4O/deEug4LaDqpMvhjqesW/UTKnoA3A8id2+Ra+M/rGI7OSEuLSdDWaOrqY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hev.cc; spf=pass smtp.mailfrom=hev.cc; dkim=pass (2048-bit key) header.d=hev-cc.20230601.gappssmtp.com header.i=@hev-cc.20230601.gappssmtp.com header.b=g326AwMP; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hev.cc Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hev.cc Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hev-cc.20230601.gappssmtp.com header.i=@hev-cc.20230601.gappssmtp.com header.b="g326AwMP" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-823c56765fdso6146124b3a.1 for ; Mon, 09 Mar 2026 20:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hev-cc.20230601.gappssmtp.com; s=20230601; t=1773112353; x=1773717153; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qdvvi5cPomjzjf9BfHEmNolRXDMIdQNGPSx8FVbAXpE=; b=g326AwMPplLroeooHi4g4xDhZ/ecuEnmIWr3pmnKNf7oa0/DS0W1gE3oukCQ5nv2AN sCq9LdFlmfWArDejFqkVon7qs1WHY8r/98IRrTAhpowQ9NWkOXhShPNbMwq4x+N85xfB QFKm2xf0IUokLg1HfnsZvQwusX0CFth1hQS7s1OfIj1P348dKNxFrqFh+3jjOBY/XDxf MRXAHRGDQGs8HHcyrx/O4aHT2u9ZGUJx96L/JAqjCrQAowKBv/HoqSOfHLJBYRumi8LA pWVY6R1XmOR+PDz6vEXifWWuFlZnvNfvjpIdL2OkQ1axHP0iURvGCz6oyVjOXZ3mZM8M 8+sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773112353; x=1773717153; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qdvvi5cPomjzjf9BfHEmNolRXDMIdQNGPSx8FVbAXpE=; b=qK2V5SiCRQR+YVFcAfSpJj/bXpM8EJz05jnIMG12LopsN0RB/zU09PrOc0S5+xk0vY WPv6VC/LjdS3daHHih/3s1Hl29JBDqcfXLhA/wrLBT/JdwTrVEwN5dxad4T0IfFvQAPY +OljC/IHemTRuHVLWU7TUaxSymr9pgHGHlsk8rnfTi5GUVdGuwQKQW/EKWT+IIuA09VX P73fsKxf6L6FPQPyvA4KJ9l1cE7EIBSlcqmltdy6VHTdz28s67NGFm3+XrOxwuYwgDUH Q1CQWjtyG2AsLH1MXsJvOme2lst8iKfQyw9JFPSj0qJXl9tCc0tI43iVKEfbB3L1YsWM KRdQ== X-Forwarded-Encrypted: i=1; AJvYcCWX2oaqTM/2Mb8mMKLUXGzE/Jl+ynMrYeo+oATaUfo3rzH/WkIak3i7vMGeOimOB6QhIA+mTvWnQ84yPiI=@vger.kernel.org X-Gm-Message-State: AOJu0YwTBDophr2NqIdrNpoeqUY7PB/uBl7EiAMskGM6arTKxIBwOBqR czegQKWIsaQaNynCUhrf6vJZetFmAvjaOnP9cKYFuHPIGbaFk7rWVcFzrrWGXFW+StQ= X-Gm-Gg: ATEYQzzOFja19gIxzpe8CNDdSWoW9qu1wXRhGZCbCqv5PB3uXEo6bZeDUopy0twwwpL LLksfHXdISEu2Iu71hwrdB31x2TN2Vpkp3DBS/mDQhzg4gCqbk/OxKjEL8iUkv1Jcev2hGkfuMQ vDqDFavm1jPQcj7H1HQcoQIPOjq1km9HvdH0QBmbLDgF86PZLBXzxiOjUC+VsvZSXJUHh6pY/Wc cD/Ob1HkEiiWoimBvUsjbd6v4pTjoSXr+RpaEZqNQrwIFHsKecr/sq4KavdZ4gSwLfmcm9LPyjS 3gyUDIWRd+a4p5r5H0qwx1R2yKn5/L1GFIr6QztIvL+sPS+42zp1kKyh22aH0Cvf9GiEbzUV4wM eDVTX6r+KwzXecYfVxlko719NDT2U5vJ2swkTfERXwz313R16JLdN0ViIDYOpUszwmzXblCpEGy Rks76oddRQ X-Received: by 2002:a05:6a00:66ca:b0:827:2c79:fa84 with SMTP id d2e1a72fcca58-829a2d88cbcmr10308211b3a.12.1773112352943; Mon, 09 Mar 2026 20:12:32 -0700 (PDT) Received: from localhost ([2400:8902:e002:de08:5754:7dac:85df:935a]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-829a465c872sm14213691b3a.19.2026.03.09.20.12.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 20:12:32 -0700 (PDT) From: WANG Rui To: Alexander Viro , Andrew Morton , Baolin Wang , Barry Song , Christian Brauner , David Hildenbrand , Dev Jain , Jan Kara , Kees Cook , Lance Yang , "Liam R. Howlett" , Lorenzo Stoakes , Matthew Wilcox , Nico Pache , Ryan Roberts , Zi Yan Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, WANG Rui Subject: [PATCH v4 0/2] binfmt_elf: Align eligible read-only PT_LOAD segments to PMD_SIZE for THP Date: Tue, 10 Mar 2026 11:11:36 +0800 Message-ID: <20260310031138.509730-1-r@hev.cc> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Changes since [v3]: * Fixed compilation failure under !CONFIG_TRANSPARENT_HUGEPAGE. * No functional changes otherwise. Changes since [v2]: * Renamed align_to_pmd() to should_align_to_pmd(). * Added benchmark results to the commit message. Changes since [v1]: * Dropped the Kconfig option CONFIG_ELF_RO_LOAD_THP_ALIGNMENT. * Moved the alignment logic into a helper align_to_pmd() for clarity. * Improved the comment explaining why we skip the optimization when PMD_SIZE > 32MB. When Transparent Huge Pages (THP) are enabled in "always" mode, file-backed read-only mappings can be backed by PMD-sized huge pages if they meet the alignment and size requirements. For ELF executables loaded by the kernel ELF binary loader, PT_LOAD segments are normally aligned according to p_align, which is often only page-sized. As a result, large read-only segments that are otherwise eligible may fail to be mapped using PMD-sized THP. A segment is considered eligible if: * THP is in "always" mode, * it is not writable, * both p_vaddr and p_offset are PMD-aligned, * its file size is at least PMD_SIZE, and * its existing p_align is smaller than PMD_SIZE. To avoid excessive address space padding on systems with very large PMD_SIZE values, this optimization is applied only when PMD_SIZE <= 32MB, since requiring larger alignments would be unreasonable, especially on 32-bit systems with a much more limited virtual address space. This increases the likelihood that large text segments of ELF executables are backed by PMD-sized THP, reducing TLB pressure and improving performance for large binaries. This only affects ELF executables loaded directly by the kernel binary loader. Shared libraries loaded by user space (e.g. via the dynamic linker) are not affected. Benchmark Machine: AMD Ryzen 9 7950X (x86_64) Binutils: 2.46 GCC: 15.2.1 (built with -z,noseparate-code + --enable-host-pie) Workload: building Linux v7.0-rc1 vmlinux with x86_64_defconfig. Without patch With patch instructions 8,246,133,611,932 8,246,025,137,750 cpu-cycles 8,001,028,142,928 7,565,925,107,502 itlb-misses 3,672,158,331 26,821,242 time elapsed 64.66 s 61.97 s Instructions are basically unchanged. iTLB misses drop from ~3.67B to ~26M (~99.27% reduction), which results in about a ~5.44% reduction in cycles and ~4.18% shorter wall time for this workload. [v3]: https://lore.kernel.org/linux-fsdevel/20260310013958.103636-1-r@hev.cc [v2]: https://lore.kernel.org/linux-fsdevel/20260304114727.384416-1-r@hev.cc [v1]: https://lore.kernel.org/linux-fsdevel/20260302155046.286650-1-r@hev.cc WANG Rui (2): huge_mm: add stubs for THP-disabled configs binfmt_elf: Align eligible read-only PT_LOAD segments to PMD_SIZE for THP fs/binfmt_elf.c | 29 +++++++++++++++++++++++++++++ include/linux/huge_mm.h | 10 ++++++++++ 2 files changed, 39 insertions(+) -- 2.53.0