From patchwork Mon Aug 19 08:14:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13768060 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 B707DC52D7C for ; Mon, 19 Aug 2024 08:15:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 87D5E6B0098; Mon, 19 Aug 2024 04:15:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 82D576B0099; Mon, 19 Aug 2024 04:15:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D1A06B009A; Mon, 19 Aug 2024 04:15:02 -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 4CB1D6B0098 for ; Mon, 19 Aug 2024 04:15:02 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0AC55A1084 for ; Mon, 19 Aug 2024 08:15:02 +0000 (UTC) X-FDA: 82468284444.15.0872451 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) by imf16.hostedemail.com (Postfix) with ESMTP id E506118001D for ; Mon, 19 Aug 2024 08:14:58 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=ZBd2VAQ6; spf=pass (imf16.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.97 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=1724055224; 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=xzFqhooDuGLHWOHvpjrYWo9DgZTyuxAAfwMQUt6kp8M=; b=QAsFzkumGxb6EBBUXdxwGHqqiCKEZDHzMfXtYAQr2OJE65bzUn/BVONMk1HbiXh4qtggVs Z0yYErj27QRkc5F0cgsegOZiAJDpN+7kOAm8KOQxcgwEkpdZeodKndxct5tWSHExdp4ZdN OGCumonvFwr5FXcwbt+lXuZAoFx1zj0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724055224; a=rsa-sha256; cv=none; b=tOT2u/aV9QMq6gcLftCBdxCPKCmByny5ERoRSPfJeVAMjDi4eU207bQIyBmHKuEM6U7ama 2bh4UWIVPYNZyMquveg52OwzAyIEY8YxGTk09EqhAOaCJFqvsRf+VZlfhlFRVg2ziKm75/ QchleVM363a375jdzBnY2IA9/pPxMN4= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=ZBd2VAQ6; spf=pass (imf16.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.97 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=1724055289; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=xzFqhooDuGLHWOHvpjrYWo9DgZTyuxAAfwMQUt6kp8M=; b=ZBd2VAQ6mVAeLthLMAGrLwrGf9+g3Nq5KIwokq/ZYTkixUtBzoBUaYqOcqcN65UQLMWqAeAxMq5HLbqwfvjx0kkVLfsAP51Tj9ILed/pjB00moXwyVbHmrFUJAn0tmDdOHxb3CswTguMXjKcmFc1qqIkb/T6Z1Gg6li/Iu4hlU8= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WD9CrIU_1724055287) by smtp.aliyun-inc.com; Mon, 19 Aug 2024 16:14:48 +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 3/5] mm: khugepaged: support shmem mTHP copy Date: Mon, 19 Aug 2024 16:14:04 +0800 Message-Id: <938e8cc5a15f841fdd343d324d8a6dd989cd52e0.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-Queue-Id: E506118001D X-Stat-Signature: zjquf7u61fcufbgmdowmsaqzpzq56arb X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1724055298-614742 X-HE-Meta: U2FsdGVkX19jHbEZJTv5B8F56IB0jhlKTcoY6oCpvJxiNsbFO3sJW6a6PHUcMXoMsJo0NFNWxEOAn3Q6RUfs2jxUU7V4UNFeGnv+WiZhuK32hv7omCsR905Kqff6SW0066BP88o1RqsMYFqsynBP+RZ2RbyXbmcumGBPmtgD7rlCyww6+m4wr/BVtwx/z9hTp2uTNsqpCeFtxisXSRl0HkNPpY9ZOMolE0ZDGhhRpJVQeEyUyJ/r8ZBBMWKMZLwOzyRAagdFW5GtcYuZw8hyoOSLpMkGQnn6Ih8mD+MAxdTOv+KjKQFgrn2w3uGZb2sHAoWoMjxrN+dRyUS+pRge1kf/PvccaNMZlGK5zzMwKrjb0keSCeich/ELJgz/Nq96Pl11xtZA3aq3C2j3QHiYD795AjYAIh9c0Y3teBlIRRKf5zLUggfMOqqCYPR+diyjBpFpj5hK4qKkF1zgQJtRvS/rZ+uWFbLc8b7N7OQlftEzOFRyvFyF7kgXa6Vxea7U2BRpgV222k6u6XHe2V/4JJPKP/d+7pS/0wauOd26JDoSzCqTVe71PGNnmA0z0S8EHzYgNCCJ+CYrNvQlkpPq7LFTHyHOcCqD1PythQ9efmNEZkWz1169EZtgsSalg0I1ndJMs6scj5RwGJkpBujtQvURcvkcR3NJn/2efofEamxjRgoCgwrcX7PNpNaaC4fv2ce7qgXMFxrC3vCOD/HYv3Q9ibf0kElNSj6C+3LC1qT2qyOd0ZBKEg1enTNrpnmLdFE6HWbr5Zcwa+HDwu0mjs1ejcmlHajklXlF3myyMXu4UNNDVbsRogtRRGhclyEBTXae0ynxpQ+DHCF2+3Kzop5UYoIBxoxQvEx/35cYjIRpUeQriW/K08vtKFiEmV+hU2ELuJSp/Ui5bwpj1M1pm6ktePlsB7p0eT6cCnwJip8xgWgl8sSEU9J0U9g2J0zJf+x1xjbV9tyyb5Ol18d wboSlq/D 0JIb9bPfESuddfmLX+k2ntCVzbOpUEmfvHxdzwNtLL1jCFPVcCod0fOeg8jbaLCeusICDtxMAzw/KAbxYGkT73aWt/Q+637u1ZdpeZNml7N8UvbsU4TlyXxRUGctkqF2gwE/+hajr3f6tLWRaRr1JXoRs9ay4vc2ou4qteGDiA8Xfqgn1jBNhyjZcAI/oyHbjyUjd0iCAO39ZQmc= 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 60d95f08610c..91ee672db202 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2060,17 +2060,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);