From patchwork Sat Oct 9 09:26:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rongwei Wang X-Patchwork-Id: 12547387 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1017C433FE for ; Sat, 9 Oct 2021 09:27:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6572960EE4 for ; Sat, 9 Oct 2021 09:27:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6572960EE4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id F3C02900002; Sat, 9 Oct 2021 05:27:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EC4936B0073; Sat, 9 Oct 2021 05:27:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D655F900002; Sat, 9 Oct 2021 05:27:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0009.hostedemail.com [216.40.44.9]) by kanga.kvack.org (Postfix) with ESMTP id BF7CC6B0072 for ; Sat, 9 Oct 2021 05:27:07 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 71D89182B69D4 for ; Sat, 9 Oct 2021 09:27:07 +0000 (UTC) X-FDA: 78676370094.34.0BE3E2C Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by imf21.hostedemail.com (Postfix) with ESMTP id AC7E7D03D945 for ; Sat, 9 Oct 2021 09:27:06 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=rongwei.wang@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0Ur5qOcb_1633771618; Received: from localhost.localdomain(mailfrom:rongwei.wang@linux.alibaba.com fp:SMTPD_---0Ur5qOcb_1633771618) by smtp.aliyun-inc.com(127.0.0.1); Sat, 09 Oct 2021 17:27:01 +0800 From: Rongwei Wang To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: akpm@linux-foundation.org, willy@infradead.org, viro@zeniv.linux.org.uk, song@kernel.org, william.kucharski@oracle.com, hughd@google.com, shy828301@gmail.com, linmiaohe@huawei.com, peterx@redhat.com Subject: [PATCH 2/3] mm, thp: make mapping address of libraries THP align Date: Sat, 9 Oct 2021 17:26:57 +0800 Message-Id: <20211009092658.59665-3-rongwei.wang@linux.alibaba.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211009092658.59665-1-rongwei.wang@linux.alibaba.com> References: <20211009092658.59665-1-rongwei.wang@linux.alibaba.com> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: AC7E7D03D945 X-Stat-Signature: ys3sdppt6eiwdyrhtyfqsh99izakonw7 Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf21.hostedemail.com: domain of rongwei.wang@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=rongwei.wang@linux.alibaba.com X-HE-Tag: 1633771626-528367 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: For shared libraries, ld.so seems not to consider p_align well, as shown below. $ readelf -l /usr/lib64/libc-2.17.so LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x00000000001c2fe8 0x00000000001c2fe8 R E 200000 $ cat /proc/1/smaps 7fecc4072000-7fecc4235000 r-xp 00000000 08:03 655802 /usr/lib64/libc-2.17.so This makes the mapping address allocated by 'get_unmapped_area' align with 2M for libraries, to facilitate file THP for .text section as far as possible. Signed-off-by: Gang Deng Signed-off-by: Xu Yu Signed-off-by: Rongwei Wang --- include/linux/huge_mm.h | 12 ++++++++++++ mm/huge_memory.c | 15 +++++++++++++++ mm/mmap.c | 18 ++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 95b718031ef3..ddbc0d19f90f 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -147,8 +147,20 @@ static inline bool transhuge_vma_enabled(struct vm_area_struct *vma, #define hugetext_enabled() \ (transparent_hugepage_flags & \ (1<mm->get_unmapped_area(filp, addr, len, pgoff, flags); +} +#endif /* CONFIG_HUGETEXT */ + static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf, struct page *page, gfp_t gfp) { diff --git a/mm/mmap.c b/mm/mmap.c index 88dcc5c25225..cad94a13edc2 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2242,8 +2242,26 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, get_area = current->mm->get_unmapped_area; if (file) { +#ifdef CONFIG_HUGETEXT + /* + * Prior to the file->f_op->get_unmapped_area. + * + * If hugetext is enabled, except for MAP_FIXED, it always + * make the mapping address of files that have executable + * attribute be mapped in 2MB alignment. + */ + struct inode *inode = file_inode(file); + + if (hugetext_enabled() && (inode->i_mode & 0111) && + (!file->f_op->get_unmapped_area || + file->f_op->get_unmapped_area == thp_get_unmapped_area)) + get_area = hugetext_get_unmapped_area; + else if (file->f_op->get_unmapped_area) + get_area = file->f_op->get_unmapped_area; +#else if (file->f_op->get_unmapped_area) get_area = file->f_op->get_unmapped_area; +#endif } else if (flags & MAP_SHARED) { /* * mmap_region() will call shmem_zero_setup() to create a file,