Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp258239lqt; Thu, 6 Jun 2024 02:42:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUJKp8QLZ2hUlWsuPWUMFwocFQkAnwLdoPHPrNgMQvDId2QMriJqZlaa4xe4F1dnek8+pBsOWsA1DMp5THdENpM9Xi88Ow3eCdUEo0ldw== X-Google-Smtp-Source: AGHT+IHN85BCKBzEb5i4YtIoYJvkKRUg2COMCPYpCXSj7onTaNr1dmSpaagM8UjLplneTxY7fi3L X-Received: by 2002:a05:622a:1a22:b0:43d:f0e4:65ef with SMTP id d75a77b69052e-4402b58b05emr53593711cf.4.1717666942545; Thu, 06 Jun 2024 02:42:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717666942; cv=pass; d=google.com; s=arc-20160816; b=WDKsFOtlDkCy/DEMxqNBhK63KbbZy5U1jjxCPO8ywBjYOCVuATlsoanmDQihvNMrTy dQPMtq/FKjwtqzCvs+jNCQlo2TvppQlhW2F0WJlHE+Y+nFkT3/qgN4ztMVLKIpSyXCoK Sw4YBGQYhykxGAUWyUhO+ItX8NCzvgPgHKTkcIO0Lj1JRZoezvSI3fbGXgVppt8j1Crd NZV7/+LeraYG9Fu8x3wb3C5ebsAxb/937aKdCGmUx7+Xa+Y3Y6XCAgkKETvgliLX7u3n 2hGv+SDkG1dp+hAXA3BDUjxCCyeDY+3+co62+kDE00/ViROUVGtMv2vN7ykVMcOy+aJT HUyw== 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=vuIaxRIhb5hZGMnBYkACkHZr40Z2UBkRk4QEvo/xDyA=; fh=FOVolK9nrAevBzru0cLEnFGOPAbULYTNG/AiM57b1TI=; b=ftdQ1Z+FqVbM5E0Y+OxU4iNiXb1Qo/5TkOsr5Z2F8KV6lNaneg5TO//0OUwdy3BmHZ bgkpcCikK6uDptZ+D2VdVEc96FMRmgHz+b1hnwcSGM8c4ToX2XB0wR/luiSR0tcA+Fz6 hnl2ZdKFheEHOGpR4XNr/9kHPFMzc/yK/k+yiaW6Yrl9DJ3ySQ/zagSamBISMPddUK1F wpelkeY93IR31CdSWdrUuJ4akMUalzFNCu7Ub808JWywm3l3qSvtvt1gNc060zjcJWUT Jzd4av4yZ9/yhGmQKfH2K87B8cLA8PMBgjN/grjQmKdYdCovip4+AQqyw20KadQFMcdM eR9g==; 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-204033-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204033-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 ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-44038a8894csi11774651cf.195.2024.06.06.02.42.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 02:42:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204033-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-204033-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204033-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 4153D1C252D4 for ; Thu, 6 Jun 2024 09:42:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DB0915278F; Thu, 6 Jun 2024 09:42:17 +0000 (UTC) Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) (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 7F1E51514EE for ; Thu, 6 Jun 2024 09:42:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=63.216.63.35 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717666936; cv=none; b=Hgtp959+KDa3BBRFp0bs5ckVh88ENI6iq1LBKWJdvX/yDBvAgIY+CYpb5rX5jJfdcRWOo7fkC0bRAVKlBr7Vnte53Rik9Anh10aHHwE9SAyQwcSgLwa3LBqif8qrQLWoh64W9Yv+8UCwGr8v6Tdta0NHLvfJ0OZ5PWUcw37ka2o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717666936; c=relaxed/simple; bh=rAgI9GGJJTeCZyVaG2TflywO4JVeIlVSaK6x8F0N7Wc=; h=Date:Message-ID:Mime-Version:From:To:Cc:Subject:Content-Type; b=TK9tic4460eWYsakIOd9DjVJ2g1pSgPXMGYpBG9XAEe5apOZ6ACizEHtjmDvP4lBrLvzWpBkyNg2UfLU8B6Z6bTNekU6mRfZLaUO/5R1CoFcK1P7tSeLQK3gmfJ9fnM0Lvpw+NWOZzIkriLd94njB7A/tAJKBUtw3XIM5g6nf6o= 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=63.216.63.35 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 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 4VvzrG4pqkz4xPBc; Thu, 6 Jun 2024 17:42:06 +0800 (CST) Received: from xaxapp03.zte.com.cn ([10.88.97.17]) by mse-fl1.zte.com.cn with SMTP id 4569g0MO058198; Thu, 6 Jun 2024 17:42:00 +0800 (+08) (envelope-from xu.xin16@zte.com.cn) Received: from mapi (xaxapp02[null]) by mapi (Zmail) with MAPI id mid32; Thu, 6 Jun 2024 17:42:03 +0800 (CST) Date: Thu, 6 Jun 2024 17:42:03 +0800 (CST) X-Zmail-TransId: 2afa6661846bffffffff819-af71f X-Mailer: Zmail v1.0 Message-ID: <20240606174203124_OW-VQZ_ZLm4lGEimA-K9@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?W1BBVENIIGxpbnV4LW5leHQgdjJdIG1tOiBodWdlX21lbW9yeTogZml4IG1pc3VzZWQgbWFwcGluZ19sYXJnZV9mb2xpb19zdXBwb3J0KCnCoGZvciBhbm9uIGZvbGlvcw==?= Content-Type: text/plain; charset="UTF-8" X-MAIL:mse-fl1.zte.com.cn 4569g0MO058198 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6661846E.000/4VvzrG4pqkz4xPBc 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. Signed-off-by: Ran Xiaokai --- include/linux/pagemap.h | 4 ++++ mm/huge_memory.c | 27 ++++++++++++++++----------- 2 files changed, 20 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..62d57270b08e 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3009,30 +3009,35 @@ 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)) { + /* Cannot split anonymous THP to order-1 */ + 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