From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9618B33ADBA for ; Thu, 5 Feb 2026 12:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770293285; cv=none; b=Z5UuVu0Kyd1wHsSRi913gpZMVZ46+zSj6DDNXG3uchI0GiZuCZ0YbTHR2+yvRd2FEO4oJ7enUjlYatNNeRF7qrXoQefP9+TOHzSHdtZiWYn1DMIf0SErq7B6haIKtPgdQk9v+1/I4rbDWofVZV1QdRDGUXhXQIwyC4EQ+LxpwZs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770293285; c=relaxed/simple; bh=yfEhnczIS92hlGUjeZ9NqGntjp0oqEsmxXs2FnRwOVA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ty9F5v6iWC3lS4CRcpTq3NyzgG3Xld8YBrF5S3noEPMFpG4R24fFcYBFcO+o2nzfl6Q5V16QPUZF7vwuQiq0CiRSe5kpPqIgturCkkwvNO81/lXOTDV8qADfxsFZsgQYYhWZRFgvsDxT0xOy2tJEySbY4X8ku+1p/yJYAz2dxWc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C2408339; Thu, 5 Feb 2026 04:07:56 -0800 (PST) Received: from [10.164.18.70] (MacBook-Pro.blr.arm.com [10.164.18.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7D68B3F73F; Thu, 5 Feb 2026 04:08:00 -0800 (PST) Message-ID: <4f719bed-89bf-44f3-a1cc-39ddc7c66824@arm.com> Date: Thu, 5 Feb 2026 17:37:57 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH mm-new v6 2/5] mm: khugepaged: refine scan progress number To: Vernon Yang , "David Hildenbrand (arm)" Cc: akpm@linux-foundation.org, lorenzo.stoakes@oracle.com, ziy@nvidia.com, baohua@kernel.org, lance.yang@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Vernon Yang References: <20260201122554.1470071-1-vernon2gm@gmail.com> <20260201122554.1470071-3-vernon2gm@gmail.com> Content-Language: en-US From: Dev Jain In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 05/02/26 11:38 am, Vernon Yang wrote: > On Thu, Feb 5, 2026 at 5:35 AM David Hildenbrand (arm) wrote: >> [...] >> >>> + if (cur_progress) { >>> + if (_pte >= pte + HPAGE_PMD_NR) >>> + *cur_progress = HPAGE_PMD_NR; >>> + else >>> + *cur_progress = _pte - pte + 1; >> *cur_progress = max(_pte - pte + 1, HPAGE_PMD_NR); > I guess, your meaning is "min(_pte - pte + 1, HPAGE_PMD_NR)", not max(). > >> ? >> >> It's still a bit nasty, though. >> >> Can't we just add one at the beginning of the loop and let the compiler >> optimize that? ;) > I'm also worried that the compiler can't optimize this since the body of > the loop is complex, as with Dev's opinion [1]. > > [1] https://lore.kernel.org/linux-mm/7c4b5933-7bbd-4ad7-baef-830304a09485@arm.com > > If you have a strong recommendation for this, please let me know, Thanks! I haven't explicitly checked with assembly, but I am fairly sure this won't get optimized. There are two cases where it could have been optimized: 1) Had the compiler inlined hpage_collapse_scan_pmd 2) Had the compiler done something like if (p) -> foo(), where foo() contains the complete for loop, with the increment else -> bar(), where bar() contains the complete for loop, without the increment Both of which are highly unlikely because of the complexity of the function. > >>> + } >>> pte_unmap_unlock(pte, ptl); >>> if (result == SCAN_SUCCEED) { >>> result = collapse_huge_page(mm, start_addr, referenced, >>> @@ -2286,8 +2301,9 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr, >>> return result; >>> } >>> >>> -static enum scan_result hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr, >>> - struct file *file, pgoff_t start, struct collapse_control *cc) >>> +static enum scan_result hpage_collapse_scan_file(struct mm_struct *mm, >>> + unsigned long addr, struct file *file, pgoff_t start, >>> + unsigned int *cur_progress, struct collapse_control *cc) >>> { >>> struct folio *folio = NULL; >>> struct address_space *mapping = file->f_mapping; >>> @@ -2376,6 +2392,8 @@ static enum scan_result hpage_collapse_scan_file(struct mm_struct *mm, unsigned >>> cond_resched_rcu(); >>> } >>> } >>> + if (cur_progress) >>> + *cur_progress = max(xas.xa_index - start, 1UL); >> I would really just keep it simple here and do a >> >> *cur_progress = HPAGE_PMD_NR; >> >> This stuff is hard to reason about, so I would just leave the file case >> essentially unchanged. >> >> IIRC, it would not affect the numbers you report in the patch description? > Yes, Let's keep it simple, always equal to HPAGE_PMD_NR in file case. > > -- > Thanks, > Vernon