{"id":2222544,"url":"http://patchwork.ozlabs.org/api/1.2/covers/2222544/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/cover/20260412174334.3111385-1-wangrui@loongson.cn/","project":{"id":41,"url":"http://patchwork.ozlabs.org/api/1.2/projects/41/?format=json","name":"GNU C Library","link_name":"glibc","list_id":"libc-alpha.sourceware.org","list_email":"libc-alpha@sourceware.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260412174334.3111385-1-wangrui@loongson.cn>","list_archive_url":null,"date":"2026-04-12T17:43:28","name":"[v9,0/6] elf: THP-aware load segment alignment","submitter":{"id":85150,"url":"http://patchwork.ozlabs.org/api/1.2/people/85150/?format=json","name":"WANG Rui","email":"wangrui@loongson.cn"},"mbox":"http://patchwork.ozlabs.org/project/glibc/cover/20260412174334.3111385-1-wangrui@loongson.cn/mbox/","series":[{"id":499622,"url":"http://patchwork.ozlabs.org/api/1.2/series/499622/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/list/?series=499622","date":"2026-04-12T17:43:29","name":"elf: THP-aware load segment alignment","version":9,"mbox":"http://patchwork.ozlabs.org/series/499622/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/covers/2222544/comments/","headers":{"Return-Path":"<libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":["incoming@patchwork.ozlabs.org","libc-alpha@sourceware.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","libc-alpha@sourceware.org"],"Authentication-Results":["legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n dmarc=none (p=none dis=none) header.from=loongson.cn","sourceware.org; spf=pass smtp.mailfrom=loongson.cn","server2.sourceware.org;\n arc=none smtp.remote-ip=114.242.206.163"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4ftybP3rLvz1yCx\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 13 Apr 2026 03:44:27 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id E99C24BA23DC\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 12 Apr 2026 17:44:23 +0000 (GMT)","from mail.loongson.cn (mail.loongson.cn [114.242.206.163])\n by sourceware.org (Postfix) with ESMTP id 216644BA2E18\n for <libc-alpha@sourceware.org>; Sun, 12 Apr 2026 17:44:00 +0000 (GMT)","from loongson.cn (unknown [223.64.120.66])\n by gateway (Coremail) with SMTP id _____8BxMKvc2dtp24QkAA--.2550S3;\n Mon, 13 Apr 2026 01:43:56 +0800 (CST)","from localhost (unknown [223.64.120.66])\n by front1 (Coremail) with SMTP id qMiowJBxxuLT2dtpi51rAA--.48016S2;\n Mon, 13 Apr 2026 01:43:51 +0800 (CST)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org E99C24BA23DC","OpenDKIM Filter v2.11.0 sourceware.org 216644BA2E18"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 216644BA2E18","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 216644BA2E18","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776015841; cv=none;\n b=fRfBbDgIyjagrpzfnoCIOCwWfLQRvkC/oVxMn3RW/Cab5QPYmFtoXWJQEOFaNneABEwB7bEg/ghDLBv4oXa1IUF1nuUwAwgYrit7NioeGiV6ib1WZw0hLAsLgfOuFHj5bsC83k527P8GeOfE73FFoao4U5nbTNUURS3xKuSrhfc=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776015841; c=relaxed/simple;\n bh=n96aGtQ8wI5mWuGwjFfwLKZGDmnuWEpA91nYIk4bfr8=;\n h=From:To:Subject:Date:Message-ID:MIME-Version;\n b=x9ZB/075RxQl/tM2HsbH0toQxm8U77uktQybwSVO9vxKMQkdBJ7ZdSN98X9tnnd7aQNrF+G95Lvt0mEFHht5WAkyFIxKbNWgmhW+fG3ACaHD8RjqtkhMbTsDnMq4KSy3wz5lF+IVY5mx4Q/vthEm1gLme4iw9ECzUgkaeHogYYA=","ARC-Authentication-Results":"i=1; server2.sourceware.org","From":"WANG Rui <wangrui@loongson.cn>","To":"libc-alpha@sourceware.org","Cc":"Adhemerval Zanella <adhemerval.zanella@linaro.org>,\n Dev Jain <dev.jain@arm.com>, Florian Weimer <fweimer@redhat.com>,\n Wilco Dijkstra <Wilco.Dijkstra@arm.com>, Xi Ruoyao <xry111@xry111.site>,\n WANG Xuerui <git@xen0n.name>, caiyinyu <caiyinyu@loongson.cn>,\n mengqinggang <mengqinggang@loongson.cn>,\n Huacai Chen <chenhuacai@kernel.org>, hjl.tools@gmail.com,\n WANG Rui <wangrui@loongson.cn>","Subject":"[PATCH v9 0/6] elf: THP-aware load segment alignment","Date":"Mon, 13 Apr 2026 01:43:28 +0800","Message-ID":"<20260412174334.3111385-1-wangrui@loongson.cn>","X-Mailer":"git-send-email 2.53.0","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","X-CM-TRANSID":"qMiowJBxxuLT2dtpi51rAA--.48016S2","X-CM-SenderInfo":"pzdqw2txl6z05rqj20fqof0/","X-Coremail-Antispam":"1Uk129KBj93XoWxCw45Cw4furWrXF48Xr1DurX_yoWrKF18pF\n WSkFn5KFWYyry7CFZay3W7Xwnaqa1rGrW5Cw13Kw1DX34rWF1xWan2vF13WFy7Gr1UJF40\n qrn2qFn5Za4rZacCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa\n sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU\n 0xBIdaVrnRJUUUvKb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2\n IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v\n e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI\n 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVWUJVW8JwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_\n Jr0_Gr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2\n x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17\n McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr4\n 1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_\n JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17\n CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0\n I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I\n 8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU\n 0xZFpf9x07je0PfUUUUU=","X-BeenThere":"libc-alpha@sourceware.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Libc-alpha mailing list <libc-alpha.sourceware.org>","List-Unsubscribe":"<https://sourceware.org/mailman/options/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe>","List-Archive":"<https://sourceware.org/pipermail/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-request@sourceware.org?subject=help>","List-Subscribe":"<https://sourceware.org/mailman/listinfo/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=subscribe>","Errors-To":"libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org"},"content":"Changes since [v8]:\n  * Add a new test case.\n  * Minor formatting fixes.\n  * Mark _dl_map_segment_align with attribute_hidden.\n\nChanges since [v7]:\n  * Rename tunable glibc.elf.hugetlb to glibc.elf.thp.\n  * Rebase on current master.\n\nChanges since [v6]:\n  * Move MAX_THP_PAGESIZE to hugepages.\n  * Skip THP mode probing when DL_MAP_DEFAULT_THP_PAGESIZE is non-zero.\n\nChanges since [v5]:\n  * No functional changes.\n  * Add benchmark results to the commit message.\n\nChanges since [v4]:\n  * Merge malloc-hugepages into hugepages.\n  * Limit the glibc.elf.hugetlb tunable maximum value to 1.\n\nChanges since [v3]:\n  * Rebased on current master.\n  * Resolved conflicts with recently merged changes.\n  * No functional changes intended.\n\nChanges since [v2]:\n  * Refactor THP detection into a new generic hugepages abstraction,\n    moving helpers out of malloc-hugepages.\n  * Add a new tunable, `glibc.elf.hugetlb`, to control THP-aware ELF\n    segment alignment.\n  * Move the Linux implementation of `_dl_map_segment_align` to\n    sysdeps/unix/sysv/linux/, making it generic for Linux (including\n    32-bit) and avoiding wordsize-64-specific overrides.\n  * Use `static inline` instead of `static __always_inline`.\n\nChanges since [v1]:\n  * Fix CI build failure (-Wunused-function).\n\nThis patch series introduces a small extension point in the ELF loader to allow\narchitecture-specific adjustment of load segment alignment, and uses it to\nimprove Transparent Huge Page (THP) usage on Linux.\n\nPatch 1 removes a redundant declaration of `_dl_map_segments` from\ndl-load.h, avoiding `-Wunused-function` build failures and keeping the\nprototype colocated with its definition.\n\nPatch 2 adds a new helper, `_dl_map_segment_align`, which is called when\ndetermining the maximum alignment for ELF load segments. The generic\nimplementation is a no-op and preserves existing behavior.\n\nPatch 3 introduces a new tunable, `glibc.elf.hugetlb`, which controls\nTHP-aware alignment of ELF loadable segments. By default, the value is 0\nand existing behavior is preserved.\n\nPatch 4 provides a Linux implementation of `_dl_map_segment_align` that\nopportunistically aligns large, suitably aligned, non-writable `PT_LOAD`\nsegments to the system’s default THP page size when THP is configured to\nbe used unconditionally and the tunable is enabled.\n\nPatch 5 enables this behavior by default on LoongArch64 Linux and defines\nthe default THP page size (32MB), matching the architecture’s PMD huge page\ngeometry.\n\nPatch 6 adds a new test for THP alignment of large load segments.\n\n[v8]: https://sourceware.org/pipermail/libc-alpha/2026-April/176440.html\n[v7]: https://sourceware.org/pipermail/libc-alpha/2026-March/175776.html\n[v6]: https://sourceware.org/pipermail/libc-alpha/2026-March/175737.html\n[v5]: https://sourceware.org/pipermail/libc-alpha/2026-March/175694.html\n[v4]: https://sourceware.org/pipermail/libc-alpha/2026-March/175644.html\n[v3]: https://sourceware.org/pipermail/libc-alpha/2026-February/175464.html\n[v2]: https://sourceware.org/pipermail/libc-alpha/2026-February/175394.html\n[v1]: https://sourceware.org/pipermail/libc-alpha/2026-February/175359.html\n\nWANG Rui (6):\n  elf: Remove redundant _dl_map_segments declaration from dl-load.h\n  elf: Introduce _dl_map_segment_align hook for segment alignment tuning\n  tunables: Add glibc.elf.thp tunable for THP-aware segment alignment\n  elf: Align large load segments to PMD huge page size for THP\n  loongarch: Enable THP-aligned load segments by default on 64-bit\n  elf: Add test for THP alignment of large load segments\n\n elf/dl-load.c                                 |   4 +\n elf/dl-load.h                                 |   5 +-\n elf/dl-tunables.list                          |   8 +\n manual/tunables.texi                          |  24 +++\n sysdeps/generic/dl-map-segment-align.h        |  26 +++\n sysdeps/unix/sysv/linux/Makefile              |   8 +-\n .../unix/sysv/linux/dl-map-segment-align.c    |  55 +++++++\n .../unix/sysv/linux/dl-map-segment-align.h    |  27 ++++\n .../unix/sysv/linux/loongarch/cpu-features.c  |   6 +\n .../loongarch/lp64/dl-map-segment-align.h     |  22 +++\n sysdeps/unix/sysv/linux/tst-thp-align.c       | 149 ++++++++++++++++++\n sysdeps/unix/sysv/linux/tst-thp-size-mod.S    |  22 +++\n 12 files changed, 352 insertions(+), 4 deletions(-)\n create mode 100644 sysdeps/generic/dl-map-segment-align.h\n create mode 100644 sysdeps/unix/sysv/linux/dl-map-segment-align.c\n create mode 100644 sysdeps/unix/sysv/linux/dl-map-segment-align.h\n create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/dl-map-segment-align.h\n create mode 100644 sysdeps/unix/sysv/linux/tst-thp-align.c\n create mode 100644 sysdeps/unix/sysv/linux/tst-thp-size-mod.S"}