From patchwork Mon Aug 19 08:14:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13768058 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 C48B8C5320E for ; Mon, 19 Aug 2024 08:14:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0D7F6B008C; Mon, 19 Aug 2024 04:14:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E97496B0095; Mon, 19 Aug 2024 04:14:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D35D76B0092; Mon, 19 Aug 2024 04:14:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A6FA96B008A for ; Mon, 19 Aug 2024 04:14:55 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 62900A10A7 for ; Mon, 19 Aug 2024 08:14:55 +0000 (UTC) X-FDA: 82468284150.04.422A1F4 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 2F244180007 for ; Mon, 19 Aug 2024 08:14:52 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=A3z7YfkG; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf16.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724055230; a=rsa-sha256; cv=none; b=C/QPc8qSJAX8Br4RTJHBxj/SHPnvETKk+HkmRc4ynlmW8VK1AorHzRoXnW6vTSXtACmyaR gMGrvx4WMfgq4To/TF+8I+qKn/PJk1a9MDIMp5N3Jyz9wuneny5MaNRGcXQqCc+RugABFA u4T8647vvGK0xMUqEa80nsOD3+gM4bY= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=A3z7YfkG; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf16.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724055230; 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:dkim-signature; bh=6V7YyBIVTByMizq9TfzYvtX9oniYv5CXu0xU9TzqEDc=; b=Ay8kDodW2oYzKAJ9AjK51ZSuU5bt15vTy85PDi+C3Q7fAWVaIwJ1G1+k8aCHG+v7KfSgx/ qJh2A2a3BglOpOL7PqJbrxCh7wVIqBk7EZvaXnR6zJTmRowQdk8SEmcqo8xYfdVir7pA/e SzrLxGqJa2woT+Y6m9d0toY7zksk5hE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1724055290; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=6V7YyBIVTByMizq9TfzYvtX9oniYv5CXu0xU9TzqEDc=; b=A3z7YfkGm4x0DCib5UTsQjmy4e6ieTd746j6dyJd5ERlOW2GpyFPk1mS23yQcpEn1E+f3t+YPUaFmKYgQLITAcBTF2/+gSXAtxM8TPBb+5hrjlar3Kfn5WuXSpLO3/ZkPPyFEcC2/icWr0kpb16+nVo2oTBENXb2HjmK6zTxcl8= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WD9CrIt_1724055288) by smtp.aliyun-inc.com; Mon, 19 Aug 2024 16:14:49 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: hughd@google.com, willy@infradead.org, david@redhat.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] mm: khugepaged: support shmem mTHP collapse Date: Mon, 19 Aug 2024 16:14:05 +0800 Message-Id: <8a2a87affac65f2ecdcea9917b5ae7a261689676.1724054125.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2F244180007 X-Stat-Signature: 76xxhqa6wewmnxru53c97me3gx3wxgfm X-Rspam-User: X-HE-Tag: 1724055292-469048 X-HE-Meta: U2FsdGVkX19w02PSYJ3eIOYhaeQl+0E8JSyHoIWHH5PTNa4Q7A0qLp1IENxpDcmtso34Ga8k5CurVD7ClTZENeCA8+W8eIRR1c11vcdoABilD7boWND/z9J18e7rdtdv1klmqbZCIXqOLMHkW/iuf/B2Eri+TcY69HoXgdiGE/wWWQjsOoKktFd4vk5bQoIfBOnIQHe5si/cuKtRLoX9oz1+TfK7x1DL+5YzDV+8qK8Y5AP79LqIgzSUmdLRXTinihUmuIHlF6Fd6W6RothXOOthc3wPIH+eQEOjibuhEoSBGtWrUsBEmyuKtZIIaTQwQlM0xhj5uAPeL+rA6gEM50zyzNlTsMW62Gffps44V7FI8v7rvRxWfwuq0xT6jnGq/oek+Zs6SktdEJK5mU1Ed92TxZg0C12TCl2XH+08GEGUwJxzYqM1iDykHehf5yyLSeLh29v+9z6yhWFHuyqJm/OCqCecfPNc8sAIifCNG0zejMkMs65WB3zI0Jlrfz6rt3vQCDsQIe4sG3giAAV5UqckJP0Z/ynUcwcJWtOYn7rRZaPzsnCh/Q7K2Su9iAKn4xhcQRCYchF+QxU0o8Y8Qy3SNc6Qt8Vgg4Qco1Nrko0XbHr2oM9AIxBM/jx7Ub8YVxjUD01tLXCf5XEyDBmOgNHiy/k1KgRiHYN1OfCUVp3+5+e87ZIGF/aIwte8SLV3f0Kct60yn3vBgxWZGcxDtGe415MXJmW0bGXnTxwWTAwXnQH7VpArXYjvJhk3JiQa+8T5n5FcOMivlhZ8WKZV16Htd7/7YzUlvn9kL389pHdbj5TjJjcesCB1F5HW3XDm4xLuMuy+PVrO8+nZFW0YBWjHwFVlOEINqvWpsSyVatEMpIhmAemLsUCfA/dUOP/GmpUG22I+whs8UpaobTvjS64x0Wo48o6n0a+C6GDGIM5q1MRLymrs5S5PqWvrBWrpMk7jiUhjW/qCcJiJmZ5 s8acm9xV xzXZqOYf7EZAQiB9KYQVfL+zl3oho2twwACcFNEh6PgTuYhfr+l3LREMtU9g4fQh2Op4UXCSHYrNZkT3jw3BHblVPZZWd5WVb1Usfz/4YGk18bm+uql128QRkDKvLcczIHk+WMX+EOlRtaaO0xSqfGFksNKLfeMqfQ3XqnAzxpJe9Fr5bJnKKZSrmn3fYWNvfQMddiQyNre2sfWvvG+bPgA5p3EeHgLEW+QS0 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: Shmem already supports the allocation of mTHP, but khugepaged does not yet support collapsing mTHP folios. Now khugepaged is ready to support mTHP, and this patch enables the collapse of shmem mTHP. Signed-off-by: Baolin Wang --- mm/khugepaged.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 91ee672db202..4b35239b5e46 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1847,7 +1847,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, } } while (1); - for (index = start; index < end; index++) { + for (index = start; index < end;) { xas_set(&xas, index); folio = xas_load(&xas); @@ -1866,6 +1866,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, } } nr_none++; + index++; continue; } @@ -1947,12 +1948,10 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, * we locked the first folio, then a THP might be there already. * This will be discovered on the first iteration. */ - if (folio_test_large(folio)) { - result = folio_order(folio) == HPAGE_PMD_ORDER && - folio->index == start - /* Maybe PMD-mapped */ - ? SCAN_PTE_MAPPED_HUGEPAGE - : SCAN_PAGE_COMPOUND; + if (folio_order(folio) == HPAGE_PMD_ORDER && + folio->index == start) { + /* Maybe PMD-mapped */ + result = SCAN_PTE_MAPPED_HUGEPAGE; goto out_unlock; } @@ -2013,6 +2012,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, * Accumulate the folios that are being collapsed. */ list_add_tail(&folio->lru, &pagelist); + index += folio_nr_pages(folio); continue; out_unlock: folio_unlock(folio); @@ -2265,16 +2265,10 @@ static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr, continue; } - /* - * TODO: khugepaged should compact smaller compound pages - * into a PMD sized page - */ - if (folio_test_large(folio)) { - result = folio_order(folio) == HPAGE_PMD_ORDER && - folio->index == start - /* Maybe PMD-mapped */ - ? SCAN_PTE_MAPPED_HUGEPAGE - : SCAN_PAGE_COMPOUND; + if (folio_order(folio) == HPAGE_PMD_ORDER && + folio->index == start) { + /* Maybe PMD-mapped */ + result = SCAN_PTE_MAPPED_HUGEPAGE; /* * For SCAN_PTE_MAPPED_HUGEPAGE, further processing * by the caller won't touch the page cache, and so