From patchwork Tue Aug 20 09:49:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13769794 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 8AA80C3DA4A for ; Tue, 20 Aug 2024 09:49:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66D366B0096; Tue, 20 Aug 2024 05:49:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F9456B0099; Tue, 20 Aug 2024 05:49:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 421126B0096; Tue, 20 Aug 2024 05:49:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0A3886B0098 for ; Tue, 20 Aug 2024 05:49:49 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A2140A1A2D for ; Tue, 20 Aug 2024 09:49:48 +0000 (UTC) X-FDA: 82472152056.09.AF8F152 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by imf19.hostedemail.com (Postfix) with ESMTP id AB9161A0005 for ; Tue, 20 Aug 2024 09:49:46 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b="RWmL/4ZY"; spf=pass (imf19.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724147308; 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=0UzIUq6FZARxgmMF/NPpanXZh/m/Lu7W5+1J/nDWXrI=; b=Bws/JsDaVg1qsWc0nt9LxlUo/UPRRiraNgu2wKjippRaSGUk31tA9w45EtNW70boP6/C5h RHoeLsg5FBckPwQBqZ0Q3aTCTBywetQWK+FbAmGtMoCYWM8zASRpM7aDNocvPD4KZhq/nE gpeSrpb3weQg6yt739jdFxpqufaLQ4A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724147308; a=rsa-sha256; cv=none; b=vzxsHqqX1eFZH22+DAbf8iddUk3QUxHrVeW/04MzBpTI1ZFd5UboAHz4nqcxlRcIKq7gcQ QbgDej5H1QPz4vmI+7hyHhvZ3u7slF/T+c0YGykNf/yXhsDmgoqeuxKUPI1dTeTM7J6j/X 4OibsdRS8gxSWLOCFfUNABFaXIbQloY= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b="RWmL/4ZY"; spf=pass (imf19.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1724147384; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=0UzIUq6FZARxgmMF/NPpanXZh/m/Lu7W5+1J/nDWXrI=; b=RWmL/4ZYqLu4isjVJqF065APyI1B4CaYn8dLMNrtRGAgX3aPdxj/78ecjeJxkd7hU8f9vAJq8oqDoMJ2AE7P5+uPFg6xqT0BTPaocAw3k+VK/1zfJPkHqKgAmUYPtfq8rSNO3EK0NZmwhHY6i1pehEI5xkVqoW62W4E4h7/lmoU= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WDIEwjB_1724147382) by smtp.aliyun-inc.com; Tue, 20 Aug 2024 17:49:43 +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 3/5] mm: khugepaged: support shmem mTHP copy Date: Tue, 20 Aug 2024 17:49:15 +0800 Message-Id: <222d615b7c837eabb47a238126c5fdeff8aa5283.1724140601.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: AB9161A0005 X-Stat-Signature: yo7jpkw5h315go3jg34yz1i8m6swj4ae X-HE-Tag: 1724147386-806538 X-HE-Meta: U2FsdGVkX19T5AUzU5tcWvkn0RyrOKw4xF1UiUBrZFe+HLUAUKFzUlS0GdIqIb5dSYrg1wgOzek4b1q4urKVSKgM40ef7Ys7IWC1aYRtcQ+JCVtRohoKgqcVT+wFWaVkRCR0K9+ODUN209I9UrmX6csKKV0TtcgOzTguskIZtlGCwBxlYmwzN5louCEfuFuh4KfbDO+cAwHXdEmDQ7DmO/XkB9wWviONWqqmJteKdZ9EFS1QaFtONWOWjvMc8u+EufsefqCSr0S1VOVKwXBQqo3rUVqKTzOBooqGGQZIeiwE8nljbW1a0jLGsIfGIIiuJtb4ZfetITHE99S2PHG13oYklT1MKtQjeMOGCAW8yCab2WD3/sqPhf0+6MJD+tQ9GG38eDN2LpXYevlRTcuRQno8361tDFBeV80SIoPBUaTY46zmabRfvNVUxII6pn7HqTJectWM6gUCg3PQb4I3q6NWdJvicfhxJp5k2SiemHw3ESI/edh0Fk0MuV6IO5eRGiJjBh/FbCdl7fDskzfcqgWOVXeF3v1BZUtIUkyt9wRlby3RUyttqbF+ZaSJAUvCnbq+wRTg1cdrD5ldBob1jekqTr2T4kEHwPS14mE1pwLNBpu9xmUQa/TGIa9XZxqiCYS1mq09XNafy5yIPStc0vjZ+FKMFFLIe25PYxMuei8feb7RSUoYrzhR45HqCqgwoc0qOUykmREw/9IXLeUyf2pDr3oI577qWrDwn+qojlHvv/bnWiRNznJ3/6nhZ7uKfRiRPZqZe9gh83mIzIgzZdvW2M4yvZhj+2+rzTh7n3ZOU2/UcBNDAwiYb+K1f8fhKoqnHV1NAJ4KBPgQsGnbKUpz/ra6xZILwsdJBqpRv7rJhT28zree3TDFjDgGzrR2peFL3zlX4Xd0AHqyv2ifqqIR6a88QsLKj7OkNItdqyOrvGSJUehrTGLsvSCtytHorlKF1GLGNSJcgENhUUX a4cQuksZ sNfmMqUTOHlMn0jsu/f5GBi4KxrtbkGWKnXHiCY86xh0U+u8LgVMl6YoV1j7XWnl1qE2jJXjRh7EGLr2h7rdxE8b3kupkzD5ikFMbd6MUoOb9v0qvaP4GdIoPNNJLL3GZPKWwv1497z8x183OLSNbUIagyrWV275uAZazHxnAo9HSFTqTA8IV0RjOfgDCJu8yXLu0RoxQm+CdmXD0hZmYChr/kGSDAANCxfdu 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: Iterate each subpage in the large folio to copy, as preparation for supporting shmem mTHP collapse. Signed-off-by: Baolin Wang --- mm/khugepaged.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index e015c94eba09..4996f7487c13 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2056,17 +2056,22 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, index = start; dst = folio_page(new_folio, 0); list_for_each_entry(folio, &pagelist, lru) { + int i, nr_pages = folio_nr_pages(folio); + while (index < folio->index) { clear_highpage(dst); index++; dst++; } - if (copy_mc_highpage(dst, folio_page(folio, 0)) > 0) { - result = SCAN_COPY_MC; - goto rollback; + + for (i = 0; i < nr_pages; i++) { + if (copy_mc_highpage(dst, folio_page(folio, i)) > 0) { + result = SCAN_COPY_MC; + goto rollback; + } + index++; + dst++; } - index++; - dst++; } while (index < end) { clear_highpage(dst);