From patchwork Sun Apr 5 03:53:20 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WANG Rui X-Patchwork-Id: 132701 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 28F544BA9028 for ; Sun, 5 Apr 2026 03:54:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 28F544BA9028 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 891824BA23FE for ; Sun, 5 Apr 2026 03:54:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 891824BA23FE Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 891824BA23FE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775361256; cv=none; b=YmtC2uQb54WFnYJKNuU5KP/ByyyKsu0OtPDu0YssxDCuTI1QhhfXdV9bzPiao4QkGEHr9Qi+bxuNN84EHozQI5XgFwGV7UWQSLGu7cvkwzMwaM4xFqSKVlh5VwN6WItyUb7eHFw/IpgLdvMixwpMc7a2JK1rfxjljc4rDw2ic1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775361256; c=relaxed/simple; bh=R6Yv29w4nzNxZJlsdjeV5hcaHovFXPv2WKsbGFl1ft0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=gpGktMyHzkNr59Wlf2WdEBxJ98XNpn84uswha8eijsLWPW9Uycxrvomhxkm3iSqQ7qGYa/uzVWMCCTHaO1ORrbCexaAj4HZx1ErWatzI7/rWzngCPD1hd8aiJkqJtq86jFlvo603QdkjbN8WgUaGiOEuwMShe75cq57Z3O1lYmE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 891824BA23FE Received: from loongson.cn (unknown [223.64.120.66]) by gateway (Coremail) with SMTP id _____8DxAfHi3NFpoBgiAA--.30399S3; Sun, 05 Apr 2026 11:54:10 +0800 (CST) Received: from localhost (unknown [223.64.120.66]) by front1 (Coremail) with SMTP id qMiowJBxDOHK3NFpP1JlAA--.44692S6; Sun, 05 Apr 2026 11:54:06 +0800 (CST) From: WANG Rui To: libc-alpha@sourceware.org Cc: Adhemerval Zanella , Dev Jain , Florian Weimer , Wilco Dijkstra , Xi Ruoyao , WANG Xuerui , caiyinyu , mengqinggang , Huacai Chen , hjl.tools@gmail.com, WANG Rui Subject: [PATCH v8 4/6] tunables: Add glibc.elf.thp tunable for THP-aware segment alignment Date: Sun, 5 Apr 2026 11:53:20 +0800 Message-ID: <20260405035323.558335-5-wangrui@loongson.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260405035323.558335-1-wangrui@loongson.cn> References: <20260405035323.558335-1-wangrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: qMiowJBxDOHK3NFpP1JlAA--.44692S6 X-CM-SenderInfo: pzdqw2txl6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCF4xKFyUZrW8ur15tw4UJrc_yoW5AFy3pr y3WFWYkr43AFnxCFWay3W5Aa15Jw4fKa4UGry7Kwn7Xw43Gryftay2gr47Jay7Jr47AF47 ZrZFgr47Cw4kG3cCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWrXVW3 AwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxkF7I0En4kS14v26r126r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMxCIbckI1I0E14v26r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AK xVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IUneRRtUUUUU== X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org Introduce a new tunable, `glibc.elf.thp`, to control Transparent Huge Page (THP) aware alignment of ELF loadable segments. When set to `1`, the dynamic loader will attempt to align sufficiently large `PT_LOAD` segments to the PMD huge page size when mapping them. This increases the likelihood that the kernel backs these mappings with Transparent Huge Pages. The default value is `0`, which preserves the traditional page-sized alignment and keeps existing behavior unchanged. On systems without THP support, or when THP is disabled in the kernel, enabling this tunable has no effect. Reviewed-by: Wilco Dijkstra Signed-off-by: WANG Rui --- elf/dl-tunables.list | 8 ++++++++ manual/tunables.texi | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/elf/dl-tunables.list b/elf/dl-tunables.list index 040a544c0e0..1bbf70d36fa 100644 --- a/elf/dl-tunables.list +++ b/elf/dl-tunables.list @@ -24,6 +24,14 @@ # env_alias: An alias environment variable glibc { + elf { + thp { + type: INT_32 + minval: 0 + maxval: 1 + } + } + malloc { check { type: INT_32 diff --git a/manual/tunables.texi b/manual/tunables.texi index 72769428e8c..389690d840b 100644 --- a/manual/tunables.texi +++ b/manual/tunables.texi @@ -64,6 +64,7 @@ glibc.pthread.mutex_spin_count: 100 (min: 0, max: 32767) glibc.rtld.optional_static_tls: 0x200 (min: 0x0, max: 0xffffffffffffffff) glibc.malloc.tcache_max: 0x0 (min: 0x0, max: 0xffffffffffffffff) glibc.malloc.check: 0 (min: 0, max: 3) +glibc.elf.thp: 0 (min: 0, max: 1) @end example @menu @@ -77,6 +78,8 @@ glibc.malloc.check: 0 (min: 0, max: 3) @theglibc{}. * gmon Tunables:: Tunables that control the gmon profiler, used in conjunction with gprof +* ELF Tunables:: Tunables that control Transparent Huge Page (THP) + aware alignment of ELF loadable segments @end menu @@ -763,3 +766,24 @@ whose size exceeds the available memory; in that case, an out of memory error will be printed at program startup, the profiler will be disabled, and no @file{gmon.out} file will be generated. @end deftp + +@node ELF Tunables +@section ELF Tunables +@cindex elf tunables + +@deftp Tunable glibc.elf.thp +This tunable controls Transparent Huge Page (THP) aware alignment of +ELF loadable segments. + +The default value is @code{0}, which preserves the traditional page-sized +alignment for loadable segments. + +If set to @code{1}, glibc will attempt to align sufficiently large +@code{PT_LOAD} segments to the PMD huge page size when mapping them +with @code{mmap}. This increases the likelihood that the kernel can +back these mappings with Transparent Huge Pages. + +This tunable has an effect only on systems that support Transparent +Huge Pages (currently Linux). On other systems, or if THP is disabled +at the kernel level, enabling this tunable has no effect. +@end deftp