[RFC,0/1] make ld.so map .text LOAD ssegments and aligned by p_align

Message ID 20211204045848.71105-1-rongwei.wang@linux.alibaba.com
Headers
Series make ld.so map .text LOAD ssegments and aligned by p_align |

Message

Rongwei Wang Dec. 4, 2021, 4:58 a.m. UTC
  Hello, Glibc Maintainers and Developers:

We are software development engineers from Alibaba Cloud OS
team. We are mainly responsible for the development and
maintenance of Alibaba Cloud Linux. This is our first time
to send patch to glibc mail-list, if we ignore anything in
this patch, please let me know. Thanks very much!

Recently, we try to realize the feature that make .text and
.data application segments use huge pages (2M). At first, we
had realized the feature in kernel, refer to LINK[1]. But
the part that align the mapping address of LOAD segment was
regarded as hack way, if realized in kernel. If .text wants
to use huge pages, alignment of mapping address is necessary.
It refers to the first LOAD segment here. So, we think it
would be better to realize this part in glibc than kernel.

Actually, related discussion had been proposed in LINK[2, 3].
The implementation method in Patch 1/1 just need ld a simple
support, then application can call 'madvise' to mark .text
pages and collapse they into huge pages by 'khugepaged' thread.
(And We make a plan to provide a global sysfs inteface in OS
for .text hugepages, realizing transparent .text hugepages.
If you have an interested in this, a simple code works well
in LINK[1].)

What's more, we can see LINK[3] had mentioned .data and .text
segment using huge pages. In our patch, we just realizes the
.text part (first LOAD segment) and we think it's not necessary
for .data segments to use huge pages because of small and no
performance benefit in most applications.

This patch mainly move the part that aligns the mapping address
into ld.so. And the rest that realizes huge pages of the .text
is handed over to OS.

LINK:
[1] first patch in linux kernel:
https://patchwork.kernel.org/project/linux-mm/cover/20211009092658.59665-1-rongwei.wang@linux.alibaba.com/
[2] https://libc-alpha.sourceware.narkive.com/zqNSW0dY/glibc-loading-of-shared-objects-with-holes-wastes-address-space
[3] https://sourceware.org/pipermail/libc-alpha/2021-February/122331.html

Best regards,
Rongwei Wang

Rongwei Wang (1):
  elf: align the mapping address of LOAD segments with p_align

 elf/dl-load.c         |  1 +
 elf/dl-map-segments.h | 60 ++++++++++++++++++++++++++++++++++++++++---
 include/link.h        |  3 +++
 3 files changed, 60 insertions(+), 4 deletions(-)