From: Ryan Roberts <ryan.roberts@arm.com>
To: "Huang, Ying" <ying.huang@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@redhat.com>,
Matthew Wilcox <willy@infradead.org>,
Gao Xiang <xiang@kernel.org>, Yu Zhao <yuzhao@google.com>,
Yang Shi <shy828301@gmail.com>, Michal Hocko <mhocko@suse.com>,
Kefeng Wang <wangkefeng.wang@huawei.com>,
Barry Song <21cnbao@gmail.com>, Chris Li <chrisl@kernel.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 0/6] Swap-out mTHP without splitting
Date: Wed, 13 Mar 2024 08:50:51 +0000 [thread overview]
Message-ID: <3d60e840-00e1-4e6e-a9f4-e67d905b1782@arm.com> (raw)
In-Reply-To: <87zfv32aq7.fsf@yhuang6-desk2.ccr.corp.intel.com>
On 13/03/2024 01:15, Huang, Ying wrote:
> Ryan Roberts <ryan.roberts@arm.com> writes:
>
>> On 12/03/2024 08:49, Ryan Roberts wrote:
>>> On 12/03/2024 08:01, Huang, Ying wrote:
>>>> Ryan Roberts <ryan.roberts@arm.com> writes:
>>>>
>>>>> Hi All,
>>>>>
>>>>> This series adds support for swapping out multi-size THP (mTHP) without needing
>>>>> to first split the large folio via split_huge_page_to_list_to_order(). It
>>>>> closely follows the approach already used to swap-out PMD-sized THP.
>>>>>
>>>>> There are a couple of reasons for swapping out mTHP without splitting:
>>>>>
>>>>> - Performance: It is expensive to split a large folio and under extreme memory
>>>>> pressure some workloads regressed performance when using 64K mTHP vs 4K
>>>>> small folios because of this extra cost in the swap-out path. This series
>>>>> not only eliminates the regression but makes it faster to swap out 64K mTHP
>>>>> vs 4K small folios.
>>>>>
>>>>> - Memory fragmentation avoidance: If we can avoid splitting a large folio
>>>>> memory is less likely to become fragmented, making it easier to re-allocate
>>>>> a large folio in future.
>>>>>
>>>>> - Performance: Enables a separate series [4] to swap-in whole mTHPs, which
>>>>> means we won't lose the TLB-efficiency benefits of mTHP once the memory has
>>>>> been through a swap cycle.
>>>>>
>>>>> I've done what I thought was the smallest change possible, and as a result, this
>>>>> approach is only employed when the swap is backed by a non-rotating block device
>>>>> (just as PMD-sized THP is supported today). Discussion against the RFC concluded
>>>>> that this is sufficient.
>>>>>
>>>>>
>>>>> Performance Testing
>>>>> ===================
>>>>>
>>>>> I've run some swap performance tests on Ampere Altra VM (arm64) with 8 CPUs. The
>>>>> VM is set up with a 35G block ram device as the swap device and the test is run
>>>>> from inside a memcg limited to 40G memory. I've then run `usemem` from
>>>>> vm-scalability with 70 processes, each allocating and writing 1G of memory. I've
>>>>> repeated everything 6 times and taken the mean performance improvement relative
>>>>> to 4K page baseline:
>>>>>
>>>>> | alloc size | baseline | + this series |
>>>>> | | v6.6-rc4+anonfolio | |
>>>>> |:-----------|--------------------:|--------------------:|
>>>>> | 4K Page | 0.0% | 1.4% |
>>>>> | 64K THP | -14.6% | 44.2% |
>>>>> | 2M THP | 87.4% | 97.7% |
>>>>>
>>>>> So with this change, the 64K swap performance goes from a 15% regression to a
>>>>> 44% improvement. 4K and 2M swap improves slightly too.
>>>>
>>>> I don't understand why the performance of 2M THP improves. The swap
>>>> entry allocation becomes a little slower. Can you provide some
>>>> perf-profile to root cause it?
>>>
>>> I didn't post the stdev, which is quite large (~10%), so that may explain some
>>> of it:
>>>
>>> | kernel | mean_rel | std_rel |
>>> |:---------|-----------:|----------:|
>>> | base-4K | 0.0% | 5.5% |
>>> | base-64K | -14.6% | 3.8% |
>>> | base-2M | 87.4% | 10.6% |
>>> | v4-4K | 1.4% | 3.7% |
>>> | v4-64K | 44.2% | 11.8% |
>>> | v4-2M | 97.7% | 13.3% |
>>>
>>> Regardless, I'll do some perf profiling and post results shortly.
>>
>> I did a lot more runs (24 for each config) and meaned them to try to remove the
>> noise in the measurements. It's now only showing a 4% improvement for 2M. So I
>> don't think the 2M improvement is real:
>>
>> | kernel | mean_rel | std_rel |
>> |:---------|-----------:|----------:|
>> | base-4K | 0.0% | 3.2% |
>> | base-64K | -9.1% | 10.1% |
>> | base-2M | 88.9% | 6.8% |
>> | v4-4K | 0.5% | 3.1% |
>> | v4-64K | 44.7% | 8.3% |
>> | v4-2M | 93.3% | 7.8% |
>>
>> Looking at the perf data, the only thing that sticks out is that a big chunk of
>> time is spent in during contpte_convert(), called as a result of
>> try_to_unmap_one(). This is present in both the before and after configs.
>>
>> This is an arm64 function to "unfold" contpte mappings. Essentially, the PMD is
>> being split during shrink_folio_list() with TTU_SPLIT_HUGE_PMD, meaning the
>> THPs are PTE-mapped in contpte blocks. Then we are unmapping each pte one-by-one
>> which means the contpte block needs to be unfolded. I think try_to_unmap_one()
>> could potentially be optimized to batch unmap a contiguously mapped folio and
>> avoid this unfold. But that would be an independent and separate piece of work.
>
> Thanks for more data and detailed explanation.
And thanks for your review! I'll address all your comments (and any others that
I get in the meantime) and repost after the merge window. It would be great if
we can get this in for v6.10.
>
> --
> Best Regards,
> Huang, Ying
next prev parent reply other threads:[~2024-03-13 8:50 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-11 15:00 [PATCH v4 0/6] Swap-out mTHP without splitting Ryan Roberts
2024-03-11 15:00 ` [PATCH v4 1/6] mm: swap: Remove CLUSTER_FLAG_HUGE from swap_cluster_info:flags Ryan Roberts
2024-03-11 15:00 ` [PATCH v4 2/6] mm: swap: free_swap_and_cache_nr() as batched free_swap_and_cache() Ryan Roberts
2024-03-20 11:10 ` Ryan Roberts
2024-03-20 14:13 ` David Hildenbrand
2024-03-20 14:21 ` Ryan Roberts
2024-03-11 15:00 ` [PATCH v4 3/6] mm: swap: Simplify struct percpu_cluster Ryan Roberts
2024-03-12 7:52 ` Huang, Ying
2024-03-12 8:51 ` Ryan Roberts
2024-03-13 1:34 ` Huang, Ying
2024-03-11 15:00 ` [PATCH v4 4/6] mm: swap: Allow storage of all mTHP orders Ryan Roberts
2024-03-12 7:51 ` Huang, Ying
2024-03-12 9:40 ` Ryan Roberts
2024-03-13 1:33 ` Huang, Ying
2024-03-20 12:22 ` Ryan Roberts
2024-03-21 4:39 ` Huang, Ying
2024-03-21 12:21 ` Ryan Roberts
2024-03-22 2:38 ` Can you help us on memory barrier usage? (was Re: [PATCH v4 4/6] mm: swap: Allow storage of all mTHP orders) Huang, Ying
2024-03-22 9:23 ` Ryan Roberts
2024-03-25 3:20 ` Huang, Ying
2024-03-22 13:19 ` Chris Li
2024-03-23 2:11 ` Akira Yokosawa
2024-03-25 0:01 ` Paul E. McKenney
2024-03-25 3:16 ` Huang, Ying
2024-03-26 17:08 ` Ryan Roberts
2024-03-25 3:00 ` Huang, Ying
2024-03-22 2:39 ` [PATCH v4 4/6] mm: swap: Allow storage of all mTHP orders Huang, Ying
2024-03-22 9:39 ` Ryan Roberts
2024-03-11 15:00 ` [PATCH v4 5/6] mm: vmscan: Avoid split during shrink_folio_list() Ryan Roberts
2024-03-11 22:30 ` Barry Song
2024-03-12 8:12 ` Ryan Roberts
2024-03-12 8:40 ` Barry Song
2024-03-15 10:43 ` David Hildenbrand
2024-03-15 10:49 ` Ryan Roberts
2024-03-15 11:12 ` David Hildenbrand
2024-03-15 11:38 ` Ryan Roberts
2024-03-18 2:16 ` Huang, Ying
2024-03-18 10:00 ` Yin, Fengwei
2024-03-18 10:05 ` David Hildenbrand
2024-03-18 15:35 ` Ryan Roberts
2024-03-18 15:36 ` Ryan Roberts
2024-03-19 2:20 ` Yin Fengwei
2024-03-19 14:40 ` Ryan Roberts
2024-03-19 2:31 ` Yin Fengwei
2024-03-11 15:00 ` [PATCH v4 6/6] mm: madvise: Avoid split during MADV_PAGEOUT and MADV_COLD Ryan Roberts
2024-03-13 7:19 ` Barry Song
2024-03-13 9:03 ` Ryan Roberts
2024-03-13 9:16 ` Barry Song
2024-03-13 9:36 ` Ryan Roberts
2024-03-13 10:37 ` Barry Song
2024-03-13 11:08 ` Ryan Roberts
2024-03-13 11:37 ` Barry Song
2024-03-13 12:02 ` Ryan Roberts
2024-03-13 9:19 ` Lance Yang
2024-03-13 14:02 ` Lance Yang
2024-03-20 13:49 ` Ryan Roberts
2024-03-20 14:35 ` Lance Yang
2024-03-20 17:38 ` Ryan Roberts
2024-03-21 1:38 ` Lance Yang
2024-03-21 13:38 ` Ryan Roberts
2024-03-21 14:55 ` Lance Yang
2024-03-21 15:24 ` Ryan Roberts
2024-03-22 0:56 ` Lance Yang
[not found] ` <ffeee7da-e625-40dc-8da8-b70e4e6ef935@redhat.com>
2024-03-15 10:55 ` Ryan Roberts
2024-03-15 11:13 ` David Hildenbrand
2024-03-20 13:57 ` Ryan Roberts
2024-03-20 14:09 ` David Hildenbrand
2024-03-12 8:01 ` [PATCH v4 0/6] Swap-out mTHP without splitting Huang, Ying
2024-03-12 8:49 ` Ryan Roberts
2024-03-12 13:56 ` Ryan Roberts
2024-03-13 1:15 ` Huang, Ying
2024-03-13 8:50 ` Ryan Roberts [this message]
2024-03-12 8:45 ` Ryan Roberts
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3d60e840-00e1-4e6e-a9f4-e67d905b1782@arm.com \
--to=ryan.roberts@arm.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chrisl@kernel.org \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=shy828301@gmail.com \
--cc=wangkefeng.wang@huawei.com \
--cc=willy@infradead.org \
--cc=xiang@kernel.org \
--cc=ying.huang@intel.com \
--cc=yuzhao@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).