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 6418C2AF1D for ; Thu, 5 Feb 2026 14:25:36 +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=1770301537; cv=none; b=Qbi8FzCNo5YYwTCEh8Eyrxl59k5S+Aob5Q1LP2SUfXgPhojziBOrKsXyyxmZEM933AWGAQE8u71vEnvC54hWH+2TNXn6/KRsPjzHpVgKsHtn2R/Dhc8x/UXr6DpUkZHyd/TDeOKCgEwvPsN6WjTV1epxtjDdu46EN8g+0uYxqnk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770301537; c=relaxed/simple; bh=09yTAKIMLJX3MbLCONT/iqUJaPKneDPDdQFcKJzvMB0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=iuOVYweJ09zdIgH94jaUKUQW4+6s03yPciL+JRMV9PhDx2qOhXNgOvpG1doHRRIsgVUsKCogmMtNTacJvOPFbiMnVFomaosTtkPjZm8gKvcQ6o/dF12pG7ZjdOG35Jl+XPE+6nE+zKQlzEhQXzs2G4AYcbtihD6n4TobGwZa6qg= 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 DF826339; Thu, 5 Feb 2026 06:25:28 -0800 (PST) Received: from [10.163.132.75] (unknown [10.163.132.75]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E16753F73F; Thu, 5 Feb 2026 06:25:31 -0800 (PST) Message-ID: <9508744b-e5d5-49ef-825f-eef683892541@arm.com> Date: Thu, 5 Feb 2026 19:55:28 +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: "David Hildenbrand (arm)" , Vernon Yang 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> <85e8ded9-a9eb-4663-9c96-93af60006fb6@kernel.org> Content-Language: en-US From: Dev Jain In-Reply-To: <85e8ded9-a9eb-4663-9c96-93af60006fb6@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 05/02/26 5:41 pm, David Hildenbrand (arm) wrote: > On 2/5/26 07:08, 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(). > > Yes! > >> >>> ? >>> >>> 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]. > > Why do we even have to optimize this? :) > > Premature ... ? :) I mean .... we don't, but the alternate is a one liner using max(). The objective is to compute the number of iterations of the for-loop. It just seems weird to me to track that in the loop, when we have the loop iterator, which *literally* does that only. Anyhow, I won't shout in any case : ) If you deem incrementing in the loop prettier, that's fine.