From patchwork Wed Oct 19 08:23:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4655 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp212549wrs; Wed, 19 Oct 2022 02:07:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5WyL8+SRtp9kP1iJsXrPZ9kb4SHidfqKC79+KWsopo3MuKx+AXpJgY+rEZNvov/vZpYCid X-Received: by 2002:a50:c31b:0:b0:458:cc93:8000 with SMTP id a27-20020a50c31b000000b00458cc938000mr6705171edb.264.1666170467029; Wed, 19 Oct 2022 02:07:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666170467; cv=none; d=google.com; s=arc-20160816; b=fE3fjrdxl4303Il+vA281qKw/k7QEaoqdNNdHNZgVmsJyUFUAJhF3lCIc5/nV+dnP9 m0vqe0ZaT96PwZODELXLSoLAegHYg0BUddXcvXHmNTGtqGa6gXj8AgjP888IlbVHXaBU 0UTXf4WQb7mT2hr/uiye4mRw6gG0sNhElzmk8wIYb29JVdjRin0a2bHpXueKHkVsrlod FBU41kNVbZp1oz8fgNxTiLik3nPq6BcBTOVcfbLDUQwaoms88maXvVuwYlOSELxW19XG UDCoHWxIbqJS3D4VVvgWUftvUF6lf8QN1frx51rDMiVefOZMBoN6JsUojip0EL9VzcuL M7pQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020a1709066bc800b0073d61f9a7b6si10841777ejs.263.2022.10.19.02.07.16; Wed, 19 Oct 2022 02:07:47 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747106363907704038?= X-GMAIL-MSGID: =?utf-8?q?1747106363907704038?= 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,