From patchwork Mon Jan 16 06:30:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13102650 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 0939FC54EBE for ; Mon, 16 Jan 2023 06:31:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C8786B0071; Mon, 16 Jan 2023 01:31:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7783F6B0072; Mon, 16 Jan 2023 01:31:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63FC46B0073; Mon, 16 Jan 2023 01:31:14 -0500 (EST) 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 5401A6B0071 for ; Mon, 16 Jan 2023 01:31:14 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 27B0F1203AA for ; Mon, 16 Jan 2023 06:31:14 +0000 (UTC) X-FDA: 80359690068.02.E226F86 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by imf15.hostedemail.com (Postfix) with ESMTP id BD170A0004 for ; Mon, 16 Jan 2023 06:31:11 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=fQxpu9A6; spf=pass (imf15.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 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=1673850672; 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=sarsKZi/wbQ1SdbEsTZHzbH9duuOwomNyxVS9qY3McI=; b=Xn0n9V2gJZGMb8oHq+N/5vbVlVIj72Zl57SpyqaLFC5aKoxI0sFeRgFCZrfLtgKxkAyFfX eQPv7uelq9rBDj8kjCsoY49yEmxkWSCsZj4exnp5sNvzhOQVpYszBKMJT6hqZMr+8UWcsY OUZ5Ne8PKfySjfMPGCbpSpFHVo8Foxs= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=fQxpu9A6; spf=pass (imf15.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 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=1673850672; a=rsa-sha256; cv=none; b=pGovQbZvxvxx7ZFru5ys6mDeMdr99JZEqm7Xz2WEpaEXmfkDx5AZltlSFvFQnTATQ8Uh/Z EcELiXUcn9mI+LUZnNiZz5JVLzTMgTDbvZEaJ/GcXoaz+KL7OMJLmkpsB6GWkqd7c0LP8h QEWMD7tdiTJHBW3mVch/rKc9gQNGM5g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673850671; x=1705386671; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=uwCY+kg/niXT6bxn6yuzEYKrQhYZyea+2TI3E6O7Lv8=; b=fQxpu9A6dQlsd9vCFjM3TI+g9S5pDDMz5bs6QmWo2I34rATdcVGiTKbq x+cP/2KuyYhR9kEyS5FboCPYFtPcW4CcheHvDD385RjubwuMqx4c3fqcO PEXz9TkCqG5f66QnCaMduu1nIGcbj+Q2lBVkvfWkktLAtrSXV8oSQ6RKx R1Hv1x8inQWqujWRmBitd+OjBuQXyIzU7L0Who/LGziPU11DwSSwcMvDZ pL9pGDHFloUwUgxaL3pjpvPjD/7koHrzhw6V/AUoNq02JWVsNJhNdpTds mbS58Chg7eCSQVUPho5O632+FVh4FlwHqTAwRO1mtGdO5aVPnDP6B2bKj w==; X-IronPort-AV: E=McAfee;i="6500,9779,10591"; a="388892112" X-IronPort-AV: E=Sophos;i="5.97,220,1669104000"; d="scan'208";a="388892112" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jan 2023 22:31:10 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10591"; a="801286575" X-IronPort-AV: E=Sophos;i="5.97,220,1669104000"; d="scan'208";a="801286575" Received: from tiangeng-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.28.220]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jan 2023 22:31:06 -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 , Minchan Kim Subject: [PATCH -v3 0/9] migrate_pages(): batch TLB flushing Date: Mon, 16 Jan 2023 14:30:48 +0800 Message-Id: <20230116063057.653862-1-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: BD170A0004 X-Stat-Signature: ght4pdt7kefxqpj1sapufqajo5sxo53f X-Rspam-User: X-HE-Tag: 1673850671-197497 X-HE-Meta: U2FsdGVkX1+5UzAPBJKUV29sMd829EsAatSQszu3ssxGfQESCidowPR5alY/r5jcJ1kb0fo87jSY+fWTcIAvHqZs33H5KC/H1ybhSOyBzH+6UugmD71aADr5i8vvKvFfKA3WsTOw8i2t2umDW/hMS9hL7kIJYVQiU3FN9nfkYF8vkKDHpLUa/kkVC4jal/Wm3kwAXPCQf+XHJWNCifULu1SGwXb6rpOkNDtOv+26XiXW7TelEHkQF+lS5aNbZjK4UuDzM9923oP+V+SrAc2rmgAGxxk/zBnkb3tzxp1V+sMBcYjlTKL+d/Sq11zuDofJ3NmfbeiDVlCBrQISsTllnRbceVbw6xpF7FqKBG2mFCQ8WIJR/s8AESiZadslzO6+H3mhc5MKyfg8sO9WVyi6iEUdgj70OMqsaWSiQnUwq0Fxn8PcY3GHDmBBszPjhlf2oE3pnbu8Oi5LHewV9bOfLDVmTfT1GfKlmOvJ8qAde/AeR2yrNsC7H9ATbZMUsRjlQa4ri2i+UQfLyG1Ck/zHv6Ywx8IRdZ+G37EyaADOnbDMHgSDqkDbX+s/RnWvWR2yIXSOAbIO+1KrYawZUGQtLGaKkGGNUJrA5rRqnC9qSOchP8YYBwqdq696UzIsBi04gCbhkhHYekZfk+w6E1CXDRWNIMHbnOzuBHHg2rryOvVlVQRIdY23WxoWeAQvxbf6kwBl5fd5YR9QjPBXcj3r6YccE/g0XcrgDJB1Qg2nJDeKA+VMpxJMCa8C2VZjBWDgDnKE8WDtCUdFZNghIk4N8dBvSiiq/ihH3DcsGLIcyQuZOZpxqYZoKttsicREr/1XEcUvt4EQSUQrRmLfv9U8G9OhoHTqcdGAGwMrgOgb4va5X2bG0lmB2v1dS93QEMtwqcZq+Z/ErI9/BHsi+yHXBeW6rtg282yPHLOX7QuX97RQeW6yYxJdQVZpucRGka5I 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: v3: - Rebased on v6.2-rc4 - Fixed a bug about non-LRU folio migration. Thanks Mike! - Fixed some comments. Thanks Baolin! - Collected reviewed-by. v2: - Rebased on v6.2-rc3 - Fixed type force cast warning. Thanks Kees! - Added more comments and cleaned up the code. Thanks Andrew, Zi, Alistair, Dan! - Collected reviewed-by. 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