From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 C5F6375801 for ; Sat, 13 Jun 2026 02:02:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781316131; cv=none; b=dFZdb9Tk1hQHy7j4HPAQroQdDBxkta/TJyZWiezTqR06rZeZHFAxM8/NDqmQdh44Z6Wt+ltqAGk57UpHnEU03WAjCqUgNqvlXIeZsHnJpzEbC3lRcV2VP/bp2I/+zFaJBwK1UI+pXZ1+zdX5mHoxje/TCR8WFC4LkO69s66cZgA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781316131; c=relaxed/simple; bh=06iTIkRjCTciipxVe5kTQBRQoyZZmhG/Cii8WnHjl1E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Rn3hj9CjAajAV/yn2sf8idTK+75k1AECBQHq/JfHoJoxQzJZNE5dJKx0+ZbCmcYdEfgN3PKH9yu8WoLD+ZyBjwhgIblZeJH8sOX45EYNfKimgzE0p+B55IUYQF6Whl5FrP4kh84swSDFKX2zqP0dQ2nzDhgt4SiFxHhOmT4Tmzw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EkO5e+f6; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EkO5e+f6" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-bebc80100efso161431166b.1 for ; Fri, 12 Jun 2026 19:02:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781316128; x=1781920928; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=2ppBG8HHL394aG57L0uToj+2v9Gmpu/GgEZ+lqP5+24=; b=EkO5e+f6PHhhQbdwlhcK2L/npyAsVgslAVYemUqqNRV/aghttW10wVjGCAlQUdKJ+a IEzoGi/rFUi+hIyRyaUc2xPcyWnaeBAbxU+bXHAS/wQfuiEhI4ceYOz6SBcPxKP0/Vbb WsEecEbVxVyqIZqOgYIb90QDAHqg4ughFlFTokw3fFhlBQwo5y22fFNx3VLMZPOy4m+u ELfEygZ9+XurYa97q41T3eJaFcUlnV1FbC8Zg24Aro5E05IcTVbol05QkSR7iWQQf7m2 0wWza3TVcTgsxNiGEPf+dMT8Wr8b0nPoM16b4e8a7IPq+naZDssqR6GA1ACnbCKGDvgH kYWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781316128; x=1781920928; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2ppBG8HHL394aG57L0uToj+2v9Gmpu/GgEZ+lqP5+24=; b=T0D5cwC4msa7F7fTKPPz2NWpVHpNxjQPPrVPkMNLH5d3Cwp23rovBriFIVNWp+zPmT HiFlTNIB0b28pDnzbWC9kwepiZHKk6SI4DSKU9T4MxTQt3VILMnXnog6/8D76TwaAB5G dqLmXkzBgKlPZBBOsaq7nkWBzfqyjnI2F+7iI+AZriDzyvqOr9tLoflYCJG3PcExDlNk L8RhmheWKYpw77LWt6U8W7htoW8OnHgXUg6mpAhK83DhZ+ci5pcppectEzRKekYsFbN5 ZRlSpTQIOwP0+kONMfx3NRGw7bH1KXEFFVwxOh2FGxTVe0lp4k9jq8r15QYYogI6tWSr PMXw== X-Forwarded-Encrypted: i=1; AFNElJ9n8UrTCGcGJPnepyN5jYnVwQvSk6mY1ZNSjGB30LU3LmSR4q7PeMSta5BtbHNLrR9u/GQmBTtKvMeoado=@vger.kernel.org X-Gm-Message-State: AOJu0YwC9lyhtQDQdWDXsyajIsR19Ot0DnIjKMIE9bUNm6vQVJzFLvlq KhA4Cm35XBgsxBLgobYKRjNHXkhgfiHAC+2kGSMjyf+3Xkbwk6H8+mdL X-Gm-Gg: Acq92OFGr1YrPCajQ1VQfTF4LJXOAAywCW3/GC3Vm+bwyQppWGTgqCU44GgS9GeTfec nayQqbtK+wgPCLxg+SNA1cFwAEwGlRmU11admM5z+GMiZCT2z0RAh/J1wdIC4gDYVih7EvKvUKs j9uCySom8BYbzs8yKMlTWLqS1gls8oHTqKwcUmBf5cJN8oZQLvsdgYC2jcRQzB4pFArPazTn4tk ZsH+4/8ETkr2KwpCSt7CGU0IBo5HTpZyD8Rpnu/g6OJYIkRiJDbixvAwDo60rTipkqM3gkOKyH2 xeXKmoehDaS+yWiCPNLz+xKy5wQK6ol/KBuGL7E6x4JYMtJ+vCFouL0/lD1zDkvXzUTA+UllQTv cVUdI5JUEv7nzNCrv3N+47mjHJR7LA46RaPCZUFolcMaCQ1w9QbVOpNzPMo9IQBbtbUpp47+dQ6 6RC789YPWH/UKO4KK/kV6EULNgibmXqU45 X-Received: by 2002:a17:906:8463:b0:bec:7ab2:9128 with SMTP id a640c23a62f3a-bfe27f0f67fmr170595566b.8.1781316127892; Fri, 12 Jun 2026 19:02:07 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-bfdb83428a8sm169980966b.44.2026.06.12.19.02.05 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Jun 2026 19:02:06 -0700 (PDT) Date: Sat, 13 Jun 2026 02:02:05 +0000 From: Wei Yang To: "David Hildenbrand (Arm)" Cc: Lance Yang , akpm@linux-foundation.org, ljs@kernel.org, ziy@nvidia.com, baolin.wang@linux.alibaba.com, liam@infradead.org, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH mm-unstable 1/1] mm/khugepaged: fix PMD collapse swap PTE accounting Message-ID: <20260613020205.dwdvox5wget4aitz@master> Reply-To: Wei Yang References: <20260609120443.71864-1-lance.yang@linux.dev> <7d081256-5b30-4e3c-b948-85ba76ad0e1d@kernel.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <7d081256-5b30-4e3c-b948-85ba76ad0e1d@kernel.org> User-Agent: NeoMutt/20170113 (1.7.2) On Tue, Jun 09, 2026 at 03:16:10PM +0200, David Hildenbrand (Arm) wrote: >On 6/9/26 14:04, Lance Yang wrote: >> From: Lance Yang >> >> mthp_collapse() uses mthp_present_ptes to decide whether a range has >> enough occupied PTEs to try collapse. Swap PTEs accepted by >> collapse_scan_pmd() are counted in unmapped, but are not represented in >> mthp_present_ptes. >> >> When lower orders are enabled, collapse_scan_pmd() relaxes max_ptes_none >> so the scan can cover the whole PMD and build the bitmap. mthp_collapse() >> then checks the PMD-order candidate using the bitmap. >> >> With max_ptes_none set to 0, a range with 511 present PTEs and one swap >> PTE no longer reaches collapse_huge_page(), even though PMD collapse can >> handle swap PTEs up to max_ptes_swap. >> >> Account unmapped PTEs only for PMD order. PMD collapse supports swap PTEs >> through max_ptes_swap, while lower-order mTHP collapse does not currently >> support non-present PTEs. Keep non-present PTEs out of the lower-order >> eligibility check. >> >> Signed-off-by: Lance Yang >> --- >> Sent separately, as discussed in [1], to spell out the PMD-order swap PTE >> case. Patch [2] is still only in mm-unstable, so no Fixes: tag. >> >> [1] https://lore.kernel.org/linux-mm/CAA1CXcD7WAiA1b9GTLAuNZ+kHaFx0SzZwpBkqAZ=s+RHsTUaow@mail.gmail.com/ >> [2] https://lore.kernel.org/linux-mm/20260605161422.213817-12-npache@redhat.com/ >> >> mm/khugepaged.c | 8 ++++++++ >> 1 file changed, 8 insertions(+) >> >> diff --git a/mm/khugepaged.c b/mm/khugepaged.c >> index b12187709f6d..617bca76db49 100644 >> --- a/mm/khugepaged.c >> +++ b/mm/khugepaged.c >> @@ -1508,6 +1508,14 @@ static enum scan_result mthp_collapse(struct mm_struct *mm, >> nr_occupied_ptes = bitmap_weight_from(cc->mthp_present_ptes, offset, >> offset + nr_ptes); >> >> + /* >> + * Swap PTEs accepted during the scan are counted in @unmapped, >> + * not in the present-PTE bitmap. Account them for the PMD-order >> + * candidate. >> + */ >> + if (is_pmd_order(order)) >> + nr_occupied_ptes += unmapped; >> + > >LGTM, there is a bit of opportunity for cleanup in the future :) > >Acked-by: David Hildenbrand (Arm) > > >For example, as we no longer have the VMA here, collapse_max_ptes_none is >imprecise in uffd VMAs. We might try collapsing where there sure is nothing to >collapse. I mentioned it in [1] too. [1]: https://lore.kernel.org/linux-mm/20260512154431.jxcs632mqqatqtsw@master/ > >We could likely handle the userfaultfd_armed() part easier: some indication that >we must not have any pte_none() would be sufficient. > >Also, I don't see a good reason why uffd would not be allowed to collapse with >zeropages ... it's really just about missing faults due to pte_none(). > >-- >Cheers, > >David -- Wei Yang Help you, Help me