From patchwork Tue Dec 27 00:28:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13081970 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 B729DC4332F for ; Tue, 27 Dec 2022 00:29:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FAC7900003; Mon, 26 Dec 2022 19:29:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AA88900002; Mon, 26 Dec 2022 19:29:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 771CA900003; Mon, 26 Dec 2022 19:29:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6834F900002 for ; Mon, 26 Dec 2022 19:29:27 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 497DFA06F2 for ; Tue, 27 Dec 2022 00:29:26 +0000 (UTC) X-FDA: 80286202332.11.9D611E9 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf11.hostedemail.com (Postfix) with ESMTP id C46E240003 for ; Tue, 27 Dec 2022 00:29:23 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=CfjFcXmX; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672100964; 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:references:dkim-signature; bh=a2xsuyBzGhFwK6demWSKeLgqkbiNTVuKySpakNGC5ag=; b=chQ3WvWRm3aoiE01R1mbAusVVgGGmbjKzQNeW5XvREHX2/irQAmNwUhOmhoZRThzrnu+Jk fE9sVL02DHt+f+HY+tHWpjdfnTcMfz501miVueDaUHnnyXfl/ONFAV/BKxPUyDOrwb50/+ HbsKzRS+dWciAZ7GIHa+tgG3aImEXvY= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=CfjFcXmX; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672100964; a=rsa-sha256; cv=none; b=ovsjL0HFq6D+zG2IHFDgmM7fyPMm9I3WtYQcZWgEqAtYarFyvc2ByFnEcyPsYMOaVwKVK8 52DsubA0S2IOpPHWU6qYvuHMMtyaJRbkD+sU5WBbDXoL+80CneFk2F2rOERZbr+yRGc+PS svgoDQ2EUBLX2j5L8exFUg7W7e6ZoVQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672100963; x=1703636963; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Of+NKY4iw8WWEB0zFLvTUTaUQgg1khMoL1jqU3Qdd5I=; b=CfjFcXmXvnnk0gShtv/aVchUKsVeZHs80MXvdioHDuWpHmZl2szsExpm sVVjbffoM/KccXVOBbFP1EdQtt8sH5gBUEBH6/WEZ8UdovI51MbsxKOVZ 9lLH0ZFMl8kTNUeIdyBRYVFdrXwI1M4Qgcl5VpftSAjvmYzfWNYHZqfQY Z/xskwjd/MtskKwjjym9o2GO6jGUfYBgf3VQBnQoLN6+Tn3hKM/oCn/hz AeThhx3fbQMj529uOrQjSr1+SwW+M4eKWE9gPKk8JaWhgXUk0gBZWbfD9 s4UzwQO0RRg591rdp+CHecG4/PeUXwuh0D/mvJyO7bVUT0+74r/twksCk A==; X-IronPort-AV: E=McAfee;i="6500,9779,10572"; a="322597199" X-IronPort-AV: E=Sophos;i="5.96,277,1665471600"; d="scan'208";a="322597199" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Dec 2022 16:29:21 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10572"; a="760172178" X-IronPort-AV: E=Sophos;i="5.96,277,1665471600"; d="scan'208";a="760172178" Received: from yyang3-mobl1.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.254.212.104]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Dec 2022 16:29:16 -0800 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Huang, Ying" , Zi Yan , Yang Shi , Baolin Wang , Oscar Salvador , Matthew Wilcox , Bharata B Rao , Alistair Popple , haoxin Subject: [PATCH 0/8] migrate_pages(): batch TLB flushing Date: Tue, 27 Dec 2022 08:28:51 +0800 Message-Id: <20221227002859.27740-1-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C46E240003 X-Rspam-User: X-Stat-Signature: u1ij579prozmtydq7ze5gbsfm43xycet X-HE-Tag: 1672100963-599083 X-HE-Meta: U2FsdGVkX1/rbw7baGsqlzdY2EE20OzZ1oXZtTJO4DLcaKwSsij2oFmNhzmdXflWUxRseK+ASX5S4OcSZlaosoMs2qWhTIfvaCM074wbmplWFR6mwiBO5cFRztrdHhkO+hlvJrpvmLLALpmsq2I4vfbSqoI5hFMNSy2JFlMK78o19fHu/WPKApscZiWqwO1VUkMaaGuLVr8tRZqQmJTvzYeC2yB2IORKjOp+lmeij9EjkYoFfUsmcYkwx5JbDKAUuAQV0Dnj2R/hDAbuxqVMWf4l7lDDd5/g/kIGQrX7hpWbJMjTG2ZnbV5wfyYovGviUR98i3tvctlaijHf71y0aX0itM7HO7ULoUSQGXD2J2ggZtHsaEdlITYNwBJnfUwmUbZRYoJeBTGt03GhdcuAqNnCajMyQ6wGtP0FiIuNY+lMWdpwDPFV+ArsGLzGIpn+0KBt50+PEaEs7jckCuUa64a3kUu2r7gWJtmOkRQnObgzYdxe71MSdV6X2Ihjt1KGfI1RXWC9b+iry4WwXGMsgtVTeCAnfiNzsRiq/rwEjjXTgrRFUhDg374Ugq86/HnWfP0GBTb9hlZniZDyRR5nXrJRhXt3PSbqmvHHyaTjBgzB8DC2uUUNL9TRZHWxuAGrx2ZaQh2W744dlT+99/1y4AFVGbMEkvP21uCgzsfzYt10tCxFgowFA/KewZKs1JauDKJg3jFYJMYgar9TzVHqx5DH8cxJA8iHH9bL7aQ5nHyirgpbutm+4XgyOnh7lsaM3saaX1eidi2YaZiHH+ZjQyCW0yHrtkoZK9s/3GORWIl7ssnWNg/UEZTvFC7PcVR5O8f+BQuqgyE4rRmBwUEI/enNPd1+sxyHLC2GZUSBGnptFABT16hPoGsdVDkg6nNbQf0N9tF9ce4wQbblgX8w8ZT8Z90Cm045me9l8er1NE0S/LIqUIFNHJ5d3OX5VkAa 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: From: "Huang, Ying" Now, migrate_pages() migrate folios one by one, like the fake code as follows, for each folio unmap flush TLB copy restore map If multiple folios are passed to migrate_pages(), there are opportunities to batch the TLB flushing and copying. That is, we can change the code to something as follows, for each folio unmap for each folio flush TLB for each folio copy for each folio restore map The total number of TLB flushing IPI can be reduced considerably. And we may use some hardware accelerator such as DSA to accelerate the folio copying. So in this patch, we refactor the migrate_pages() implementation and implement the TLB flushing batching. Base on this, hardware accelerated folio copying can be implemented. If too many folios are passed to migrate_pages(), in the naive batched implementation, we may unmap too many folios at the same time. The possibility for a task to wait for the migrated folios to be mapped again increases. So the latency may be hurt. To deal with this issue, the max number of folios be unmapped in batch is restricted to no more than HPAGE_PMD_NR in the unit of page. That is, the influence is at the same level of THP migration. We use the following test to measure the performance impact of the patchset, On a 2-socket Intel server, - Run pmbench memory accessing benchmark - Run `migratepages` to migrate pages of pmbench between node 0 and node 1 back and forth. With the patch, the TLB flushing IPI reduces 99.1% during the test and the number of pages migrated successfully per second increases 291.7%. This patchset is based on mm-unstable. Changes: from rfc to v1: - Rebased on v6.2-rc1 - Fix the deadlock issue caused by locking multiple pages synchronously per Alistair's comments. Thanks! - Fix the autonumabench panic per Rao's comments and fix. Thanks! - Other minor fixes per comments. Thanks! Best Regards, Huang, Ying