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

From: Kiryl Shutsemau

Date: Tue Jan 20 2026 - 06:19:51 EST


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.

--
Kiryl Shutsemau / Kirill A. Shutemov