From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-49.mta0.migadu.com [91.218.175.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95984285061 for ; Wed, 26 Aug 2026 04:43:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787719442; cv=none; b=NECcmNCCH0b43krAbneyJwaU6JS9rguVhlOIaCVMQUaqfcegpjWBhBJr3Ey9rNgsQcX7Bb4ozhGxl6ZKeRWjUzDYR0ZZMYaEm/Uka9gLvoiVdUBc9HuD/8l+R02DD08e5gqfvNceRPBcjSSPOSVxt3PnxpNUcXG3P318dGfjUnc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787719442; c=relaxed/simple; bh=cvAC78os6bsdbW8XgBgcHaxo7gGIY2XAK7sGylBvEnc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=XFcG6AYvDvdHr7CeJievRz6irlP+OkyKCnGmbd3v0feM/y0e/LeDltE4qr8KMLvi1NEry8bwozCcfMZZHKbqg5hOK8X0Ig0vMFdPhuNR73Vu+n5PYuFTtCvEY4/aJC0iga1reksXM7upX51vdoktoSQZIBYlHWZYcGatb+qjv+k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=N1F7ELc5; arc=none smtp.client-ip=91.218.175.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="N1F7ELc5" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=cvAC78os6bsdbW8XgBgcHaxo7gGIY2XAK7sGylBvEnc=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787719436; v=1; x=1788324236; b=N1F7ELc5rDkuwft/4qHqUCi2YMlDHT8cTnKDePPYTtoOmiaUJI9pTqi0MoY5zq852F+pnxBn 2uutfKIll2VbInhLzNRj7/b9ae5dYxwGlaC3/W9pPO6oXZ9kSpibcYAquBx1P2S6hbx4hqwNeIS bvspPNtns6RSmomGa09gy0XE= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost (2602:fce1:44f:115e::) by smtp.migadu.com with ESMTPS id d945f1d31c09ef98; Wed, 26 Aug 2026 04:43:55 +0000 X-Mizu-Trace-ID: d945f1d31c09ef98 X-Migadu-Flow: FLOW_OUT From: Lance Yang To: pedrodemargomes@gmail.com Cc: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, ziy@nvidia.com, baolin.wang@linux.alibaba.com, liam@infradead.org, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH mm-stable] mm/khugepaged: avoid unnecessary checking for swap entries when collapsing a mTHP Date: Wed, 26 Aug 2026 12:43:50 +0800 Message-Id: <20260826044350.24284-1-lance.yang@linux.dev> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260825192433.3185880-1-pedrodemargomes@gmail.com> References: <20260825192433.3185880-1-pedrodemargomes@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Tue, Aug 25, 2026 at 04:24:33PM -0300, Pedro Demarchi Gomes wrote: >mthp_collapse() tries to swap in PTEs when collapsing a mTHP if there are any >swap PTEs in the PMD range, even if none of those swap PTEs are >actually part of the mTHP's range. > >Track swap PTEs in cc->mthp_unmapped_ptes so that mthp_collapse() can >tell whether the mTHP's own range contains a swap PTE, and skip the >swapin check when it doesn't. > >Signed-off-by: Pedro Demarchi Gomes >--- Yeah, the code itself is fine, but ... Any numbers showing how much the extra scan costs? khugepaged is already quite a mess and badly needs some cleanup. TBH, another bitmap + more bookkeeping doesn't feel worth it unless the win is pretty clear :) > mm/khugepaged.c | 29 +++++++++++++++++++---------- > 1 file changed, 19 insertions(+), 10 deletions(-) > >diff --git a/mm/khugepaged.c b/mm/khugepaged.c >index 11ff98d55c76..38596172f7dc 100644 >--- a/mm/khugepaged.c >+++ b/mm/khugepaged.c >@@ -117,6 +117,9 @@ struct collapse_control { > > /* Each bit represents a single occupied (!none/zero) page. */ > DECLARE_BITMAP(mthp_present_ptes, MAX_PTRS_PER_PTE); >+ >+ /* Each bit represents a single not present and not none/zero pte. */ >+ DECLARE_BITMAP(mthp_unmapped_ptes, MAX_PTRS_PER_PTE); BTW, the comment is a bit of a mouthful :) How about "Each bit represents a non-present, non-none PTE." ? Cheers, Lance [...]