From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40721C00144 for ; Mon, 1 Aug 2022 18:48:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F2F56B0071; Mon, 1 Aug 2022 14:48:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 27AEC6B0072; Mon, 1 Aug 2022 14:48:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11C4A8E0001; Mon, 1 Aug 2022 14:48:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id F23C66B0071 for ; Mon, 1 Aug 2022 14:48:07 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B8DE71602A7 for ; Mon, 1 Aug 2022 18:48:07 +0000 (UTC) X-FDA: 79751908614.30.27FE3CE Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf05.hostedemail.com (Postfix) with ESMTP id 369391000EF for ; Mon, 1 Aug 2022 18:48:07 +0000 (UTC) Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 271GNwtE030932 for ; Mon, 1 Aug 2022 11:48:06 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=facebook; bh=/0Ba2BW84txtNVUrI6XJ5P58G9O2nZCOBVVyrrbvLJM=; b=KjsEEFCrhCrTXrG2s0W8PGbKnOpceSsX7WI/vOk/ONLAPON5BgOg+ChsFMTxAiKuFBIH +2SuGM5RtRZV/XzxDolQ87kK5z3WJ4rV27kMh0YMSxx8V08hZziQdHJEFWyQbA/fQFDb xPsWHQG3NsKs4ysJvyPei2wzwIIBZgG2JXk= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3hn2ftwtvv-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 01 Aug 2022 11:48:06 -0700 Received: from twshared5413.23.frc3.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:21d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Mon, 1 Aug 2022 11:48:03 -0700 Received: by devvm6390.atn0.facebook.com (Postfix, from userid 352741) id D2E391AAF666; Mon, 1 Aug 2022 11:47:55 -0700 (PDT) From: To: , , , , , , CC: alexlzhu Subject: [PATCH v2] mm: fix alginment of VMA for memory mapped files on THP Date: Mon, 1 Aug 2022 11:47:40 -0700 Message-ID: <20220801184740.2134364-1-alexlzhu@fb.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-ORIG-GUID: qMshQO-fDcLd5p8ZB-cOY9WMGtBCjW_L X-Proofpoint-GUID: qMshQO-fDcLd5p8ZB-cOY9WMGtBCjW_L X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-01_08,2022-08-01_01,2022-06-22_01 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659379687; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=/0Ba2BW84txtNVUrI6XJ5P58G9O2nZCOBVVyrrbvLJM=; b=zIjQLx00W8DG83FlC1FGPoLqQRtLHnhzEacelADc40qPKWXf8KfpN9GtsyZa9cxg9w8BA7 Sq98V+80imxPIWk1IQ4CGvOIYIOSgtfMom2aj7XkUrKBAxlBymVd8bYu0xqxDUY6fd1gFW 4ndCVINwD1FA2/GE2tGVzU2ZFQp07po= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=KjsEEFCr; spf=pass (imf05.hostedemail.com: domain of "prvs=9212fa823e=alexlzhu@fb.com" designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=9212fa823e=alexlzhu@fb.com"; dmarc=pass (policy=reject) header.from=fb.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659379687; a=rsa-sha256; cv=none; b=HmbTjJnqZ/X4eBsVYATa2W3Vlu5AnL5rjwVoEvf6giPZidtHUMmGfX50UHRHFAIufizmia v0f9eh1b78JjD0Da72tLWNyKrpSsG4SIXRhHToKhz/Us0szpXrtp1v++yCBq7h6TkXs+rF +xanLzVB03VNaFIQxI6zD6vQWqkiU6A= X-Rspam-User: X-Stat-Signature: qnopnfpcsuoc1wud68oxh965iy5b3bf8 X-Rspamd-Queue-Id: 369391000EF Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=KjsEEFCr; spf=pass (imf05.hostedemail.com: domain of "prvs=9212fa823e=alexlzhu@fb.com" designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=9212fa823e=alexlzhu@fb.com"; dmarc=pass (policy=reject) header.from=fb.com X-Rspamd-Server: rspam08 X-HE-Tag: 1659379687-898661 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: From: alexlzhu With CONFIG_READ_ONLY_THP_FOR_FS, the Linux kernel supports using THPs fo= r read-only mmapped files, such as shared libraries. However, the kernel makes no attempt to actually align those mappings on 2MB boundarie= s, which makes it impossible to use those THPs most of the time. This issue applies to general file mapping THP as well as existing setups using CONFIG_READ_ONLY_THP_FOR_FS. This is easily fixed by using thp_get_unmapped_area for the unmapped_area function in btrfs, which is what ext2, ext4, fuse, and xfs all use. The problem can be seen in /proc/PID/smaps where THPeligible is set to 0 on mappings to eligible shared object files as shown below. Before this patch: 7fc6a7e18000-7fc6a80cc000 r-xp 00000000 00:1e 199856 /usr/lib64/libcrypto.so.1.1.1k Size: 2768 kB THPeligible: 0 VmFlags: rd ex mr mw me With this patch the library is mapped at a 2MB aligned address: fbdfe200000-7fbdfe4b4000 r-xp 00000000 00:1e 199856 /usr/lib64/libcrypto.so.1.1.1k Size: 2768 kB THPeligible: 1 VmFlags: rd ex mr mw me This fixes the alignment of VMAs for any mmap of a file that has the rd and ex permissions and size >=3D 2MB. The VMA alignment and THPeligible field for anonymous memory is handled separately and is thus not effected by this change. Signed-off-by: alexlzhu --- fs/btrfs/file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 9dfde1af8a64..2423040db167 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -3808,6 +3808,7 @@ const struct file_operations btrfs_file_operations = =3D { .mmap =3D btrfs_file_mmap, .open =3D btrfs_file_open, .release =3D btrfs_release_file, + .get_unmapped_area =3D thp_get_unmapped_area, .fsync =3D btrfs_sync_file, .fallocate =3D btrfs_fallocate, .unlocked_ioctl =3D btrfs_ioctl, --=20 2.30.2