Re: [PATCH 01/10] mm/ksm: reduce the flush action for ksm merging page

From: David Hildenbrand
Date: Wed Jun 05 2024 - 05:14:42 EST


On 05.06.24 11:10, Alex Shi wrote:


On 6/5/24 3:26 PM, David Hildenbrand wrote:
On 04.06.24 15:02, Alex Shi wrote:


On 6/4/24 6:45 PM, David Hildenbrand wrote:
On 04.06.24 12:26, Alex Shi wrote:


On 6/4/24 4:07 PM, David Hildenbrand wrote:
On 04.06.24 06:24, alexs@xxxxxxxxxx wrote:
From: "Alex Shi (tencent)" <alexs@xxxxxxxxxx>

We can put off the flush action util a merging is realy coming. That
could reduce some unmerge page flushing.
BTW, flushing only do at arm, mips and few other archs.


I'm no expert on that flushing, but I thought we would have to do the flushing before accessing page content -- before calculating the checksum etc.

Now you would only do it before the pages_identical() check, but not when calculating the checksum.


Hi David,

Thanks a lot for comments!

If calc_checksum() is wrong before pages_idential(), (that's just after page was write_protected, that's a real guarantee for page context secured) pages_identical could recheck and make thing right.


Yes, but you would get more wrong checksums, resulting in more unnecessary pages_identical() checks.

That is missing from the description, and why we want to change that behavior.

What's the net win?

And as to 2 flush functions here, I didn't see the guarantee for other writer from any other place. So maybe we should remove these flush action?

"I didn't see the guarantee for other writer from any other place" can you rephrase your comment?

If you mean "the process could modify that page concurrently", then you are right. But that's different than "the process modified the page in the past and we are reading stale content because we missed a flush".


Maybe moving the flush before checksum could relief some worries. :)
But still no one knows what flush really help, since if page content only syncs to memory by the flush, the kernel or process can't be work with current code.

Please explain to me why we care about moving the flushs at all :)

If they are NOP on most architectures either way, why not simply leave them there and call it a day?
Uh, 2 reasons:
1, it uses page and can't convert to folio now.
2, as you pointed, flush action w/o page reading seems just waste time.

Alex, I don't think the approach you take for coming up with the current set of patches is a good idea.

Please reconsider what you can actually convert to folios and what must stay pages for now due to support for large folios in that code.

Then, please explain properly why changes are required and why they are safe.

For example, for in scan_get_next_rmap_item() we really *need* the page and not just the folio. So just leave the flushing there and be done with it.

--
Cheers,

David / dhildenb