All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Gavin Shan <gshan@redhat.com>, linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	shan.gavin@gmail.com,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	Alexander Duyck <alexander.duyck@gmail.com>
Subject: Re: [RFC PATCH] mm/page_reporting: Adjust threshold according to MAX_ORDER
Date: Wed, 16 Jun 2021 13:15:01 +0200	[thread overview]
Message-ID: <be4b74ef-ac53-8c36-3097-6acead368cab@redhat.com> (raw)
In-Reply-To: <bd49c9d2-fb0b-5387-45f4-dbaa7a9eac2c@redhat.com>

On 16.06.21 14:59, Gavin Shan wrote:
> On 6/16/21 5:59 PM, David Hildenbrand wrote:
>> On 16.06.21 03:53, Gavin Shan wrote:
>>> On 6/14/21 9:03 PM, David Hildenbrand wrote:
>>>> On 11.06.21 09:44, Gavin Shan wrote:
>>>>> On 6/1/21 6:01 PM, David Hildenbrand wrote:
>>>>>> On 01.06.21 05:33, Gavin Shan wrote:
>>>>>>> The PAGE_REPORTING_MIN_ORDER is equal to @pageblock_order, taken as
>>>>>>> minimal order (threshold) to trigger page reporting. The page reporting
>>>>>>> is never triggered with the following configurations and settings on
>>>>>>> aarch64. In the particular scenario, the page reporting won't be triggered
>>>>>>> until the largest (2 ^ (MAX_ORDER-1)) free area is achieved from the
>>>>>>> page freeing. The condition is very hard, or even impossible to be met.
>>>>>>>
>>>>>>>       CONFIG_ARM64_PAGE_SHIFT:              16
>>>>>>>       CONFIG_HUGETLB_PAGE:                  Y
>>>>>>>       CONFIG_HUGETLB_PAGE_SIZE_VARIABLE:    N
>>>>>>>       pageblock_order:                      13
>>>>>>>       CONFIG_FORCE_MAX_ZONEORDER:           14
>>>>>>>       MAX_ORDER:                            14
>>>>>>>
>>>>>>> The issue can be reproduced in VM, running kernel with above configurations
>>>>>>> and settings. The 'memhog' is used inside the VM to access 512MB anonymous
>>>>>>> area. The QEMU's RSS doesn't drop accordingly after 'memhog' exits.
>>>>>>>
>>>>>>>       /home/gavin/sandbox/qemu.main/build/qemu-system-aarch64          \
>>>>>>>       -accel kvm -machine virt,gic-version=host                        \
>>>>>>>       -cpu host -smp 8,sockets=2,cores=4,threads=1 -m 4096M,maxmem=64G \
>>>>>>>       -object memory-backend-ram,id=mem0,size=2048M                    \
>>>>>>>       -object memory-backend-ram,id=mem1,size=2048M                    \
>>>>>>>       -numa node,nodeid=0,cpus=0-3,memdev=mem0                         \
>>>>>>>       -numa node,nodeid=1,cpus=4-7,memdev=mem1                         \
>>>>>>>         :                                                              \
>>>>>>>       -device virtio-balloon-pci,id=balloon0,free-page-reporting=yes
>>>>>>>
>>>>>>> This tries to fix the issue by adjusting the threshold to the smaller value
>>>>>>> of @pageblock_order and (MAX_ORDER/2). With this applied, the QEMU's RSS
>>>>>>> drops after 'memhog' exits.
>>>>>>
>>>>>> IIRC, we use pageblock_order to
>>>>>>
>>>>>> a) Reduce the free page reporting overhead. Reporting on small chunks can make us report constantly with little system activity.
>>>>>>
>>>>>> b) Avoid splitting THP in the hypervisor, avoiding downgraded VM performance.
>>>>>>
>>>>>> c) Avoid affecting creation of pageblock_order pages while hinting is active. I think there are cases where "temporary pulling sub-pageblock pages" can negatively affect creation of pageblock_order pages. Concurrent compaction would be one of these cases.
>>>>>>
>>>>>> The monstrosity called aarch64 64k is really special in that sense, because a) does not apply because pageblocks are just very big, b) does sometimes not apply because either our VM isn't backed by (rare) 512MB THP or uses 4k with 2MB THP and c) similarly doesn't apply in smallish VMs because we don't really happen to create 512MB THP either way.
>>>>>>
>>>>>>
>>>>>> For example, going on x86-64 from reporting 2MB to something like 32KB is absolutely undesired.
>>>>>>
>>>>>> I think if we want to go down that path (and I am not 100% sure yet if we want to), we really want to treat only the special case in a special way. Note that even when doing it only for aarch64 with 64k, you will still end up splitting THP in a hypervisor if it uses 64k base pages (b)) and can affect creation of THP, for example, when compacting (c), so there is a negative side to that.
>>>>>>
>>>>>
>>>>> [Remove Alexander from the cc list as his mail isn't reachable]
>>>>>
>>>>
>>>> [adding his gmail address which should be the right one]
>>>>
>>>>> David, thanks for your time to review and sorry for the delay and late response.
>>>>> I spent some time to get myself familiar with the code, but there are still some
>>>>> questions to me, explained as below.
>>>>>
>>>>> Yes, @pageblock_order is currently taken as page reporting threshold. It will
>>>>> incur more overhead if the threshold is decreased as you said in (a).
>>>>
>>>> Right. Alex did quite some performance/overhead evaluation when introducing this feature. Changing the reporting granularity on most setups (esp., x86-64) is not desired IMHO.
>>>>
>>>
>>> Thanks for adding Alex's correct mail address, David.
>>>
>>>>>
>>>>> This patch tries to decrease the free page reporting threshold. The @pageblock_order
>>>>> isn't touched. I don't understand how the code changes affecting THP splitting
>>>>> and the creation of page blocks mentioned in (b) and (c). David, could you please
>>>>> provide more details?
>>>>
>>>> Think of it like this: while reporting to the hypervisor, we temporarily turn free/"movable" pieces part of a pageblock "unmovable" -- see __isolate_free_page()->del_page_from_free_list(). While reporting them to the hypervisor, these pages are not available and not even marked as PageBuddy() anymore.
>>>>
>>>> There are at least two scenarios where this could affect creation of free pageblocks I can see:
>>>>
>>>> a. Compaction. While compacting, we might identify completely movable/free pageblocks, however, actual compaction on that pageblock can fail because some part is temporarily unmovable.
>>>>
>>>> b. Free/alloc sequences. Assume a pageblocks is mostly free, except two pages (x and y). Assume the following sequence:
>>>>
>>>> 1. free(x)
>>>> 2. free(y)
>>>> 3. alloc
>>>>
>>>> Before your change, after 1. and 2. we'll have a free pageblock. 3 won't allocate from that pageblock.
>>>>
>>>> With your change, free page reporting might run after 1. After 2, we'll not have a free pageblock (until free page reporting finished), and 3. might just reallocate what we freed in 2 and prevent having a free pageblock.
>>>>
>>>>
>>>> No idea how relevant both points are in practice, however, the fundamental difference to current handling is that we would turn parts of pageblocks temporarily unmovable, instead of complete pageblocks.
>>>>
>>>
>>> Thank you for the details. Without my changes and the page reporting threshold
>>> is @pageblock_order, the whole page block can become 'movable' from 'unmovable'.
>>> I don't think it's what we want, but I need Alex's confirm.
>>
>> __isolate_free_page() will set the pageblock MIGRATE_MOVABLE in that case. It's only temporarily unmovable, while we're hinting.
>>
>> Note that MOVABLE vs. UNMOVABLE is just grouping for free pages, and even setting it to the wrong migratetype isn't "wrong" as in "correctness". It doesn't make a difference if there are no free pages because the whole block is isolated.
>>
> 
> Yes, It doesn't matter since these pages have been isolated. The migration type is changed to MIGRATE_MOVABLE
> in __isolated_free_page(). My questions are actually:
> 
> (1) Is it possible the migration type is changed from MIGRATE_UNMOVABLE to MIGRATE_MOVABLE
>       in __isolated_free_page()?

Yes, if the isolated page covers at least half the pageblock. So either 
if we isolate the complete pageblock (as it's free, there is nothing 
unmovable) or half the pageblock. The latter seems to be some heuristic 
that says if it's half-free, make it MIGRATE_MOVABLE -- maybe because 
that increases the chances that we might get a completely movable 
pageblock later (would have too look into the details).

> (2) After the free page reporting is completed, the migrate type is restored to MIGRATE_UNMOVABLE?

No, don't think so. And it also doesn't make too much sense if we 
decided when isolating that we're better off using MIGRATE_MOVABLE. 
After all, we're just putting back a free page we previously isolated 
from the free lists.

-- 
Thanks,

David / dhildenb


  reply	other threads:[~2021-06-16 11:15 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-01  3:33 [RFC PATCH] mm/page_reporting: Adjust threshold according to MAX_ORDER Gavin Shan
2021-06-01  8:01 ` David Hildenbrand
2021-06-11  7:44   ` Gavin Shan
2021-06-14 11:03     ` David Hildenbrand
2021-06-15  2:26       ` Alexander Duyck
2021-06-15  2:26         ` Alexander Duyck
2021-06-16  9:10         ` Gavin Shan
2021-06-16  8:03           ` David Hildenbrand
2021-06-16 13:16             ` Gavin Shan
2021-06-16 11:20               ` David Hildenbrand
2021-06-16 13:58                 ` Gavin Shan
2021-06-16 12:07                   ` David Hildenbrand
2021-06-21  5:16                     ` Gavin Shan
2021-06-16 14:15           ` Alexander Duyck
2021-06-16 14:15             ` Alexander Duyck
2021-06-21  7:03             ` Gavin Shan
2021-06-21  7:52             ` Gavin Shan
2021-06-21 13:43               ` Alexander Duyck
2021-06-21 13:43                 ` Alexander Duyck
2021-06-16  1:53       ` Gavin Shan
2021-06-16  7:59         ` David Hildenbrand
2021-06-16 12:59           ` Gavin Shan
2021-06-16 11:15             ` David Hildenbrand [this message]
2021-06-02  0:03 ` Andrew Morton
2021-06-11  2:54   ` Gavin Shan

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=be4b74ef-ac53-8c36-3097-6acead368cab@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.duyck@gmail.com \
    --cc=anshuman.khandual@arm.com \
    --cc=gshan@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=shan.gavin@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.