Received: by 2002:a05:622a:251a:b0:39a:b4a2:e86 with SMTP id cm26csp328760qtb; Wed, 19 Oct 2022 03:06:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM57DVGg2eCbBIetKdWrVGL+6SgPmiImdyldK0pKxsR4dAd2B4PtmwlqwmAg8DPIqpJoNoPS X-Received: by 2002:a17:90b:4f89:b0:20d:8411:ca9 with SMTP id qe9-20020a17090b4f8900b0020d84110ca9mr45243550pjb.110.1666174008259; Wed, 19 Oct 2022 03:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666174008; cv=none; d=google.com; s=arc-20160816; b=eErVeed86R9skCZADMF6DYtyoXjyI5kUft+u54OgNWKnxfzvk8oqo+IvHpB7zbnxjk m7HblmrwhcdyxMRFVgrCWe20PLFwP5W3+CwrPg7S7PY8IgxWz+DTVbCCpgALFvfR1A0j m2XUdPLH0F18MA2W1h1XDdiYl3FOTkYPMF2m3S4Z2q2/GeAQs6AvHLo4xrgvwEObUIVg rZWyH6C4rOsctfiBjIddGzHKsbS8yh53Osttgeq0gDMIC1bpJhmKC9SHxaCJG3fOsuXy zRhX6S93kRizbDvb94RH4Q/ipGW4bnsMqRPJHtroiBarmuEOwoX8xBPCBET+N+JwHo7w 2a/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=frgwFpIDgEaM5X2uYKASDtybz70RHmWF37vOfPa3M+I=; b=jZOj19Sgo+HV8Ndv0YRp5qzusLbd6GvHLBvVCJBPAoU2xcI/PNiREIeNHVUj7PTk0R tD1AAniq3STw8W+AWsuqvw/Qi4o1Jcmtze4+0aGA/HChAtME2wW3evurtwGqR6BQGurx Jfe6YJnfRtvoUK6sapBBLLZHj5ktlPTA75G7iwg0q8oA8rnURqMh8y6ZEbokMzkPxN3P M25DIpICK/XIBxoJaNyS8ynLnETNVmoJ8Gxd+NQT0VKKaHfkyvsiEwoZXEKpgQzJiWc1 5GpkOltUWNZxxMoYbOR/9dUOmqOvSFpHKbA4yZkT1xyFNTVZt1e8o2nLBWcsLqx9xoXO 7Beg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1TJghh2V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e7-20020a635447000000b0041a4bf40469si18914299pgm.271.2022.10.19.03.06.28; Wed, 19 Oct 2022 03:06:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1TJghh2V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229905AbiJSJAo (ORCPT + 99 others); Wed, 19 Oct 2022 05:00:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232026AbiJSI6v (ORCPT ); Wed, 19 Oct 2022 04:58:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C610A02DD; Wed, 19 Oct 2022 01:54:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A8C0E6181A; Wed, 19 Oct 2022 08:44:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B573CC433C1; Wed, 19 Oct 2022 08:44:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169094; bh=qWfX17P49L5XKqrAgUu3S2Ea5UyneqMUz4iGsJL8gUM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1TJghh2Vx5WeyLduLM76UPNNn4zEZlNTdFJrV3JnPdY/K4etx2oo+HxNHB4q9dW31 SrLojg5gsfqKDBkjVFPqZ2ynRGl5WeDDxfo2UYBYyGLLBUN5Dr3i3/HviQMkUuha4w MxTD5ndi62YNEbOOg7KuBTnvaYJrknUBEBlx6fPI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Zhu , David Sterba Subject: [PATCH 6.0 118/862] btrfs: fix alignment of VMA for memory mapped files on THP Date: Wed, 19 Oct 2022 10:23:25 +0200 Message-Id: <20221019083255.156973302@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Zhu commit b0c582233a8563f3c4228df838cdc67a8807ec78 upstream. With CONFIG_READ_ONLY_THP_FOR_FS, the Linux kernel supports using THPs for read-only mmapped files, such as shared libraries. However, the kernel makes no attempt to actually align those mappings on 2MB boundaries, 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. Initially btrfs had been left out in commit 8c07fc452ac0 ("btrfs: fix alignment of VMA for memory mapped files on THP") as btrfs does not support DAX. However, commit 1854bc6e2420 ("mm/readahead: Align file mappings for non-DAX") removed the DAX requirement. We should now be able to call thp_get_unmapped_area() for btrfs. 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 >= 2MB. The VMA alignment and THPeligible field for anonymous memory is handled separately and is thus not effected by this change. CC: stable@vger.kernel.org # 5.18+ Signed-off-by: Alexander Zhu Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/file.c | 1 + 1 file changed, 1 insertion(+) --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -3810,6 +3810,7 @@ const struct file_operations btrfs_file_ .mmap = btrfs_file_mmap, .open = btrfs_file_open, .release = btrfs_release_file, + .get_unmapped_area = thp_get_unmapped_area, .fsync = btrfs_sync_file, .fallocate = btrfs_fallocate, .unlocked_ioctl = btrfs_ioctl,