freenode
Kernel & Low-Level

Linux fixes page-table accounting on memory hot-remove

Constructor and destructor mismatches left NR_PAGETABLE wrong when freeing hot-removed tables on x86, arm64, and RISC-V.

Muchun Song has posted fixes for page-table teardown bugs that left kernel page-table accounting unbalanced after memory hot-remove on x86, arm64, and RISC-V.

Page-table pages can be allocated through paths that run a constructor (and bump NR_PAGETABLE) or through paths that do not, including generic sparse vmemmap population. Architecture hot-remove code did not treat those cases consistently: some teardown paths always ran the destructor, others never did. Either way the counter drifted. On x86-64 the failure showed up with HugeTLB vmemmap optimization (HVO). Splitting a PMD allocated a kernel PTE table with a constructor; a later hot-remove freed it without the matching destructor and left NR_PAGETABLE elevated.

The common change makes the shared page-table free helper run the destructor only when the page was constructor-initialized. RISC-V and arm64 hot-remove paths then route through that helper instead of unconditional destructor calls. David Hildenbrand steered the design toward the common helper; Dave Hansen and others have acked the series. Andrew Morton is taking it through the MM tree, with stable backports planned once prerequisite x86 free-path changes are in place on older trees.