Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp923064lqt; Fri, 7 Jun 2024 02:48:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXoxFh2U1u5Cnu2uxvFDA24T2Xbmd+wwn6UMHXOsaBD2FrjxGU6s5fKDfXWrPjVAwXqH6u4g3pKCLsE6u5bgew3QPNAxmdd02/bqCeLJA== X-Google-Smtp-Source: AGHT+IFB7X0FXizsKn6z1ip6eG4AwpBgbWWMeapjP0nRTnnFGJvEsJT1ATMLb5drxebwJM2Qtwes X-Received: by 2002:a2e:8e8b:0:b0:2ea:ebc6:d9c with SMTP id 38308e7fff4ca-2eaebc60ecemr1191851fa.18.1717753723054; Fri, 07 Jun 2024 02:48:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717753723; cv=pass; d=google.com; s=arc-20160816; b=ESOA3ZKxcTwnGX2gr6+EUj7J2+f6leJYRZlwzwIcVGA8vI/UZyti6rcPhVGXjMzrtZ dFjHTBqoBV9NVtZ8ElUrSHDc9P7jfCRO/Kn/DFjq/7b2UniIRO0qfbmCqYDOV/kAxZjU 2IaAcZz5Z9Fc9NRWWSzPZh2ex5R5zLYFh9yzB2ghbiSCYhcpAtAnQj6IPV3DmWp4EQTF pilhJajMudt9Y8xFt+tYmkXzC9Xcb1uFgQxgkXNS7sUFfdDfsujVbN3YSpx89/VLL5IS KfpuRq2WLYBuU/fkwZywrX/w4LHGgFfBANkB4uCHD0O0HvhHF64cLTphUt084grlLGI9 8ZYA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:cc:to:from:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:date; bh=7JzbTqE/LVmrMaTm3BN5+MORuOZjuvRPiKJY5Uz5n1o=; fh=FOVolK9nrAevBzru0cLEnFGOPAbULYTNG/AiM57b1TI=; b=Gg4IV9PBumxoMUEOm1SmQKsAHP2qYksnYQr9eaDfo3ruEDAnl2+PEqr1C/0bD3cksF zIZjvMp9Kqkk6tG3SdTFlLcjA6/HrXCor3zZW7NCINhyXCRtKsO+9O7v+BGuT04ckYYy bPuCZbEf0nXR3CBq5pcEFMnbHvJhOqXftcF1nHN8iRjJdAZdkse7ACIKIK+JXZx6SP0R 7G7hr/zljvB8BGcU6p1onqYMly3eJsbD0iud9t2YqNacDepq/LQwHierRbbWptqAq0+7 ExtmOdKgtNU3AyLGB+evHdC5YwecJCee2JR0vk0r7klCpwU9nY3ikbk2BGRlFbUazNI/ BSKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=zte.com.cn dmarc=pass fromdomain=zte.com.cn); spf=pass (google.com: domain of linux-kernel+bounces-205748-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205748-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57aae264b6fsi1726530a12.559.2024.06.07.02.48.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 02:48:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205748-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zte.com.cn dmarc=pass fromdomain=zte.com.cn); spf=pass (google.com: domain of linux-kernel+bounces-205748-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205748-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CB2281F25BAC for ; Fri, 7 Jun 2024 09:41:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 55A6915B552; Fri, 7 Jun 2024 09:41:10 +0000 (UTC) Received: from mxde.zte.com.cn (mxde.zte.com.cn [209.9.37.143]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A44FB15CD5C for ; Fri, 7 Jun 2024 09:41:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.9.37.143 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717753269; cv=none; b=qIk7Wsa+JeduYPm6Fj8BuCbTJ1gByxAKTO/6/p3kLFBhAY+qhs4gSNVwtDyktfUpAX2UpDrjRDsr0NRh1WmihReT3aDWzsnm4144IIoJhAi2iCwngjGSqas3S8NXeOEEF0ZBgEA6/+F6EFLP9CzRtIZeh147I7OXkkQHXcw5ArM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717753269; c=relaxed/simple; bh=x9fp+gWVJGtIzJ6GcT0SwqoJs5luw78VAYq6ovnD3x4=; h=Date:Message-ID:Mime-Version:From:To:Cc:Subject:Content-Type; b=u8BMOiDrRaTZUMDYYCiYiffp2CCEkdppnq6iA7guQlu53ijTCwTpfFwsf7Y4n8Yf56W/pS03FSkkpuERy3dwRutbWXJ9ZHlrWA+l97m0gWOWl2o1wuYvXDyhrGlwzDwoj0RyqxuHcHpt6bCnklLpUg0zK7nwRur63RaeqYyCkng= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn; spf=pass smtp.mailfrom=zte.com.cn; arc=none smtp.client-ip=209.9.37.143 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mxhk.zte.com.cn (unknown [192.168.250.137]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mxde.zte.com.cn (FangMail) with ESMTPS id 4VwbmW6Wx7z5TCGC for ; Fri, 7 Jun 2024 17:40:59 +0800 (CST) Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4VwbmJ0Sy0z8XrS1; Fri, 7 Jun 2024 17:40:48 +0800 (CST) Received: from xaxapp01.zte.com.cn ([10.88.99.176]) by mse-fl1.zte.com.cn with SMTP id 4579ejtn002111; Fri, 7 Jun 2024 17:40:45 +0800 (+08) (envelope-from xu.xin16@zte.com.cn) Received: from mapi (xaxapp02[null]) by mapi (Zmail) with MAPI id mid32; Fri, 7 Jun 2024 17:40:48 +0800 (CST) Date: Fri, 7 Jun 2024 17:40:48 +0800 (CST) X-Zmail-TransId: 2afa6662d5a0ffffffffa1b-000d9 X-Mailer: Zmail v1.0 Message-ID: <202406071740485174hcFl7jRxncsHDtI-Pz-o@zte.com.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: , , , Cc: , , , , , Subject: =?UTF-8?B?W1BBVENIIGxpbnV4LW5leHQgdjNdIG1tOiBodWdlX21lbW9yeTogZml4IG1pc3VzZWQgbWFwcGluZ19sYXJnZV9mb2xpb19zdXBwb3J0KCnCoCBmb3IgYW5vbiBmb2xpb3M=?= Content-Type: text/plain; charset="UTF-8" X-MAIL:mse-fl1.zte.com.cn 4579ejtn002111 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6662D5AA.000/4VwbmW6Wx7z5TCGC From: Ran Xiaokai When I did a large folios split test, a WARNING "[ 5059.122759][ T166] Cannot split file folio to non-0 order" was triggered. But the test cases are only for anonmous folios. while mapping_large_folio_support() is only reasonable for page cache folios. In split_huge_page_to_list_to_order(), the folio passed to mapping_large_folio_support() maybe anonmous folio. The folio_test_anon() check is missing. So the split of the anonmous THP is failed. This is also the same for shmem_mapping(). We'd better add a check for both. But the shmem_mapping() in __split_huge_page() is not involved, as for anonmous folios, the end parameter is set to -1, so (head[i].index >= end) is always false. shmem_mapping() is not called. Also add a VM_WARN_ON_ONCE() in mapping_large_folio_support() for anon mapping, So we can detect the wrong use more easily. THP folios maybe exist in the pagecache even the file system doesn't support large folio, it is because when CONFIG_TRANSPARENT_HUGEPAGE is enabled, khugepaged will try to collapse read-only file-backed pages to THP. But the mapping does not actually support multi order large folios properly. Using /sys/kernel/debug/split_huge_pages to verify this, with this patch, large anon THP is successfully split and the warning is ceased. Changes since v2: - fix two coding style problems suggested by David - update the comments of the order-1 case suggested by Barry Reviewed-by: Barry Song Reviewed-by: Zi Yan Acked-by: David Hildenbrand Signed-off-by: Ran Xiaokai --- include/linux/pagemap.h | 4 ++++ mm/huge_memory.c | 28 +++++++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index ee633712bba0..59f1df0cde5a 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -381,6 +381,10 @@ static inline void mapping_set_large_folios(struct address_space *mapping) */ static inline bool mapping_large_folio_support(struct address_space *mapping) { + /* AS_LARGE_FOLIO_SUPPORT is only reasonable for pagecache folios */ + VM_WARN_ONCE((unsigned long)mapping & PAGE_MAPPING_ANON, + "Anonymous mapping always supports large folio"); + return IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && test_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 317de2afd371..155d6a9f73be 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3009,30 +3009,36 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, if (new_order >= folio_order(folio)) return -EINVAL; - /* Cannot split anonymous THP to order-1 */ - if (new_order == 1 && folio_test_anon(folio)) { - VM_WARN_ONCE(1, "Cannot split to order-1 folio"); - return -EINVAL; - } - - if (new_order) { - /* Only swapping a whole PMD-mapped folio is supported */ - if (folio_test_swapcache(folio)) + if (folio_test_anon(folio)) { + /* order-1 is not supported for anonymous THP. */ + if (new_order == 1) { + VM_WARN_ONCE(1, "Cannot split to order-1 folio"); return -EINVAL; + } + } else if (new_order) { /* Split shmem folio to non-zero order not supported */ if (shmem_mapping(folio->mapping)) { VM_WARN_ONCE(1, "Cannot split shmem folio to non-0 order"); return -EINVAL; } - /* No split if the file system does not support large folio */ - if (!mapping_large_folio_support(folio->mapping)) { + /* + * No split if the file system does not support large folio. + * Note that we might still have THPs in such mappings due to + * CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping + * does not actually support large folios properly. + */ + if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && + !mapping_large_folio_support(folio->mapping)) { VM_WARN_ONCE(1, "Cannot split file folio to non-0 order"); return -EINVAL; } } + /* Only swapping a whole PMD-mapped folio is supported */ + if (folio_test_swapcache(folio) && new_order) + return -EINVAL; is_hzp = is_huge_zero_folio(folio); if (is_hzp) { -- 2.15.2