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 6A93AC3F6B0 for ; Wed, 3 Aug 2022 13:45:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 004606B0071; Wed, 3 Aug 2022 09:45:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF5746B0072; Wed, 3 Aug 2022 09:45:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBD8D8E0001; Wed, 3 Aug 2022 09:45:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C8C1B6B0071 for ; Wed, 3 Aug 2022 09:45:39 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 963D9C0269 for ; Wed, 3 Aug 2022 13:45:39 +0000 (UTC) X-FDA: 79758403998.04.1B123C6 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf14.hostedemail.com (Postfix) with ESMTP id A4A6E10012F for ; Wed, 3 Aug 2022 13:45:37 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E43F9400BE; Wed, 3 Aug 2022 13:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1659534335; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=akp1pNQEiXkOGeo4BViAGmqcuddhmRP3JLmV9s8Jl30=; b=X2G0jJi1PM5voo71dPWDflfqa+/6EF7wfOcwNxDI+kawn2SHTL39NxngM8de4U6PkAhu/y KpbSrgZfB3DLXfNjJlX3sRKlsYB875Jzg71y6CJgp42J6mJh5wCRKEirky86UJVsb5C/3l tFQiVsEBfXBuKvknaPtIQVHQoC2kqO0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1659534335; h=from:from:reply-to:reply-to:date:date:message-id:message-id:to:to: cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=akp1pNQEiXkOGeo4BViAGmqcuddhmRP3JLmV9s8Jl30=; b=/0Ob9r/t/uNjK4UfEGtcaSYFnM351yM09euQxQwh7QlaExjLrFGlFM+suKMA7O2q8T8UQ+ wihK1T3bcovbV2Bg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A199E13A94; Wed, 3 Aug 2022 13:45:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 5ziHJv976mJ1BwAAMHmgww (envelope-from ); Wed, 03 Aug 2022 13:45:35 +0000 Date: Wed, 3 Aug 2022 15:40:33 +0200 From: David Sterba To: alexlzhu@fb.com Cc: kernel-team@fb.com, linux-mm@kvack.org, clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] btrfs: fix alginment of VMA for memory mapped files on THP Message-ID: <20220803134033.GG13489@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, alexlzhu@fb.com, kernel-team@fb.com, linux-mm@kvack.org, clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220802203246.434560-1-alexlzhu@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220802203246.434560-1-alexlzhu@fb.com> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=X2G0jJi1; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="/0Ob9r/t"; spf=pass (imf14.hostedemail.com: domain of dsterba@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=dsterba@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659534338; a=rsa-sha256; cv=none; b=VuWfUyfPJTQrr7D4xyYc9LijhRnhNGX47AN9EQTSFWvWtpBW7PTt+gtCnTwB6kDFbFzTjy 11cJF5V1UylaLqh66apMMfmIYOJLaCU8MCdh2ccuqOva3faASh+FhCtZJhDUl1zIwdqzLY 1m0Qy0/HInSvQDVMhZT14iDao5iRHZQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659534338; h=from:from:sender:reply-to: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=akp1pNQEiXkOGeo4BViAGmqcuddhmRP3JLmV9s8Jl30=; b=K1d+EFr1wo0Flpd0OgwBVncvE7Jk7y/83dweIl/KZ4eXCAdcqGu2YGigmcR9EtcFJ1MKlT iFVBpaZ3DSKVFzu8EbUGsbp90XzFvv5J0Sx2lyPUN976UojYKW3vgnHuIAPbY59HaXncAT m6wfH5ZciFMmTUrrZ61ToFjcf+ALBH4= X-Stat-Signature: ruyn7foocigcc7fcidw6ksbjg8fbj9oe X-Rspamd-Queue-Id: A4A6E10012F Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=X2G0jJi1; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="/0Ob9r/t"; spf=pass (imf14.hostedemail.com: domain of dsterba@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=dsterba@suse.cz; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1659534337-184591 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: On Tue, Aug 02, 2022 at 01:32:46PM -0700, alexlzhu@fb.com wrote: > From: Alexander Zhu > > 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 > alginment 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. > > Signed-off-by: Alexander Zhu Added to misc-next, thanks.