From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 DFC2E213E7A for ; Sat, 20 Dec 2025 00:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766191135; cv=none; b=jCPk5Ox9sx/P883m0U3ZJIw6j2bVXZf+zgJpZ5ylfN9btcP3Y8ojWZQ7Tjl3zvqqhe8mQE1OvBsBPiz0mXR5zbgRsbZbXpK3w8gsZ11G4aqPUB4zUbdHXe0yAV3B7a+KbDhjCbh7Fy808/PLlott26w+RAHPlBKDGuCj196KNYc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766191135; c=relaxed/simple; bh=eswaSaP3CWqx2hoek8DiKwQajXdjPn1g3D3AAWCCS6U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=J9VUlDaXLuGAt7nd/63kvO8YRoyFgFCYIjhyhdzruO2S4TrY3a/T5cgwt5wAjEy0cShWS4ZidfsjX65JVn1gvxljxYXC0385tvbihqKACoD+UXXYQeIUEtKnjPQmlFG/Zpf+jWdVYjnWYJDZCU+kX03O15wJWP9yNzNYsqfFI2U= 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=mfmVhwWl; arc=none smtp.client-ip=209.85.218.42 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="mfmVhwWl" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-b79f8f7ea43so526150366b.2 for ; Fri, 19 Dec 2025 16:38:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766191132; x=1766795932; 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=+Y3Y0Yx+NCyZ6/DOSVsayIB2ojE39RciO6fXS+6DEgk=; b=mfmVhwWlQIDivFE7hcNjxBmO4eXeMsg2XsncLXjtduc8rPLFFGaAu5z9E8ymW8/Hu2 KshHzIMAR2Yiz6zIKxmHJAnK2T6fps9ZeBECe98fb7QMUke8FYGPEAuTiumJZINrLM6J vc809OpheDPQ/0o9P1AJDXvAYLJCr/SkcPVEUiTCql0K/2OeikMkNyXlp9pH5qpMyegg eOGfZa3Q0udffT4DTgAepJU2ljDPtDKAFvuk+4RtAQ6O86BJdC42koTOZ24NNBF2hM7U Iwubfe7AICwrzsCWvuTIAuB0FvcAS/j8qu3lyNLf55j/75UY6GtclIc44uwvXnEs0YpU hRYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766191132; x=1766795932; 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=+Y3Y0Yx+NCyZ6/DOSVsayIB2ojE39RciO6fXS+6DEgk=; b=NkvomlSjjsqaBCA7l+TqNu2sRvVBaZpU+tapiwQ5tkhM0AAs1UKMgvRlvJXaYmezVm 02B24ufcRQ6ZWvOlG83S3RuSvhUatwlE8MPgHBN120Whrrdcpi4vJ4KSHzN1qo++qquZ G7GkiRUJlhDw+LEpNjzrkQxs5eAZjOCPryJ+Q3Z53FGcYw7rHNQ66ct/pXcJ9HdFIXXi ZCvQajXBj66i7glLCq3Iwktb/QS11immc/9IGgeCXoNNDwLch+sq4KbT7k7qIq5iUxBd GZdSfqQ8b6fhsHqfYs+hsXOAMCy0S+X/ZP3hS2tUark9u/mjB4mxrLdaZf5ptjrs0Q8y vXlQ== X-Forwarded-Encrypted: i=1; AJvYcCXZ+sg1dgigy81uuNW0xepU/QB9lZ9fAg09yT55q6QAKyB5OOYLYla3QhtdpueZcx35HqcbbH83XOxzoC0=@vger.kernel.org X-Gm-Message-State: AOJu0YxdcL+XKY6DalefGOaysQRDvcI23YGvlsOl97KZuqPCGnrYSycs TaWTZ7JC/dJDvDLoCs+hI8QeNzzAzWd1fJFdzNAiAfs0UTp1++siWmR0 X-Gm-Gg: AY/fxX7ULDDzUm0f9CgIVrmtg/yvBGeUiFIyshuwLeEFIQVGJJfcUh0ka4iWbhX9kA0 FZSqXkv5ny4oQC3H3/oL/CMT/Tgy++unfM4zEZ+IQdnSgCzR/3iLfucxa3UpNgeWjE0Cm/45uay h5y9vZEWBIyFhmLHUTqgvnsoWSk/86IjnEZXRu2K+q7NOz2sB/15zcUubPxHwnq6SbRHK+4YMQO Sz0BlR3kLtSj7Xfpxk1zJXw6LH10najg//XRYyVT9XNZsV2UiyCDgjB6ZtX53UV5urMvYIDErHM K88LuuhPP2nPpu4HNLTul57bIQwP9VCwKMytxyF2uxVDMUhM/JIbZyD5lrNqn4qqj3uhQsgNmCM Z5DJjNGAyzHjVoSrq8NivoF8GGmxbJtMIbo6cdxd3PZjEB9NenvGX8u87tTVbKLiMqCL69CNsCs PEviF4gJGDHg== X-Google-Smtp-Source: AGHT+IGMkT3dRU7E8CU6/p5XRm3FX+P7Y1WZkYUD/SbScH7FS0t89FNoNETeJQo4FkXBW5inymANjQ== X-Received: by 2002:a17:907:8e95:b0:b76:7e0e:4246 with SMTP id a640c23a62f3a-b8036ecbbb2mr420395466b.12.1766191131803; Fri, 19 Dec 2025 16:38:51 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037de11dasm349498466b.35.2025.12.19.16.38.51 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Dec 2025 16:38:51 -0800 (PST) Date: Sat, 20 Dec 2025 00:38:51 +0000 From: Wei Yang To: "Garg, Shivank" Cc: Wei Yang , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] mm/khugepaged: remove unnecessary goto 'skip' label Message-ID: <20251220003851.dzsafcxtlbgzwsm6@master> Reply-To: Wei Yang References: <20251216111139.95438-2-shivankg@amd.com> <20251216111139.95438-4-shivankg@amd.com> <20251217024818.ngoime34bxeatqij@master> 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: User-Agent: NeoMutt/20170113 (1.7.2) On Fri, Dec 19, 2025 at 02:54:40PM +0530, Garg, Shivank wrote: > > >On 12/17/2025 8:18 AM, Wei Yang wrote: >> On Tue, Dec 16, 2025 at 11:11:38AM +0000, Shivank Garg wrote: >>> Replace 'goto skip' with actual logic for better code readability. >>> >>> No functional change. >>> >>> Signed-off-by: Shivank Garg >>> --- >>> mm/khugepaged.c | 7 ++++--- >>> 1 file changed, 4 insertions(+), 3 deletions(-) >>> >>> diff --git a/mm/khugepaged.c b/mm/khugepaged.c >>> index 6c8c35d3e0c9..107146f012b1 100644 >>> --- a/mm/khugepaged.c >>> +++ b/mm/khugepaged.c >>> @@ -2442,14 +2442,15 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, >>> break; >>> } >>> if (!thp_vma_allowable_order(vma, vma->vm_flags, TVA_KHUGEPAGED, PMD_ORDER)) { >>> -skip: >>> progress++; >>> continue; >>> } >>> hstart = round_up(vma->vm_start, HPAGE_PMD_SIZE); >>> hend = round_down(vma->vm_end, HPAGE_PMD_SIZE); >>> - if (khugepaged_scan.address > hend) >>> - goto skip; >>> + if (khugepaged_scan.address > hend) { >>> + progress++; >>> + continue; >>> + } >> >> Hi, Shivank >> >> The change here looks good, while I come up with an question. >> >> The @progress here seems record two things: >> >> * number of pages scaned >> * number of vma skipped >> >Three things: number of mm. It's incremented 1 for whole khugepaged_scan_mm_slot(). > Agree. > >> While in very rare case, we may miss to count the second case. >> >> For example, we have following vmas in a process: >> >> vma1 vma2 >> +----------------+------------+ >> |2M |1M | >> +----------------+------------+ >> >> Let's assume vma1 is exactly HPAGE_PMD_SIZE and also HPAGE_PMD_SIZE aligned. >> But vma2 is only half of HPAGE_PMD_SIZE. >> >> When scan finish vma1 and start on vma2, we would have hstart = hend = >> address. So we continue here but would not do real scan, since address == hend. >> >> I am thinking whether this could handle it: >> >> if (khugepaged_scan.address > hend || hend <= hstart) { >> progress++; >> continue; >> } >> >> Do you thinks I am correct on this? > >I think you're correct. >IIUC, @progress acts as rate limiter here. > >It is increasing +1 for whole, and then increases by +1 per VMA (if skipped), >or by +HPAGE_PMD_NR (if actually scanned). > >So, progress ensuring the hugepaged_do_scan run only until (progress >= pages) >at which point it yields and sleeps (wait_event_freezable). > >Without your suggested fix, if a process contains a large number of small VMAs (where >round_up hstart >= round_down(hend), it will unfairly consume more CPU cycles before >yielding compared to a process with fewer or aligned VMAs. You are right. While I am not sure it exists in reality, but in theory it could be. > >I think your suggestion is ensuring fairness by charging 'progress' count correctly. > Thanks for your confirmation. Would you mind add a cleanup in next version, or you prefer me to send it :-) >Thanks, >Shivank -- Wei Yang Help you, Help me