From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 492CB24A046 for ; Wed, 24 Dec 2025 11:51:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766577112; cv=none; b=OxCg4tWs0gg/SZORLccqYHo4reaYncMedHEIsrToPMoUURNcGEwGfQ+4KPQoXbZbp1bqrKCEBsrG05qJ+dgc3ziDwdviBxWmZceroa7OhMjh/kkbqXjl87tNA7hsJ1too9AD7Ag+5Tgb57pMF/W0HIBylOoJwITlka47RhP2+y4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766577112; c=relaxed/simple; bh=WjiqqkClZ1NkQy9y1FU7gbhiTA9g7+pr7BXgr7aQKXk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=X04oZMA2H1C0FQ6YhNILDODY0UTpcv+RCcNz3z9zJ6QREVQ0lfEV9XiZ1Gn0/WEN5EKkWvXs9Cw5US59FTf3A6JPqk9fMBD2k4aCsESsEc3JONS0uFswqcZnXcD9sieh8DO46cie3lPHDPODQBsx8znTqfwxl1EsJB9e9peF1Eo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=bj9MAiPn; arc=none smtp.client-ip=95.215.58.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="bj9MAiPn" Message-ID: <6b408736-978a-4d40-adfc-97819951c3a6@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1766577108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dlj+qYNSD9ArUgWjMNVWYsSJk26ac0eHZulc973xx+A=; b=bj9MAiPnFohtWISNZ7PPoZ7tjLLSaTi0K1CtXYtDt3lvFPDrc6zfS39xupyWiDikLXkSuD k9yJeZSAuLxWBgul5JkeFePrADnjvQAE9q2e43ONFoemonNfka+mQpDGSE10pWT1OgKcih SzzVjy5zSySzckFTYl1o6Tfkz2SCeQo= Date: Wed, 24 Dec 2025 19:51:36 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH V2 2/5] mm/khugepaged: count small VMAs towards scan limit Content-Language: en-US To: Shivank Garg Cc: Zi Yan , Andrew Morton , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Lorenzo Stoakes , David Hildenbrand , Barry Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang References: <20251224111351.41042-4-shivankg@amd.com> <20251224111351.41042-8-shivankg@amd.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: <20251224111351.41042-8-shivankg@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2025/12/24 19:13, Shivank Garg wrote: > The khugepaged_scan_mm_slot() uses a 'progress' counter to limit the > amount of work performed and consists of three components: > 1. Transitioning to a new mm (+1). > 2. Skipping an unsuitable VMA (+1). > 3. Scanning a PMD-sized range (+HPAGE_PMD_NR). > > Consider a 1MB VMA sitting between two 2MB alignment boundaries: > > vma1 vma2 vma3 > +----------+------+----------+ > |2M |1M |2M | > +----------+------+----------+ > ^ ^ > start end > ^ > hstart,hend > > In this case, for vma2: > hstart = round_up(start, HPAGE_PMD_SIZE) -> Next 2MB alignment > hend = round_down(end, HPAGE_PMD_SIZE) -> Prev 2MB alignment > > Currently, since `hend <= hstart`, VMAs that are too small or unaligned > to contain a hugepage are skipped without incrementing 'progress'. > A process containing a large number of such small VMAs will unfairly > consume more CPU cycles before yielding compared to a process with > fewer, larger, or aligned VMAs. > > Fix this by incrementing progress when the `hend <= hstart` condition > is met. > > Additionally, change 'progress' type to `unsigned int` to match both > the 'pages' type and the function return value. > > Suggested-by: Wei Yang > Signed-off-by: Shivank Garg > --- > mm/khugepaged.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 107146f012b1..0b549c3250f9 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -2403,7 +2403,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, > struct mm_slot *slot; > struct mm_struct *mm; > struct vm_area_struct *vma; > - int progress = 0; > + unsigned int progress = 0; > > VM_BUG_ON(!pages); > lockdep_assert_held(&khugepaged_mm_lock); > @@ -2447,7 +2447,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, > } > hstart = round_up(vma->vm_start, HPAGE_PMD_SIZE); > hend = round_down(vma->vm_end, HPAGE_PMD_SIZE); > - if (khugepaged_scan.address > hend) { Maybe add a short comment explaining why we increment progress for small VMAs ;) Something like this: /* Count small VMAs that can't hold a hugepage towards scan limit */ > + if (khugepaged_scan.address > hend || hend <= hstart) { > progress++; > continue; > } Otherwise, looks good to me. Reviewed-by: Lance Yang