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 20877C636CC for ; Wed, 8 Feb 2023 06:22:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A4646B0071; Wed, 8 Feb 2023 01:22:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42E146B0072; Wed, 8 Feb 2023 01:22:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2CE566B0073; Wed, 8 Feb 2023 01:22:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 169446B0071 for ; Wed, 8 Feb 2023 01:22:05 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4DC5D120CC3 for ; Wed, 8 Feb 2023 06:22:04 +0000 (UTC) X-FDA: 80443129368.11.80A05D5 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by imf12.hostedemail.com (Postfix) with ESMTP id 3858040003 for ; Wed, 8 Feb 2023 06:21:58 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675837322; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pbtzl9wbi3I73hyaBuyHP5bT7ND9byfiNZQdPXW97Lg=; b=bpe6d00ybktwgdan3eVgTfG6kTMUxofwX31PaoHPsipPv9DYPFlGu+jZSEHXKgmq7RTNK/ eGAkQBUTB74FdEn75dKWG+/laorU5eg0SV5FHnegegzzOzXwZYms9LS2hUYDC6Sb4e1j5f VwqiSk5GHSabpSwq1kP2758Pymc9H0s= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675837322; a=rsa-sha256; cv=none; b=g/UcVpBvDzabGqNZrIYGsF5jFIKLROD3tvT9nNtKye1G5Rg/jHJZNyB1X0bRfS8xhsPZKb VP6qolCHixqNx768bRuFZA4nHU0OybINYoDXYqLd9gYJbC8XD238ao6bEG68HgdjJ9Z3/q LKmojpSpXA6qg9p3h/WsfL5LJz5peTw= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R911e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0VbAFnmI_1675837308; Received: from 30.240.100.162(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VbAFnmI_1675837308) by smtp.aliyun-inc.com; Wed, 08 Feb 2023 14:21:50 +0800 Content-Type: multipart/alternative; boundary="------------uQwfbfWywm9WcKHJWpyZFOjU" Message-ID: Date: Wed, 8 Feb 2023 14:21:48 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH -v4 0/9] migrate_pages(): batch TLB flushing To: Huang Ying , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zi Yan , Yang Shi , Baolin Wang , Oscar Salvador , Matthew Wilcox , Bharata B Rao , Alistair Popple , Minchan Kim , Mike Kravetz , Hyeonggon Yoo <42.hyeyoo@gmail.com> References: <20230206063313.635011-1-ying.huang@intel.com> From: haoxin In-Reply-To: <20230206063313.635011-1-ying.huang@intel.com> X-Stat-Signature: 9koqown1iymf76anbf8yijsr6m8hpr87 X-Rspam-User: X-Rspamd-Queue-Id: 3858040003 X-Rspamd-Server: rspam06 X-HE-Tag: 1675837318-178171 X-HE-Meta: U2FsdGVkX18ImgQmAaQQT31lFYUMRWCZuhwF8v61ANCV9uDbh/NMlV/GhDKazvWSjtexx1rgH3Kmqo5myr/OQmOS+/XC84bmUt0NA/O7YPk0EHETZgxU0Q3OyPXgz/5vj+h5m0PUcNaYjPtegU4VTNYq2ROoGRXzn3ehDaDp2HLiV8Ed0oYPC8WDiXOZNVypMbGkLH7VvGzB0zbhcSJuxE963O2urT5pFCHuGwFdw5H7GD97sE2UZkop163swSZ8fw7kmUkpcG+HJpZP1ncifr/0Ys8pTZgoGPvJKcN3UQS2iQ9i3TnJJiw9Be1ckbWRCMcB54rsITxyPAjj6occOA7A5pNBA0yIkLma+x68yoNWMhsBKVuDWpcuF7eiDQyUEk81M7qMdymDFt7HoKNLw2BcUaJN1tfCEd3oifkz/VZgewlYlQN8qBTuKWR4mj1a/WaaNeDwlvqO2hhV6o/EGWobuBuWHsbO1s5s3xju3nx1szCRPZVFLS0g18b3MqpDg8Z0f119SxxiiWiWg02BblBtWsjaUx9Eg0cVgv5rZm/4UiSl21ZZgB52sheF/+3CG5dqLSCHp4Xb2TDFKQriMbBVAb6KO+MIScHv9fNmFwDtru5mKM9A81xaD91NbV/4/Mpinbh44cUoOKFdYFnqbrb4wimNlj0FaXv7jx9PO6mrISnzav1anHhJG1I/W8+NWMTRcxsc0NaQg9iIC37A+tjAuqEGQeemP6mAkEjvZtKSIGOLfKbzdjNNwX2SzcneUUPEbnXKbLLZ1spuZ1CU0DKXjdyzh6ym8W7oXQ2ZbmzcIB72brxZzFawCBx23SXPLmyq4ysobjVIIq3OWJDlzoXlQCRTrvcAqmnLduPIbcuwWxrRSo9CXWZEfzd8ZyAoVELKLSovqXkrzCAx/Wv/4HsbLfjvCujm/3VtvXsvlVrSiHaXE9aPhqM1OkMrw/z+d90elZ0FqTgLGFHAyrf XuGJR+mO hHFjN2JN7RcNR/X7GHFeczVhrI6w7GQbTqonPBbnknOvBPAXhrb+F4UebShjYtVFONgEfhmen61YXc8V6rmeXRddIS/FIfVXK6jvGhda9CNuQk0+Tt5yfewqTp5/YM/rp7vFrkyh83LgTMJzJ8a1RJ5BIZx73v8OIaRaK7EkyKoNr+kO24Huzybku67sB5cl+rv1W+DZJnk9Gc32BFPGD/mQeR4/7+LRoJu/KxDPYBqxUfs+bQE6Oh2yF3H1diCtOhAS9OOnF+6gz+Mu609f+yPdAXBl3qa1YssiTlgoyEm6zmmmR9ZeX2lWzAVF2OR0H5Dh1FBSXmgbIMF7EtknDAUg+SH8werUHSDQ1FCqzfImGcmp87gtw+S0+w9xjehHWIsJGEjMbSqx3UteD9QQgmJn6rQwfEXi1bqT81jXlJZ+oO6NhV4Kz2f3mOA== 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: This is a multi-part message in MIME format. --------------uQwfbfWywm9WcKHJWpyZFOjU Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On my arm64 server with 128 cores, 2 numa nodes. I used memhog as benchmark :     numactl -m -C 5 memhog -r100000 1G The test result as below:  With this patch:     #time migratepages 8490 0 1     real 0m1.161s     user 0m0.000s     sys 0m1.161s without this patch:     #time migratepages 8460 0 1     real 0m2.068s     user 0m0.001s     sys 0m2.068s So you can see the migration performance improvement about *+78%* This is the perf  record info. w/o +   51.07%     0.09%  migratepages  [kernel.kallsyms]  [k] migrate_folio_extra +   42.43%     0.04%  migratepages  [kernel.kallsyms]  [k] folio_copy +   42.34%    42.34%  migratepages  [kernel.kallsyms]  [k] __pi_copy_page +   33.99%     0.09%  migratepages  [kernel.kallsyms]  [k] rmap_walk_anon +   32.35%     0.04%  migratepages  [kernel.kallsyms]  [k] try_to_migrate *+   27.78%    27.78%  migratepages  [kernel.kallsyms]  [k] ptep_clear_flush * +    8.19%     6.64%  migratepages  [kernel.kallsyms]  [k] folio_migrate_flagsmigrati_tlb_flush w/ this patch +   18.57%     0.13%  migratepages     [kernel.kallsyms]   [k] migrate_pages +   18.23%     0.07%  migratepages     [kernel.kallsyms]   [k] migrate_pages_batch +   16.29%     0.13%  migratepages     [kernel.kallsyms]   [k] migrate_folio_move +   12.73%     0.10%  migratepages     [kernel.kallsyms]   [k] move_to_new_folio +   12.52%     0.06%  migratepages     [kernel.kallsyms]   [k] migrate_folio_extra Therefore, this patch helps improve performance in page migration So,  you can add Tested-by: Xin Hao 在 2023/2/6 下午2:33, Huang Ying 写道: > 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 v6.2-rc4. > > Changes: > > 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 --------------uQwfbfWywm9WcKHJWpyZFOjU Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

On my arm64 server with 128 cores, 2 numa nodes.

I used memhog as benchmark :

    numactl -m -C 5 memhog -r100000 1G

The test result as below:

 With this patch:

    #time migratepages 8490 0 1

    real 0m1.161s

    user 0m0.000s

    sys 0m1.161s

without this patch:

    #time migratepages 8460 0 1

    real 0m2.068s

    user 0m0.001s

    sys 0m2.068s

So you can see the  migration performance improvement about +78%

 

This is the perf  record info.

w/o
+   51.07%     0.09%  migratepages  [kernel.kallsyms]  [k] migrate_folio_extra                                        
+   42.43%     0.04%  migratepages  [kernel.kallsyms]  [k] folio_copy                                                  
+   42.34%    42.34%  migratepages  [kernel.kallsyms]  [k] __pi_copy_page                                             
+   33.99%     0.09%  migratepages  [kernel.kallsyms]  [k] rmap_walk_anon                                             
+   32.35%     0.04%  migratepages  [kernel.kallsyms]  [k] try_to_migrate                                             
+   27.78%    27.78%  migratepages  [kernel.kallsyms]  [k] ptep_clear_flush                                          
+    8.19%     6.64%  migratepages  [kernel.kallsyms]  [k] folio_migrate_flagsmigrati_tlb_flush

w/ this patch
+   18.57%     0.13%  migratepages     [kernel.kallsyms]   [k] migrate_pages                                 
+   18.23%     0.07%  migratepages     [kernel.kallsyms]   [k] migrate_pages_batch                          
+   16.29%     0.13%  migratepages     [kernel.kallsyms]   [k] migrate_folio_move                             
+   12.73%     0.10%  migratepages     [kernel.kallsyms]   [k] move_to_new_folio                           
+   12.52%     0.06%  migratepages     [kernel.kallsyms]   [k] migrate_folio_extra
 

Therefore, this patch helps improve performance in page migration


So,  you can add Tested-by: Xin Hao <xhao@linux.alibaba.com>


在 2023/2/6 下午2:33, Huang Ying 写道:
From: "Huang, Ying" <ying.huang@intel.com>

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 v6.2-rc4.

Changes:

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
--------------uQwfbfWywm9WcKHJWpyZFOjU--