Re: [PATCH v1 1/2] mm: move pte table reclaim code to memory.c

From: David Hildenbrand (Red Hat)

Date: Wed Jan 21 2026 - 07:17:50 EST


On 1/20/26 12:19, Kiryl Shutsemau wrote:
On Mon, Jan 19, 2026 at 11:07:07PM +0100, David Hildenbrand (Red Hat) wrote:
The pte-table reclaim code is only called from memory.c, while zapping
pages, and it better also stays that way in the long run. If we ever
have to call it from other files, we should expose proper high-level
helpers for zapping if the existing helpers are not good enough.

So, let's move the code over (it's not a lot) and slightly clean it up a
bit by:
- Renaming the functions.
- Dropping the "Check if it is empty PTE page" comment, which is now
self-explaining given the function name.
- Making zap_pte_table_if_empty() return whether zapping worked so the
caller can free it.
- Adding a comment in pte_table_reclaim_possible().
- Inlining free_pte() in the last remaining user.
- In zap_empty_pte_table(), switch from pmdp_get_lcokless() to
pmd_clear(), we are holding the PMD PT lock.

By moving the code over, compilers can also easily figure out when
zap_empty_pte_table() does not initialize the pmdval variable, avoiding
false-positive warnings about the variable possibly not being
initialized.

mm/memory.c is a kitchen sink as it is.

I think you miss opportunity to introduce mm/zap.c and move all zap
code.

It can be done for code from both mm/memory.c and mm/huge_memory.c.
Line between THP and non-THP code gets more and more blurry over time.

The same can be done for copy and fault code. I think it is going to be
more maintainable this way.

While agree that memory.c contains too much stuff, I don't think zap.c is the right abstraction either. And actually, I think basic page table handling is well kept in memory.c, or moved along with other stuff (fork()) handling somewhere else.

So I won't do any of that as part of this patch.

--
Cheers

David