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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5705AC636CC for ; Mon, 13 Feb 2023 12:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229834AbjBMMfT (ORCPT ); Mon, 13 Feb 2023 07:35:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231214AbjBMMfQ (ORCPT ); Mon, 13 Feb 2023 07:35:16 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 920ACA24C for ; Mon, 13 Feb 2023 04:35:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676291715; x=1707827715; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=8kM/5jxfZlI/Ucp9ptNmm7hMWs8FA/UuOHWcst0gECs=; b=GA15cciRPmkFnO4o6DXIlfxtUo2qppoTrMVWgeq4X90opGcV2iQuVZjf h4a440BmN5u0al9yg3wXn3C8aslUDiQITWFxeNFD7AOEigujBeRhh4+Bo TvIwahzkBKDtmC9QZPaLOO2wpA9iisUWQMm5Y+yjeSv+RWgTB/UvbysOM vJP5EPukRQTD+PAGjhtaRrv37i0hHFpVPtD5GRQ+Bf1CYMJV+K96GLZgt Tk3xmAJbnv2PtrnWk/DkpzSYvWr6jU39ElVSwsmOU5OaOQIPo7ZH1BTef PlBd+0iz+FCQ89rGiPDZvK3M2/0Z0fSHZ81Wc/A407HMU5EfHWtFZF3Fj w==; X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="310513136" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="310513136" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 04:35:15 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10619"; a="646366578" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="646366578" Received: from changxin-mobl2.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.28.171]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 04:35:11 -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 , Xin Hao , Minchan Kim , Mike Kravetz , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH -v5 0/9] migrate_pages(): batch TLB flushing Date: Mon, 13 Feb 2023 20:34:35 +0800 Message-Id: <20230213123444.155149-1-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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%. Xin Hao helped to test the patchset on an ARM64 server with 128 cores, 2 NUMA nodes. Test results show that the page migration performance increases up to 78%. This patchset is based on mm-unstable 2023-02-10. Changes: v5: - Added Xin's test results on ARM 64. Thanks Xin! - Fixed many comments. Thanks Zi and Xin! - Collected reviewed-by and tested-by. v4: - Fixed another bug about non-LRU folio migration. Thanks Hyeonggon! 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