From patchwork Tue Aug 20 09:49:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13769795 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 28DAAC3DA4A for ; Tue, 20 Aug 2024 09:49:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A7AF6B0089; Tue, 20 Aug 2024 05:49:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 55A096B0098; Tue, 20 Aug 2024 05:49:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 335C76B0099; Tue, 20 Aug 2024 05:49:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0C9B96B0089 for ; Tue, 20 Aug 2024 05:49:50 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B2ED3A1A2F for ; Tue, 20 Aug 2024 09:49:49 +0000 (UTC) X-FDA: 82472152098.01.6D798AB Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by imf23.hostedemail.com (Postfix) with ESMTP id B6C63140010 for ; Tue, 20 Aug 2024 09:49:47 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=SsH6Xp0A; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf23.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.98 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=1724147300; 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=bSL4r/U095xkuorzmW1ZSPtc/nQFSKSzXorZ/e7zvxM=; b=2kZWMSmO7OY3c1WLy0zhpGlJbG6KGv8CVM66h9WAeGVgskBTc4cj4BDFEJJhPjXEPx9Hei gFJnuLDWxcbc5nvz4w7X2AWR/zPBRIQ7sSzj3EQAt65XrSvyYqrTGKNkzfB6XxjEAEUHNY GOkLVrFUkbAUZzzsapnjE7iXi1a8o7k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724147300; a=rsa-sha256; cv=none; b=zeEMBXVkkjFo4VgHv3uMtkDxBU20WHi9BAzLk92qjj88XMt+A6i29qUmAaF+ZX0DxmqotM aknUSdXbIGmFoTkZTBSnnqYInaf2FlJVWjAzCOMyNdRHhyDPitjNfm+L5QV/nivDBvt3CN xtpJ9aVbXb/6ojUEp9h9TSwcDnJ97f4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=SsH6Xp0A; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf23.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.98 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1724147385; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=bSL4r/U095xkuorzmW1ZSPtc/nQFSKSzXorZ/e7zvxM=; b=SsH6Xp0ANjTMUbvjUlCGHD9737tCl3RrODOXO0jUNvMS89yDsDYZPRDZmsr/okem1m3HuxwFFo1J8C+RW5QF+aBOfq9jX+q7ouu40GEeM7vOv61N/O1zRpSl/4GNUD/ajERzTOOgkUosju1iuambrYjNsUqvbcrkxfxf/XO1Jtc= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WDIChLj_1724147383) by smtp.aliyun-inc.com; Tue, 20 Aug 2024 17:49:44 +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 v2 4/5] mm: khugepaged: support shmem mTHP collapse Date: Tue, 20 Aug 2024 17:49:16 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B6C63140010 X-Stat-Signature: ek9k1p1fc85g48tgq1kaheghdq65chui X-Rspam-User: X-HE-Tag: 1724147387-47424 X-HE-Meta: U2FsdGVkX19e83ZU97v30sNwA2KADO9smdnuJHl61k5y+9Ad0nBgNFJL+1cnVgHKlGDYt3BZIiQ+DHBAchTZb78xrxQ66dEOYPQ1MXOXrFLq/ohoZBbaPzEOHgsmDCqIBVYTOE1ZU1dGIdeiNr3aEb8zGvGUOoGqN/Q5r600mL6ycxqqgIdhfejgWcAJn6XfE5Qtk2xyyoEGo9KwdjF8VIsWTJsZ3K7gVgsZvNpGGVhbxkAWujACZIJeyuvDjB2XvkpCIr4+FsvehkmyCOo//mEz7fLN3NnkyPB283cARbGVA/wWpQHIco5hzhVmZYnyMxhBUHnk4Dn5cTivwoWnjkFpkpqU2hbBpdIMP1Q9LsLn3WZVxFW0gkriRlelrKxFiNVgALmm9Ccnp40d9sCmBuBojsSA2GF0a7XnAvviDjWmuK4NvQs4KqJ9hWVl19iQh7yBjZL5LwZugcuCsgJVXU44JgXe8NHHMd3JaAuClQNThkFyi9NFqTrRNLSyUMQzoI+2HAgWieEckZ+yiTbVDbVXIeSQCveNHz2s+yECvxchMxYcXLoeU3ttBZsLpmxRXYROyyPf1hFA9J/+9QzKUnKO968IQUcdRRxYMRf4S+LpjyTU/gOY7FiUzJWuoewvuRNffMzFKjAwTin0A5P979Fk3WRdwB8DjdYVbX1EvrSEv6ukKkMv0uS5S4nUEN1QEgQr0ZAJaVDlER+rWe+7OcW/vg6/3F5rZdD5ONQbA0jccZeeErvFq0EyUYF5mllDBD05l08bE5wI62dGDV3R57ytN/qJu5lu/lsmM2CLS5+gQW3icCQI8FA4NYHEH0GFgpA94oiXHQuacKaMXZDCPsilUqphG3S/HqsW+mayTvnUOJnLZBNlBdQsvSsXgROnUAiPB54C1CGJsd7KgX1R0dfdqJJKEcLtaJLPIoFBYvCYmMlJzD0hqGDlXpvnZeIdHANcx67fxbSPwIiXghC FL0Tcvx/ LQubACJt5bqMgC14JUsOPYmvKvO9oa1GeaGSrBJqLejOf9WbJ+RrxF1avaYjL5VPDLnRDVQCpDh1fnXb21SDgkCLdlGPVa0CyWbdv9vwx9GiXkN/bSuj496bBunrFbW242Q3NOZMcHpNY4adJp3F0etshaS2rjx8KaJnmg3xvkRP6oBzfizHGZNuq3IO+o5AfoGDv14DTRh8H171+sc6p19Dz18Yirc+S65aZ 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 4996f7487c13..4a83c40d9053 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1843,7 +1843,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); @@ -1862,6 +1862,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, } } nr_none++; + index++; continue; } @@ -1943,12 +1944,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; } @@ -2009,6 +2008,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); @@ -2261,16 +2261,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