From patchwork Thu Feb 26 06:33:02 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WANG Rui X-Patchwork-Id: 130665 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 84CAE4B9DB64 for ; Thu, 26 Feb 2026 06:34:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 84CAE4B9DB64 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 E637A4BA23CA for ; Thu, 26 Feb 2026 06:34:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E637A4BA23CA 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 E637A4BA23CA 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=1772087665; cv=none; b=RunUAZzDX9hYbT+80uIl/nKKiLlV7PZdSbCy3xr/fB7ovx3mWoqybfOeC25lsnTrD+aTuoiD3romDkPRSqNMxl2a1woF6t6nEvppX/rh1jiCuMisE+qGVqV+yGXC+g2hWVRL3/iBjoWTLgiUG3j6rqolsgEBV2R1k5LSyRPEuE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772087665; c=relaxed/simple; bh=aMguE29MrWgCBUzSe8chtZhdr48ycpqDJ2+GEjinvhg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=R93JPcvpNdJj084lysl1lNPe69Uzxev4vmRlYiOdyZrI27KyVRsx7bpdHzysvkhH3OmIHmQXilVAZWhfrYRvS3HDWkQbF2G0fTjuVwlyZLdlzF8aHWGV0NJtX/uN33+iPob1pbHTzFhI5kJDpaSWjsJ1I5sZCmOjJHeJDoOZlxQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E637A4BA23CA Received: from loongson.cn (unknown [223.64.120.216]) by gateway (Coremail) with SMTP id _____8CxJMFu6Z9pAlkVAA--.17992S3; Thu, 26 Feb 2026 14:34:22 +0800 (CST) Received: from localhost (unknown [223.64.120.216]) by front1 (Coremail) with SMTP id qMiowJAxVcBY6Z9pFhhLAA--.21582S3; Thu, 26 Feb 2026 14:34:19 +0800 (CST) From: WANG Rui To: libc-alpha@sourceware.org Cc: Adhemerval Zanella , Florian Weimer , Wilco Dijkstra , Xi Ruoyao , WANG Xuerui , caiyinyu , mengqinggang , WANG Rui Subject: [PATCH v2 1/4] elf: Remove redundant _dl_map_segments declaration from dl-load.h Date: Thu, 26 Feb 2026 14:33:02 +0800 Message-ID: <20260226063305.2141669-2-wangrui@loongson.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260226063305.2141669-1-wangrui@loongson.cn> References: <20260226063305.2141669-1-wangrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: qMiowJAxVcBY6Z9pFhhLAA--.21582S3 X-CM-SenderInfo: pzdqw2txl6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxJr4kZry7Jw4kWrW8CFW5XFc_yoW8Cw4UpF 1Yka4rKFn3Ca1rua9rta17Ka13Zrn5Jw45Xry3W397Xwn7Wr4xXFWrK3WY934fJrZ5JayS vF9rKr15AF4FkrXCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Fb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07 AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWU tVWrXwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7V AKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v2 6r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1I6r4UMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIx AIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2 KfnxnUUI43ZEXa7IU8N6pPUUUUU== X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, 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 The function `_dl_map_segments` is defined in ``, which provides the canonical implementation (optionally overridden by sysdeps variants). All call sites include `` directly, so declaring `_dl_map_segments` in `dl-load.h` is unnecessary. Keeping a static prototype in `dl-load.h` can trigger -Wunused-function errors when the header is included by translation units that do not include `` and do not reference `_dl_map_segments`. Since glibc builds with `-Werror`, this results in build failures [1]. Remove the redundant declaration from `dl-load.h` to avoid these spurious warnings and keep the declaration colocated with the definition as intended. * elf/dl-load.h (_dl_map_segments): Remove prototype. [1] https://ci.linaro.org/job/tcwg_glibc_build--master-aarch64-precommit/4624/artifact/artifacts/artifacts.precommit/notify/mail-body.txt Signed-off-by: WANG Rui --- elf/dl-load.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/elf/dl-load.h b/elf/dl-load.h index dbc29b335e..897c4034c5 100644 --- a/elf/dl-load.h +++ b/elf/dl-load.h @@ -109,14 +109,15 @@ _dl_postprocess_loadcmd (struct link_map *l, const ElfW(Ehdr) *header, The file defines this function. The canonical implementation in elf/dl-map-segments.h might be replaced by a sysdeps - version. */ + version. + static const char *_dl_map_segments (struct link_map *l, int fd, const ElfW(Ehdr) *header, int type, const struct loadcmd loadcmds[], size_t nloadcmds, const size_t maplength, bool has_holes, - struct link_map *loader); + struct link_map *loader); */ /* All the error message strings _dl_map_segments might return are listed here so that different implementations in different sysdeps From patchwork Thu Feb 26 06:33:03 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WANG Rui X-Patchwork-Id: 130666 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 930204B9DB5B for ; Thu, 26 Feb 2026 06:35:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 930204B9DB5B 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 328984BA23CB for ; Thu, 26 Feb 2026 06:34:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 328984BA23CB 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 328984BA23CB 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=1772087667; cv=none; b=KdO5xwjVN2ToC9QPF67kzNlN+VMxKvjyEoOe6ednKpgtxPB6qkxxOgo+5TYSlUrpnXhD6LOoLhFW/0ySM08zDjme5r9k+/Uu0U1Atk/XIJ7vYUtMHXdWzUrA8sPLYYTXpfjdZzk4yVFDxIH0ZSlqsTgRJ84aIPK8dxB92uzVs24= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772087667; c=relaxed/simple; bh=W9NtmSaM/yCr5jXGUhpyRXzj/9fFRu3r0nZP+cRh+/k=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=IquC6tRh3chUdGvmWSaYcXd03+ESLwSKmLBPeIe3L/s+LTLyCM713UCjU0hAUzCKGn9deXKu+RQM/DXlgDXsgQt93ZKkVwqbrf16uylJ0c6n18EaW4fnpcdz4WWC1xRRVGzVAb9LV4dMmDksDCXdGjN+YsXQhgd5otxMX2OEHxc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 328984BA23CB Received: from loongson.cn (unknown [223.64.120.216]) by gateway (Coremail) with SMTP id _____8Bx08Bw6Z9pCVkVAA--.6151S3; Thu, 26 Feb 2026 14:34:24 +0800 (CST) Received: from localhost (unknown [223.64.120.216]) by front1 (Coremail) with SMTP id qMiowJAxVcBY6Z9pFhhLAA--.21582S4; Thu, 26 Feb 2026 14:34:22 +0800 (CST) From: WANG Rui To: libc-alpha@sourceware.org Cc: Adhemerval Zanella , Florian Weimer , Wilco Dijkstra , Xi Ruoyao , WANG Xuerui , caiyinyu , mengqinggang , WANG Rui Subject: [PATCH v2 2/4] elf: Introduce _dl_map_segment_align hook for segment alignment tuning Date: Thu, 26 Feb 2026 14:33:03 +0800 Message-ID: <20260226063305.2141669-3-wangrui@loongson.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260226063305.2141669-1-wangrui@loongson.cn> References: <20260226063305.2141669-1-wangrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: qMiowJAxVcBY6Z9pFhhLAA--.21582S4 X-CM-SenderInfo: pzdqw2txl6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCFyktFW8tF4Dur1DXFW8GrX_yoW5CrW3pF 92kF4rKF1rJF17CFZ7t3W2yr15X3WrGF4YyrnxuwnrZrs7GFy8XrZIv3W5WryrGrW8CF4a vFZFqF98CF4rA3gCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Fb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07 AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWU tVWrXwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7V AKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v2 6r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6ryUMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIx AIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2 KfnxnUUI43ZEXa7IU8y8BUUUUUU== X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, 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 helper function, _dl_map_segment_align, to allow architecture-specific adjustment of ELF load segment alignment during object mapping. The generic ELF loader now calls this hook when determining the maximum segment alignment. The generic implementation is a no-op and preserves existing behavior. This provides a well-defined extension point for architectures that need to adjust segment alignment policies (for example, to improve mapping efficiency or enable platform-specific optimizations) without embedding such logic directly in the generic loader. * elf/dl-load.c (_dl_map_object_from_fd): Call _dl_map_segment_align to allow sysdeps to adjust maximum segment alignment. * sysdeps/generic/dl-map-segment-align.h: New file with generic no-op implementation. Signed-off-by: WANG Rui --- elf/dl-load.c | 4 ++++ sysdeps/generic/dl-map-segment-align.h | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 sysdeps/generic/dl-map-segment-align.h diff --git a/elf/dl-load.c b/elf/dl-load.c index 7355eef8e7..f3d943e99c 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -71,6 +71,7 @@ struct filebuf #include #include #include +#include #include #include #include @@ -1171,6 +1172,9 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, /* Optimize a common case. */ c->prot = pf_to_prot (ph->p_flags); + + /* Architecture-specific adjustment of segment alignment. */ + p_align_max = _dl_map_segment_align (c, p_align_max); break; case PT_TLS: diff --git a/sysdeps/generic/dl-map-segment-align.h b/sysdeps/generic/dl-map-segment-align.h new file mode 100644 index 0000000000..5bc2f21288 --- /dev/null +++ b/sysdeps/generic/dl-map-segment-align.h @@ -0,0 +1,26 @@ +/* _dl_map_segment_align. Generic version. + Copyright (C) 2026 Free Software Foundation, Inc. + Copyright The GNU Toolchain Authors. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +static __always_inline ElfW(Addr) +_dl_map_segment_align (const struct loadcmd *c, ElfW(Addr) p_align_max) +{ + return p_align_max; +} From patchwork Thu Feb 26 06:33:04 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WANG Rui X-Patchwork-Id: 130667 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 1054F4BAD15A for ; Thu, 26 Feb 2026 06:35:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1054F4BAD15A 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 EB36D4BA23CE for ; Thu, 26 Feb 2026 06:34:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EB36D4BA23CE 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 EB36D4BA23CE 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=1772087670; cv=none; b=Bm9svOsEuU/PVe0QWdIMR+ib+C4dgVaHn5KyReBRfTkHMb1U8SwKPpntQO+ejQG9IO27qzEdqr9FXE7TaaVh3tfdi1zhMLxMqX9ViM8QMSPnONyK/bl09csG+dlF7roXXRFIzJw+9Ywe96uxTU0rf/KCSTf9H0AURHIywMgMKvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772087670; c=relaxed/simple; bh=1NkSY6zsqMA8XLzGr79y3yvlWIM4i68T2OgGm5FRAaU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=cysYuthg/E2FYnEdoEF8LRNsjxtvAhJwPHwP87rnuP4mva9bviYx6ynlKx2KXCu+IVx9SEbEdATOFxe3l8Z8/tWDIXtP5L0YGtiqa/vJ1irTN8wh/b75G8m2f0gcfYuIoSJmabf4c+hA42jT56ZJ8n+hWsLl0QubCL/uJJtXs/k= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB36D4BA23CE Received: from loongson.cn (unknown [223.64.120.216]) by gateway (Coremail) with SMTP id _____8DxAfFx6Z9pEFkVAA--.65386S3; Thu, 26 Feb 2026 14:34:25 +0800 (CST) Received: from localhost (unknown [223.64.120.216]) by front1 (Coremail) with SMTP id qMiowJAxVcBY6Z9pFhhLAA--.21582S5; Thu, 26 Feb 2026 14:34:24 +0800 (CST) From: WANG Rui To: libc-alpha@sourceware.org Cc: Adhemerval Zanella , Florian Weimer , Wilco Dijkstra , Xi Ruoyao , WANG Xuerui , caiyinyu , mengqinggang , WANG Rui Subject: [PATCH v2 3/4] elf: Align large load segments to PMD huge page size for THP Date: Thu, 26 Feb 2026 14:33:04 +0800 Message-ID: <20260226063305.2141669-4-wangrui@loongson.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260226063305.2141669-1-wangrui@loongson.cn> References: <20260226063305.2141669-1-wangrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: qMiowJAxVcBY6Z9pFhhLAA--.21582S5 X-CM-SenderInfo: pzdqw2txl6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoW3Gry7tr47uF1fCw4xJFWxZrc_yoWxCF48pF 4akF45GFWrXFy8CFySg3WUAr1Yqa1rGr98A343uw13AwnrGFyxWFsFya43XryxGrWfCF48 ZFsrtF98ur4rZagCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU92b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07 AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWU tVWrXwAv7VC2z280aVAFwI0_Cr0_Gr1UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x 0EwIxGrwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AK xVWUXVWUAwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67 AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW5JVW7JwCI 42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMI IF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVF xhVjvjDU0xZFpf9x07j8a9-UUUUU= X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED 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 Mapping segments that are at least the size of a PMD huge page to huge-page-aligned addresses helps make them eligible for Transparent Huge Pages (THP). This patch introduces a Linux-specific helper, `_dl_map_segment_align`, to determine an appropriate maximum alignment for ELF load segments on 64-bit systems based on the system THP policy. The optimization is enabled only when the glibc tunable `glibc.malloc.hugetlb=1` is set and THP is configured to be used unconditionally. When enabled, the helper queries the default THP page size and uses it to align sufficiently large load segments that are already properly aligned in both virtual address and file offset. For eligible segments, the alignment is bumped to the THP page size, which improves THP eligibility, reduces TLB pressure, and improves performance for large objects. To avoid excessive address space padding on systems with very large THP sizes, the alignment is capped at 32MB. The optimization is applied only to writable segments, matching typical THP usage. * sysdeps/unix/sysv/linux/wordsize-64/dl-map-segment-align.c (_dl_map_segment_align): Determine segment alignment based on THP policy and default huge page size. * sysdeps/unix/sysv/linux/wordsize-64/dl-map-segment-align.h: New header. * sysdeps/unix/sysv/linux/Makefile (dl-routines): Add dl-map-segment-align. * sysdeps/unix/sysv/linux/malloc-hugepages.c: Exclude THP helpers from rtld. Signed-off-by: WANG Rui --- sysdeps/unix/sysv/linux/Makefile | 1 + sysdeps/unix/sysv/linux/malloc-hugepages.c | 4 ++ .../linux/wordsize-64/dl-map-segment-align.c | 56 +++++++++++++++++++ .../linux/wordsize-64/dl-map-segment-align.h | 23 ++++++++ 4 files changed, 84 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/wordsize-64/dl-map-segment-align.c create mode 100644 sysdeps/unix/sysv/linux/wordsize-64/dl-map-segment-align.h diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index c6bd97abf1..9879fec9a9 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -673,6 +673,7 @@ endif ifeq ($(subdir),elf) dl-routines += \ + dl-map-segment-align \ dl-rseq-symbols \ # dl-routines diff --git a/sysdeps/unix/sysv/linux/malloc-hugepages.c b/sysdeps/unix/sysv/linux/malloc-hugepages.c index 77b49374e6..28930c0e53 100644 --- a/sysdeps/unix/sysv/linux/malloc-hugepages.c +++ b/sysdeps/unix/sysv/linux/malloc-hugepages.c @@ -81,6 +81,8 @@ __malloc_thp_mode (void) return malloc_thp_mode_not_supported; } +#if !IS_IN (rtld) + static size_t malloc_default_hugepage_size (void) { @@ -205,3 +207,5 @@ __malloc_hugepage_config (size_t requested, size_t *pagesize, int *flags) __close_nocancel (dirfd); } + +#endif /* !IS_IN(rtld) */ diff --git a/sysdeps/unix/sysv/linux/wordsize-64/dl-map-segment-align.c b/sysdeps/unix/sysv/linux/wordsize-64/dl-map-segment-align.c new file mode 100644 index 0000000000..3c57d593bd --- /dev/null +++ b/sysdeps/unix/sysv/linux/wordsize-64/dl-map-segment-align.c @@ -0,0 +1,56 @@ +/* _dl_map_segment_align. Linux version. + Copyright (C) 2026 Free Software Foundation, Inc. + Copyright The GNU Toolchain Authors. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +#define MAX_THP_PAGESIZE (32 * 1024 * 1024) + +ElfW (Addr) +_dl_map_segment_align (const struct loadcmd *c, ElfW (Addr) p_align_max) +{ + static enum malloc_thp_mode_t thp_mode = malloc_thp_mode_not_supported; + static unsigned long int thp_pagesize; + +#ifndef DL_MAP_SEGMENT_ALIGN_THP_DEFAULT + if (TUNABLE_GET (glibc, malloc, hugetlb, size_t, NULL) != 1) + return p_align_max; +#endif + + if (__glibc_unlikely (thp_mode == malloc_thp_mode_not_supported + || thp_pagesize == 0)) + { + thp_mode = __malloc_thp_mode (); + thp_pagesize = __malloc_default_thp_pagesize (); + } + + /* Aligning load segments that are large enough to the PMD size helps + improve THP eligibility and reduces TLB pressure. + We cap the huge page size at MAX_THP_PAGESIZE to avoid over-aligning + on systems with very large normal pages (like 64K pages with 512M + huge pages). */ + if (thp_mode == malloc_thp_mode_always && thp_pagesize <= MAX_THP_PAGESIZE + && ((c->mapstart | c->mapoff) & (thp_pagesize - 1)) == 0 + && (c->mapend - c->mapstart) >= thp_pagesize + && p_align_max < thp_pagesize && (c->prot & PROT_WRITE) == 0) + return thp_pagesize; + + return p_align_max; +} diff --git a/sysdeps/unix/sysv/linux/wordsize-64/dl-map-segment-align.h b/sysdeps/unix/sysv/linux/wordsize-64/dl-map-segment-align.h new file mode 100644 index 0000000000..2893408133 --- /dev/null +++ b/sysdeps/unix/sysv/linux/wordsize-64/dl-map-segment-align.h @@ -0,0 +1,23 @@ +/* _dl_map_segment_align. Linux version. + Copyright (C) 2026 Free Software Foundation, Inc. + Copyright The GNU Toolchain Authors. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +ElfW (Addr) + _dl_map_segment_align (const struct loadcmd *c, ElfW (Addr) p_align_max); From patchwork Thu Feb 26 06:33:05 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: WANG Rui X-Patchwork-Id: 130668 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 4E4634BA23D7 for ; Thu, 26 Feb 2026 06:35:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E4634BA23D7 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 165014BA23D7 for ; Thu, 26 Feb 2026 06:34:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 165014BA23D7 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 165014BA23D7 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=1772087670; cv=none; b=d/HuUhgJG8W50RhWpL8FDYB73oiFolkHF2z9oX/Dd1W1VdTmvDFMpUMB0e2mlLDdyocJdSNHOuJTVvWBArpmc9SfEUmokzzMDAVORvhjr4yMl2GhrIGBiqxV5AfKXgbicHIoPewW7MuTaVVA5Igqij0SWE4h26vgoWiuOZIr86A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772087670; c=relaxed/simple; bh=N0RJjmPtB9Y45tHT5PNpqeamPKFHJk2rnFGuAkUFCmU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=i/hOE6rYNjqmANnS0olahLePC3lv8s5ifO0stO2zUwLbbICgd4Vnu0EkdKNjGOjcCsjStNfcexSYus8WIdzBjEAsqu1u1gGskLN6eNQT4AWcTHllUZCtlhXVC2QxtM43ofn69T82laRfQ64qyMna/EmM5Lz75fPutP+7TjeRyNU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 165014BA23D7 Received: from loongson.cn (unknown [223.64.120.216]) by gateway (Coremail) with SMTP id _____8Axz6ty6Z9pGFkVAA--.5956S3; Thu, 26 Feb 2026 14:34:26 +0800 (CST) Received: from localhost (unknown [223.64.120.216]) by front1 (Coremail) with SMTP id qMiowJAxVcBY6Z9pFhhLAA--.21582S6; Thu, 26 Feb 2026 14:34:25 +0800 (CST) From: WANG Rui To: libc-alpha@sourceware.org Cc: Adhemerval Zanella , Florian Weimer , Wilco Dijkstra , Xi Ruoyao , WANG Xuerui , caiyinyu , mengqinggang , WANG Rui Subject: [PATCH v2 4/4] loongarch: Enable THP-aligned load segments by default and define THP page size Date: Thu, 26 Feb 2026 14:33:05 +0800 Message-ID: <20260226063305.2141669-5-wangrui@loongson.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260226063305.2141669-1-wangrui@loongson.cn> References: <20260226063305.2141669-1-wangrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: qMiowJAxVcBY6Z9pFhhLAA--.21582S6 X-CM-SenderInfo: pzdqw2txl6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCw1UWr1Uury3ur4xGF17urX_yoWrurWDpr ZxuFn8GF4rWr17CrWS9a4UZF1rJFn5GF90k3sI93yUZryDJryxXFZFkas3WFy8A3yxCF4j vFn2q3WDuFs5AagCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Ib4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07 AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWU tVWrXwAv7VC2z280aVAFwI0_Cr0_Gr1UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x 0EwIxGrwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AK xVWUXVWUAwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67 AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW5JVW7JwCI 42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMI IF0xvEx4A2jsIE14v26F4j6r4UJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnI WIevJa73UjIFyTuYvjxU2na9DUUUU X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, PROLO_LEO1, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED 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 On LoongArch64 Linux, aligning ELF load segments to Transparent Huge Page (THP) boundaries provides consistent performance benefits for large binaries by reducing TLB pressure and improving instruction fetch efficiency. Enable THP-based load segment alignment by default on LoongArch64 by defining `DL_MAP_SEGMENT_ALIGN_THP_DEFAULT`. This allows the dynamic loader to apply THP-friendly alignment without requiring the `glibc.malloc.hugetlb` tunable to be explicitly set. Define the default THP page size as 32MB for LoongArch64, reflecting the architecture’s normal 16KB page size and PMD-level huge page geometry. This value is used by the THP infrastructure to determine appropriate alignment and mapping decisions. * sysdeps/unix/sysv/linux/loongarch/lp64/dl-map-segment-align.h: Enable THP-based load segment alignment by default. * sysdeps/unix/sysv/linux/loongarch/lp64/malloc-hugepages.h: Define the default THP page size. Signed-off-by: WANG Rui --- elf/tst-decorate-maps.c | 2 +- .../loongarch/lp64/dl-map-segment-align.h | 23 +++++++++++++++++++ .../linux/loongarch/lp64/malloc-hugepages.h | 21 +++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/dl-map-segment-align.h create mode 100644 sysdeps/unix/sysv/linux/loongarch/lp64/malloc-hugepages.h diff --git a/elf/tst-decorate-maps.c b/elf/tst-decorate-maps.c index fa3637af89..d3e6a5540f 100644 --- a/elf/tst-decorate-maps.c +++ b/elf/tst-decorate-maps.c @@ -109,7 +109,7 @@ do_test_threads (bool set_guard) xpthread_barrier_init (&b, NULL, num_threads + 1); /* Issue a large malloc to trigger a mmap call. */ - void *p = xmalloc (2 * 1024 * 1024); + void *p = xmalloc (32 * 1024 * 1024); pthread_t thr[num_threads]; { diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/dl-map-segment-align.h b/sysdeps/unix/sysv/linux/loongarch/lp64/dl-map-segment-align.h new file mode 100644 index 0000000000..8e95419b1c --- /dev/null +++ b/sysdeps/unix/sysv/linux/loongarch/lp64/dl-map-segment-align.h @@ -0,0 +1,23 @@ +/* _dl_map_segment_align. LoongArch64 Linux version. + Copyright (C) 2026 Free Software Foundation, Inc. + Copyright The GNU Toolchain Authors. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* Enable THP-based load segment alignment by default. */ +#define DL_MAP_SEGMENT_ALIGN_THP_DEFAULT 1 + +#include_next diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/malloc-hugepages.h b/sysdeps/unix/sysv/linux/loongarch/lp64/malloc-hugepages.h new file mode 100644 index 0000000000..8409670c7c --- /dev/null +++ b/sysdeps/unix/sysv/linux/loongarch/lp64/malloc-hugepages.h @@ -0,0 +1,21 @@ +/* Huge Page support. LoongArch64 Linux version. + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; see the file COPYING.LIB. If + not, see . */ + +#define DEFAULT_THP_PAGESIZE (32 * 1024 * 1024) + +#include_next