From patchwork Mon Dec 16 16:51:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dev Jain X-Patchwork-Id: 13910086 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 28655E77180 for ; Mon, 16 Dec 2024 16:53:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ADB946B00C9; Mon, 16 Dec 2024 11:53:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A8AE56B00C8; Mon, 16 Dec 2024 11:53:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 957A96B00C9; Mon, 16 Dec 2024 11:53:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 71E2B6B00B4 for ; Mon, 16 Dec 2024 11:53:52 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1B3AC140E73 for ; Mon, 16 Dec 2024 16:53:52 +0000 (UTC) X-FDA: 82901418180.10.38416E4 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf01.hostedemail.com (Postfix) with ESMTP id 185D740011 for ; Mon, 16 Dec 2024 16:53:27 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf01.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734367998; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xhFPveaZorJV7RkvdDwNQ8gdAUT2oKTD6wdqzlLHLWs=; b=lANLQmQZGGytKoOlg6PIQ2ysahJ2J+2+pFVprl8Rl3Xneo++iA7In105oG/Xdu5YFvKgok LbcuEqO8iKjRZRkLvPYHU+UtZZEupwMgKviOHkz1HNmAScBcg8VCVidFjpoYCwwy7Kz+fr lAVhZkfDd1POpKgCB8/KmiENSY0N7do= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734367998; a=rsa-sha256; cv=none; b=GL6Zj6owUglzfgyGViN7AkpRfqUKnl/k1TwppqLWg+D7Mj1UYz1+icIt8AjejxuAFaO6qT ox+tpYZrgLw0qnzXwhZIELQU4cBhDUpIrJD6LjahvYgsMVIOg++2UThhkAHhME0E5o2szD pkJSMH0PBkUbN3cGaK93EYNOR14maA0= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf01.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0479416F8; Mon, 16 Dec 2024 08:54:18 -0800 (PST) Received: from K4MQJ0H1H2.arm.com (unknown [10.163.78.212]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1A31E3F528; Mon, 16 Dec 2024 08:53:38 -0800 (PST) From: Dev Jain To: akpm@linux-foundation.org, david@redhat.com, willy@infradead.org, kirill.shutemov@linux.intel.com Cc: ryan.roberts@arm.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, cl@gentwo.org, vbabka@suse.cz, mhocko@suse.com, apopple@nvidia.com, dave.hansen@linux.intel.com, will@kernel.org, baohua@kernel.org, jack@suse.cz, srivatsa@csail.mit.edu, haowenchao22@gmail.com, hughd@google.com, aneesh.kumar@kernel.org, yang@os.amperecomputing.com, peterx@redhat.com, ioworker0@gmail.com, wangkefeng.wang@huawei.com, ziy@nvidia.com, jglisse@google.com, surenb@google.com, vishal.moola@gmail.com, zokeefe@google.com, zhengqi.arch@bytedance.com, jhubbard@nvidia.com, 21cnbao@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dev Jain Subject: [RFC PATCH 12/12] selftests/mm: khugepaged: Enlighten for mTHP collapse Date: Mon, 16 Dec 2024 22:21:05 +0530 Message-Id: <20241216165105.56185-13-dev.jain@arm.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20241216165105.56185-1-dev.jain@arm.com> References: <20241216165105.56185-1-dev.jain@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 185D740011 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: a4jnbh1b6amttaexa7x6j9oxqns8s8eb X-HE-Tag: 1734368007-108322 X-HE-Meta: U2FsdGVkX1+tnbsV56W7hwh+8M9skcnjljqVVcJ4XOVun9vDaVSZmc+gS2BXeS1iK3a4qE2EZ+OcxzHvvaHgIAIxUk8igmdyB84oIByNM5cCFDhAQRI+4enAFMh6OpsteaBfPfWDn084zP4Ee8pPH8YkHbwa+oMv5yVQAuqprbRv8wKik7yoEDVCGNVouUfy/NmRI6mQvEcC4Ms0scOCYc+FdgZvGYBTaaffW/5Siuh3JJ/FpVGYvAKDl75Q4YYbrNcqgoNfRYSc3KkNKlWYaAF3Bgo2umW88sKVNW1VxIbkyrKKtm7V0f3To04GkiOPqLQrequOnWh59IqSetxzsN0pkdmWb4wsfsMkx3XZOPqlnPPPUHjgY4aABDO47483GkLrDBysqZDZnkab/oZBMB60p6+KK0KuNt/rpjRR+axshVvej6533kP37ncx6WKIQl2ij+SoMst/S+7m4R2/3rA4uVlTCNNEm1hVv1JG2fGxap9HxHi+o3YrQ3CXpXM1Ywd32DcduerZ18iKBnL5lOWMT3xuVvjU23FsGsMwxG4xO661CbDuuVijqD7n1NEOX1CPtwLWgXLuqLGRRtVs16DCY3UpvtYxfuC+Qm1ylhGLkYUA7zJT9BlcIWyhfU/dbM5AKFLDg+mJkHQvtfqsrrMsf7hSEVsI6XsfgHFRcPf+oq7+UTd8yAcFUzrV1/QehsVSSbIA6muDlzvWlWkO7Tu9VNlmcgkELqG3Rd50h+p/UIVO1BbKDUPkFznwUuWk0fszS9yEHmDl2g779ny6mgIh/ytEbIocmYp1hs66LrBtM5f8Ek/ga7lUnS47JGJvO22cMRv4dHDyvtou+OHaF/viL6+boZ9JlvOPM6lxvGmLipSe1QzM4y5YMJ6d7lI+3FEYr5mlsp7dDaRtP5E+qTaSGW3tCGYqK3BA94uozDCEmE4XGLfh9G1FnJM/UPHQdf3OhDrn4a1v30mNOAD NASuKHuT C8R468b7MOwiNCW5zd/DM9IvwAmLBwGL0Ap7cnzN/riSqHyeDGqvK58R7JvXJDwsnTVee8e3dcQ8/3Ry0F8LqwD1yiMSeFtaV0burmzA0gk6HiyffG57VGXOxON9iR4Jv3Oa3t9Z7+CW+uPV9QNvXLuACEUooFgK8QO3KuBt5GugfnBQbESIGXO3jEJN03a0RLM9z8Qre5TPTngzQydWw2mWcCSAxLS/T/6WCGZndUadyT1q4s51+VR3KIAS4th2KA5tIo4shM6tWiKVJxUHFrNdwcjlyCYFZPJAzY8aYD3a+9q7A/CaTlO12BqG+Ld4esst4 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: One of the testcases triggers a CoW on the 255th page (0-indexing) with max_ptes_shared = 256. This leads to 0-254 pages (255 in number) being unshared, and 257 pages shared, exceeding the constraint. Suppose we run the test as ./khugepaged -s 2. Therefore, khugepaged starts collapsing the range to order-2 folios, since PMD-collapse will fail due to the constraint. When the scan reaches 254-257 PTE range, because at least one PTE in this range is writable, with other 3 being read-only, khugepaged collapses this into an order-2 mTHP, resulting in 3 extra PTEs getting unshared. After this, we encounter a 4-sized chunk of read-only PTEs, and mTHP collapse stops according to the scaled constraint, but the number of shared PTEs have now come under the constraint for PMD-sized THPs. Therefore, the next scan of khugepaged will be able to collapse this range into a PMD-mapped hugepage, leading to failure of this subtest. Fix this by reducing the CoW range. Note: The only objective of this patch is to make the test work for the PMD-case; no extension has been made for testing for mTHPs. Signed-off-by: Dev Jain --- tools/testing/selftests/mm/khugepaged.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c index 8a4d34cce36b..143c4ad9f6a1 100644 --- a/tools/testing/selftests/mm/khugepaged.c +++ b/tools/testing/selftests/mm/khugepaged.c @@ -981,6 +981,7 @@ static void collapse_fork_compound(struct collapse_context *c, struct mem_ops *o static void collapse_max_ptes_shared(struct collapse_context *c, struct mem_ops *ops) { int max_ptes_shared = thp_read_num("khugepaged/max_ptes_shared"); + int fault_nr_pages = is_anon(ops) ? 1 << anon_order : 1; int wstatus; void *p; @@ -997,8 +998,8 @@ static void collapse_max_ptes_shared(struct collapse_context *c, struct mem_ops fail("Fail"); printf("Trigger CoW on page %d of %d...", - hpage_pmd_nr - max_ptes_shared - 1, hpage_pmd_nr); - ops->fault(p, 0, (hpage_pmd_nr - max_ptes_shared - 1) * page_size); + hpage_pmd_nr - max_ptes_shared - fault_nr_pages, hpage_pmd_nr); + ops->fault(p, 0, (hpage_pmd_nr - max_ptes_shared - fault_nr_pages) * page_size); if (ops->check_huge(p, 0)) success("OK"); else