Re: [PATCH 1/2] mm: Allow architectures to request 'old' entries when prefaulting

From: Linus Torvalds
Date: Thu Dec 17 2020 - 13:24:20 EST


On Thu, Dec 17, 2020 at 2:54 AM Kirill A. Shutemov <kirill@xxxxxxxxxxxxx> wrote:
>
> Also if the range doesn't have a mappable page we would setup a page
> table into the PMD entry. It means we cannot have huge page mapped there
> later. It may be a bummer: getting the page table out of page table tree
> requires mmap_write_lock().
>
> We also take ptl for cold page cache. It may increase ptl contention, but
> it should be negligible with split-ptl.

Both good points.

I doubt the second one is really noticeable, since if it isn't cached
you're going to have all the costs of actually getting the page, but
the first one sounds fairly fundamental.,

But I think both issues could be easily fixed by doing that
"xas_is_value()" and checking for 'head' being non-NULL early.

In fact, maybe that should be done as part of that early setup loop.
So that early code that is now

+ head = xas_find(&xas, end_pgoff);
+ if (!head) {
+ rcu_read_unlock();
+ return;
+ }
+
+ while (xas_retry(&xas, head))
+ head = xas_next_entry(&xas, end_pgoff);

could/should perhaps be something more along the lines of

+ head = xas_find(&xas, end_pgoff);
+ for (; ; head = xas_next_entry(&xas, end_pgoff)) {
+ if (!head) {
+ rcu_read_unlock();
+ return;
+ }
+ if (likely(!xas_retry(&xas, head))
+ break;
+ }

instead. So that if we don't find any cached entries, we won't do
anything, rather than take locks and then not do anything.

Then that second loop very naturally becomes a "do { } while ()" one.

Hmm?

Linus