We use pte_range_none() to determine whether contiguous PTEs are empty for an mTHP allocation. Instead of iterating the while loop for every order, use some information from the previous iteration to eliminate some cases. v1->v2: - Break into two patches v1: https://lore.kernel.org/all/20240913091902.1160520-1-dev.jain@xxxxxxx/ Dev Jain (2): mm: Make pte_range_none() return number of empty PTEs mm: Compute first_set_pte to eliminate evaluating redundant ranges mm/memory.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) -- 2.30.2