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 540B032E697 for ; Sun, 8 Feb 2026 09:05:24 +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=1770541525; cv=none; b=ZEObL6ElmPxaoGuKreE+XbIm/Rk5rgPaWLzq9hP67pfrzCAWsFo+QAFHk/QPwJoNW58tEQU17lGxFGRDdox7TQfvhcV3AAhzdriabT56F2wyVW1w4EPTE6Qz5EN+z3JVarU98rTfzQQnvnawFGyrtBZ/AcUEovram80O9K/GdeE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770541525; c=relaxed/simple; bh=0sBjHK6um17hcFRf4EY8Sawj0GIbqk+Cca2MqmMASUM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=BzmUeKvzpg/Dh796Z/jp+6dTDwx5o4y4cztmYJ1PCqoCGeS3MLeeCenRVEvmW4Y07BQ32O6rVOw6kBGuVHoka62G7UMN6/O99f/2hK8iLc48jFIMHp4L6yIaPjmyfp05Qx6G88MmEgf9VZiIPrfbyOhQI+yCDh8rBuDkElkT37o= 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 2A319339; Sun, 8 Feb 2026 01:05:11 -0800 (PST) Received: from [10.164.10.250] (unknown [10.164.10.250]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 862A53F740; Sun, 8 Feb 2026 01:05:14 -0800 (PST) Message-ID: <78b9bb1c-21aa-435f-a697-ebbfbe604a5a@arm.com> Date: Sun, 8 Feb 2026 14:35:11 +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> <85e8ded9-a9eb-4663-9c96-93af60006fb6@kernel.org> <9508744b-e5d5-49ef-825f-eef683892541@arm.com> <1a6d8295-e27b-4440-a367-af0432a7af4f@kernel.org> <6zltgzs24wpypzu36ldwgtzilhv2z3ofuu45azp5u45huiwqvj@6jhhp5r24po6> Content-Language: en-US From: Dev Jain In-Reply-To: <6zltgzs24wpypzu36ldwgtzilhv2z3ofuu45azp5u45huiwqvj@6jhhp5r24po6> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 06/02/26 4:42 pm, Vernon Yang wrote: > On Fri, Feb 06, 2026 at 10:02:48AM +0100, David Hildenbrand (Arm) wrote: >> On 2/5/26 15:25, Dev Jain wrote: >>> 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: >>>>> >>>>> I guess, your meaning is "min(_pte - pte + 1, HPAGE_PMD_NR)", not max(). >>>> Yes! >>>> >>>>> >>>>> 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(). >> I'm fine with the max(), but it still seems like adding complexity to >> optimize something that is nowhere prove to really be a problem. > Hi David, Dev, > > I use "*cur_progress += 1" at the beginning of the loop, the compiler > optimize that. Assembly as follows: > > 60c1: 4d 29 ca sub %r9,%r10 // r10 is _pte, r9 is pte, r10 = _pte - pte > 60c4: b8 00 02 00 00 mov $0x200,%eax // eax = HPAGE_PMD_NR > 60c9: 44 89 5c 24 10 mov %r11d,0x10(%rsp) // > 60ce: 49 c1 fa 03 sar $0x3,%r10 // > 60d2: 49 83 c2 01 add $0x1,%r10 // r10 += 1 > 60d6: 49 39 c2 cmp %rax,%r10 // r10 = min(r10, eax) > 60d9: 4c 0f 4f d0 cmovg %rax,%r10 // > 60dd: 44 89 55 00 mov %r10d,0x0(%rbp) // *cur_progress = r10 > > To make the code simpler, Let us use "*cur_progress += 1". Wow! Wasn't expecting that. What's your gcc version? I checked with gcc 11.4.0 (looks pretty old) with both x86 and arm64, and it couldn't optimize. > -- > Thanks, > Vernon