From patchwork Tue Jun 25 09:06:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 13710787 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 073F3C2BBCA for ; Tue, 25 Jun 2024 09:07:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 930F86B02F6; Tue, 25 Jun 2024 05:07:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E0A66B02F9; Tue, 25 Jun 2024 05:07:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 781626B02FA; Tue, 25 Jun 2024 05:07:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 59FBF6B02F6 for ; Tue, 25 Jun 2024 05:07:36 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 14B4BC0D4D for ; Tue, 25 Jun 2024 09:07:36 +0000 (UTC) X-FDA: 82268832912.02.3CB3EA0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 3D005180011 for ; Tue, 25 Jun 2024 09:07:34 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gJm6pQ3z; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of gshan@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=gshan@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719306442; a=rsa-sha256; cv=none; b=RZPUqYJgEEtgP4eel84/yzqv49945HnBOu1LX6IlEW0vyys+rdo57J1gTOl9vwA7UJ/yCc oEb/uDGwWz65QoaZTujJdlKrEz6Z+sDXYgfk/G0sbq+LyCD5fVIDSfR1uL/ULoWNKtdB1G yBAXDvuzLfa/jc6RF2pIYR+A/6R6Nzg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gJm6pQ3z; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of gshan@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=gshan@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719306442; 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:in-reply-to:references:references:dkim-signature; bh=mpTFKwtZMDnLyGvHe5Gpx78ZwRB1TPy/HybiDm8shcc=; b=oAcFMDFtXw7OuwgDl3p9BMyeq/6dMOnaiWn9oCIObWdgztOG6el4KHYgYJXtqE5fSPlhSo aJi4zgQ/EHxl3xGQXrS66nN3znIw/ym2B8pGOidcpiL13JzzvVFLOyjScHdVEGEI5waqy0 4a/gYoTu14fzrjYnZ8tPo9NlBKfeQf0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719306453; h=from:from: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:in-reply-to:references:references; bh=mpTFKwtZMDnLyGvHe5Gpx78ZwRB1TPy/HybiDm8shcc=; b=gJm6pQ3zNyP0PYIhgWTr/Fs9IXdkfPO4ezj4FxXsIu7IEPEgwoLFC2XgKLFApI3NSJZLjr CueDFgY5GJTC53uCmdS6mi/jru7MeuE2Na+o2Z16B5jow+PgUtzhIslQJ+dd8x1jlmJJu0 isPrpq6CR2bZikEN5hrhtuLNnK7Z0vQ= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-683-Juu5SSqfP5-ZJJFPS-5imA-1; Tue, 25 Jun 2024 05:07:27 -0400 X-MC-Unique: Juu5SSqfP5-ZJJFPS-5imA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 719781955E80; Tue, 25 Jun 2024 09:07:25 +0000 (UTC) Received: from gshan-thinkpadx1nanogen2.remote.csb (unknown [10.67.24.180]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1EBA11954AC0; Tue, 25 Jun 2024 09:07:18 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, david@redhat.com, djwong@kernel.org, willy@infradead.org, akpm@linux-foundation.org, hughd@google.com, torvalds@linux-foundation.org, zhenyzha@redhat.com, shan.gavin@gmail.com Subject: [PATCH 2/4] mm/filemap: Skip to allocate PMD-sized folios if needed Date: Tue, 25 Jun 2024 19:06:44 +1000 Message-ID: <20240625090646.1194644-3-gshan@redhat.com> In-Reply-To: <20240625090646.1194644-1-gshan@redhat.com> References: <20240625090646.1194644-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 3D005180011 X-Stat-Signature: 1wut73apatksyqcaxzz9jxoycwinr354 X-Rspam-User: X-HE-Tag: 1719306454-590276 X-HE-Meta: U2FsdGVkX19UWYz3cxR2wvKgMnHMAp6knbckPzJ6WH1SeL4InSJWNELrNJv26VU9S3S8SDQIMJ2LPxeSj3Kpc1QNtU9HIztVVZJyKtWuQDeht0RLmkIjhA0FFrMgkKunGpHr0AD6duiLr4r1Koka/NquRJhLglkk62BfdDKuPMdOhDdfGBHV5R/WCD9McZ+urqhP8DRN+s/w/bjT2bERtYK5wLAo6VwQn/kapv9CS2cz0NlABi4QWDKpIHH/CkSLa40MyIIRvC9FcQBiR1d78BTpSW85hbUgtbFAJ4VfdeaaQaQc2b/L39CFNzwLTAFo5PjZnZuOFoo/7W4QoJsZHJX+AcVfCx8bWdNw5hOCUPBar9iReYetU/zbERnLqukhYPIYO8vErI1LKzu7lIeVk8K5Q10ZiMQdQAFtjAuSWwSQhxrorO6DrPpWfvdv/o6MMCv1rexH3r+04YV/uTAuI01beECdz7PntZSOnmFSu+D5+fzWCyp1ilduw+AlQFsmhIUr38BtY0jv1cVWvvrlDG8VsUkLnbzdDjfRHkEAd1AWjViJqUsh6Gjvk+QinGuXuTuzv9tqlF4a3RKyeUprpZ97D5sMLprGmu8NxlYRAI8z52Ma1aFbPDPNN7Mm1SnosTlZI/aGrf+0mcRbNfMQllpQcR9mE/Gpd8H9DTzw5cWqSjgLCOoHNRq/igXBLM+i8Cv1Lc4G5KWGroL6ciECQwyixuCdfXa7MDy8Iz0MYy8x8z6LcxvHUgVJTVyyWnIRxfLOyi55WDrnJqT1g1C/RQ955y9XmKgX4QJxBG2zc8oePjF68f12L2meHhjdTMI0yffJwbzPdygpycZcvM8alkB+Ca0XaXugqEeQTfj7gjHmC78hH7r5ESg+5KlOTXYWGFNdBDn22gPMG5JcuKov8W+HLMIbo1NpKaEIak+upvnrm9TF28XmL6qP+gQOBebh/eMMyycMA9bF51a7T2+ aPeJjzYQ kFiu2isKFW9qIH2rBeMr9eYYJq/ztDf997p+BXvfVSM16TAPd1xxnvhlB6qGA+MB0LhvY9EXgYahe/YQHnPj03pNK2we/iIh6v6pQ8EFcBhQKi15aE9LgUE8CkSsxgof7BHZLtlYmLWglz+xiFhfgLDTTw5PVVx4vDuRDXCYTzwklwJaZvUFVhUobKT4B7zN0YIWwXakgOepQJuuh5NeGN9C+XKaWf047oFR3KzZS6JEJ/cmCoLu1jfEKxUq+ki4T8QhlCBAV0ivlU1tAKNL9Kx+mC5HIwZ/6FnqvVCQFka9K2JHr/IszxqNh4PhD4sN0Al7B3cc1MMTWH7fWrEkLKC7sBuAI0U/3PoRc2i9FffkU92VpP53LDVxUWDt5Sl/qAeVWoTzTp5G91dY0PNgizpiRrLmuiXvUWWgBR8n1Ff2430rLSQcrNkp3+Q== 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: List-Subscribe: List-Unsubscribe: On ARM64, HPAGE_PMD_ORDER is 13 when the base page size is 64KB. The PMD-sized page cache can't be supported by xarray as the following error messages indicate. ------------[ cut here ]------------ WARNING: CPU: 35 PID: 7484 at lib/xarray.c:1025 xas_split_alloc+0xf8/0x128 Modules linked in: nft_fib_inet nft_fib_ipv4 nft_fib_ipv6 nft_fib \ nft_reject_inet nf_reject_ipv4 nf_reject_ipv6 nft_reject nft_ct \ nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 \ ip_set rfkill nf_tables nfnetlink vfat fat virtio_balloon drm \ fuse xfs libcrc32c crct10dif_ce ghash_ce sha2_ce sha256_arm64 \ sha1_ce virtio_net net_failover virtio_console virtio_blk failover \ dimlib virtio_mmio CPU: 35 PID: 7484 Comm: test Kdump: loaded Tainted: G W 6.10.0-rc5-gavin+ #9 Hardware name: QEMU KVM Virtual Machine, BIOS edk2-20240524-1.el9 05/24/2024 pstate: 83400005 (Nzcv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--) pc : xas_split_alloc+0xf8/0x128 lr : split_huge_page_to_list_to_order+0x1c4/0x720 sp : ffff800087a4f6c0 x29: ffff800087a4f6c0 x28: ffff800087a4f720 x27: 000000001fffffff x26: 0000000000000c40 x25: 000000000000000d x24: ffff00010625b858 x23: ffff800087a4f720 x22: ffffffdfc0780000 x21: 0000000000000000 x20: 0000000000000000 x19: ffffffdfc0780000 x18: 000000001ff40000 x17: 00000000ffffffff x16: 0000018000000000 x15: 51ec004000000000 x14: 0000e00000000000 x13: 0000000000002000 x12: 0000000000000020 x11: 51ec000000000000 x10: 51ece1c0ffff8000 x9 : ffffbeb961a44d28 x8 : 0000000000000003 x7 : ffffffdfc0456420 x6 : ffff0000e1aa6eb8 x5 : 20bf08b4fe778fca x4 : ffffffdfc0456420 x3 : 0000000000000c40 x2 : 000000000000000d x1 : 000000000000000c x0 : 0000000000000000 Call trace: xas_split_alloc+0xf8/0x128 split_huge_page_to_list_to_order+0x1c4/0x720 truncate_inode_partial_folio+0xdc/0x160 truncate_inode_pages_range+0x1b4/0x4a8 truncate_pagecache_range+0x84/0xa0 xfs_flush_unmap_range+0x70/0x90 [xfs] xfs_file_fallocate+0xfc/0x4d8 [xfs] vfs_fallocate+0x124/0x2e8 ksys_fallocate+0x4c/0xa0 __arm64_sys_fallocate+0x24/0x38 invoke_syscall.constprop.0+0x7c/0xd8 do_el0_svc+0xb4/0xd0 el0_svc+0x44/0x1d8 el0t_64_sync_handler+0x134/0x150 el0t_64_sync+0x17c/0x180 Fix it by skipping to allocate PMD-sized page cache when its size is larger than MAX_PAGECACHE_ORDER. For this specific case, we will fall to regular path where the readahead window is determined by BDI's sysfs file (read_ahead_kb). Fixes: 4687fdbb805a ("mm/filemap: Support VM_HUGEPAGE for file mappings") Cc: stable@kernel.org # v5.18+ Suggested-by: David Hildenbrand Signed-off-by: Gavin Shan Acked-by: David Hildenbrand --- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index 876cc64aadd7..b306861d9d36 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3124,7 +3124,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) #ifdef CONFIG_TRANSPARENT_HUGEPAGE /* Use the readahead code, even if readahead is disabled */ - if (vm_flags & VM_HUGEPAGE) { + if ((vm_flags & VM_HUGEPAGE) && HPAGE_PMD_ORDER <= MAX_PAGECACHE_ORDER) { fpin = maybe_unlock_mmap_for_io(vmf, fpin); ractl._index &= ~((unsigned long)HPAGE_PMD_NR - 1); ra->size = HPAGE_PMD_NR;