From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 CBDB21A9F9B for ; Wed, 31 Dec 2025 02:51:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767149478; cv=none; b=MnEtT/T3S6eXnCAWLSaCvH1GfkztCzLnntahYFj3FnJz8Mq4unrCE7aZFoAx3UgsbZiDNS8wIeEUkwqBz7yi2jaAUmFfxs78oIQagqgdJaemfu20GHPBgzEP0j1VzfImIGjqzzZo3XuVTXJVdEzT5AJOeV2HQSccm8g5iqMgyss= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767149478; c=relaxed/simple; bh=RErDidXmWlMMHLZqaC4FkNJ+U0uGAaIJchnG+wXerk0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IoLg+sBJGTGgGo71nryJAZ/owQ/hN1Sc6hfb2blZpwLDhUIGTfQMpQCjLb/J7dv5eKYRJ1TUWcJnXvXFK+FhXg9a/xkErXvydZXHAg41Z/S9w7h2WpjX3+wWbQBWsdHxtBo8EN69f99AjZkfTqWQHu4sIMO3PippVO+KnKZWArQ= 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=KUaqp6XH; arc=none smtp.client-ip=209.85.218.48 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="KUaqp6XH" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-b832522b47cso608615266b.0 for ; Tue, 30 Dec 2025 18:51:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767149474; x=1767754274; 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=EmlhgLzDihwQXJKjPLEsbonM6eB7pTCajPhK6zvZfAY=; b=KUaqp6XHlAIVAtAEc5KCtj5ZvA1f1CEG/IG9n5irwDRLhkv4zGqF/uE0LXE8BHuAPd etC/1Fzper0xg59Y4U1psXn2QQrR6BjuCHjiNTRiILtdLvijnZ31EphZ3NWedfM3NmSo 2dSeLcckdLoduURemSurcD9OtBTKdOLCuSbZ1R3pWxj0fOhTMkD+VPhMY0c194jr1pUI OLlYTI++B75GnOUWtqEBrKMmbWy7m2TUD/niHYA89x7LWfZN8NFmotGpKCpMuiSjj7/3 71Y2UMTBwv3xOacp7hev9f37tb/qRixmfUXWMbtw5sK/lQc9r9OUyB1GoHKECtKaMS8e Q5PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767149474; x=1767754274; 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=EmlhgLzDihwQXJKjPLEsbonM6eB7pTCajPhK6zvZfAY=; b=Xu3BVLLcXtxOhJjLDqMXDliQNLTSTqaG4o/c2Ly/K/s8bVMcBJ+4AVedd3u6gtMGKT pRxFs6q7QVdUlHYrSqLkY/7a60iTdmrQ0CyKh/e3OY7SfShh/I6fbNb/yAt7iq2bibKW 29Uou+L2DpdIkXIjt+O3jyUPMxvhwRiBAGNyC6Z4bLVDqheyE21/ckYae24RMeceBeeC f3xupGXQcQRnofphGYp2k/EDYs2sG0ByetEyXmkD4YYzWb9Sb0Op6d45z1U8B5rUWmuf JdHBDPL6ucljNcQwhKYrq32t69ELADcf+FK6aVDvhW4mowomTMwoBi2q1ZsZXABkxpQm yAxg== X-Forwarded-Encrypted: i=1; AJvYcCUkxlVjC3skVqX8YNPp+SAFo5Hh3nsK93DPLT8yasERjRkZHdq6msP4De4TUqQKOg0tQseebCuFN03spV4=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+lEjUxA8CK8AnF8f765YnmL0SQnl2fm0seABwOH4wttgf3ZbL qoadN/bSLa6GZXSHeAbeLxDCo6IINL2MY6/s4BOJUgdb+iYcotybQIOV X-Gm-Gg: AY/fxX7V4AKZ/HEEIW/akkVNHC1KDGy3B1bh+X55BDr/taJZ7EIitIPLA4VUw2l6DFM Ap1Wc7JjW6xHUPiopBCado1MCNlTTVU/32VuxZZxAjSZ4nsXC9AqTRuoK8zWJFEV3/DbasWfswn WrCH2eH1Mn+Iv4I+lz6XUbSRHa4MfQAWnl0ZrqKXvQGfCXxywV1djSSu9/4ol72IOtulVtLRHJa yZUVXkVJvSUtPgRNv8xO773L//ihzyCH8hgqTUBOe2dPPivIdJ7q6CMLjMr9TtXgbbL00hO4cvQ NVwKCredjXYLWhdBpcdxZPekl6mjj0qUA05PYsDX6Bg5pi0i2aR74ohlwhZ5LYsGdSZIM1dOVwm Vgzdf99/8DKJxZP8bAgLLK/kziZig47O4OqOnzrs6DBmC0L+CWYaXbxX6eEaXR7m6S/oUbCmTuT +eD5PpAm5Ub6sf0uPz2erB X-Google-Smtp-Source: AGHT+IGVcLZdqj6eNaasrn746ipTYI7fDfRCvu0V+Z1Q5bofYsJUvEoTAObsuEDApPDu/anBTFxEKA== X-Received: by 2002:a17:906:5a68:b0:b83:9751:4334 with SMTP id a640c23a62f3a-b839751755fmr285999566b.50.1767149473783; Tue, 30 Dec 2025 18:51:13 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037f511fesm3867530466b.65.2025.12.30.18.51.13 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Dec 2025 18:51:13 -0800 (PST) Date: Wed, 31 Dec 2025 02:51:12 +0000 From: Wei Yang To: "David Hildenbrand (Red Hat)" Cc: Vernon Yang , akpm@linux-foundation.org, lorenzo.stoakes@oracle.com, ziy@nvidia.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, richard.weiyang@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Vernon Yang Subject: Re: [PATCH v2 4/4] mm: khugepaged: set to next mm direct when mm has MMF_DISABLE_THP_COMPLETELY Message-ID: <20251231025112.uzlgrs3dgbyzul2x@master> Reply-To: Wei Yang References: <20251229055151.54887-1-yanglincheng@kylinos.cn> <20251229055151.54887-5-yanglincheng@kylinos.cn> 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 Tue, Dec 30, 2025 at 09:03:23PM +0100, David Hildenbrand (Red Hat) wrote: >On 12/29/25 06:51, Vernon Yang wrote: >> When an mm with the MMF_DISABLE_THP_COMPLETELY flag is detected during >> scanning, directly set khugepaged_scan.mm_slot to the next mm_slot, >> reduce redundant operation. >> >> Signed-off-by: Vernon Yang >> --- >> mm/khugepaged.c | 9 +++++++-- >> 1 file changed, 7 insertions(+), 2 deletions(-) >> >> diff --git a/mm/khugepaged.c b/mm/khugepaged.c >> index 2b3685b195f5..72be87ef384b 100644 >> --- a/mm/khugepaged.c >> +++ b/mm/khugepaged.c >> @@ -2439,6 +2439,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, >> cond_resched(); >> if (unlikely(hpage_collapse_test_exit_or_disable(mm))) { >> + vma = NULL; >> progress++; >> break; >> } > >I don't understand why we need changes at all. > >The code is > > mm = slot->mm; > /* > * Don't wait for semaphore (to avoid long wait times). Just move to > * the next mm on the list. > */ > vma = NULL; > if (unlikely(!mmap_read_trylock(mm))) > goto breakouterloop_mmap_lock; > > progress++; > if (unlikely(hpage_collapse_test_exit_or_disable(mm))) > goto breakouterloop; > > ... > >So we'll go straight to breakouterloop with vma=NULL. > >Do you want to optimize for skipping the MM if the flag gets toggled >while we are scanning that MM? > >Is that really something we should be worrying about? > >Also, why can't we simply do a > >diff --git a/mm/khugepaged.c b/mm/khugepaged.c >index 97d1b2824386f..af8481d4b0f4e 100644 >--- a/mm/khugepaged.c >+++ b/mm/khugepaged.c >@@ -2516,7 +2516,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, > * Release the current mm_slot if this mm is about to die, or > * if we scanned all vmas of this mm. > */ >- if (hpage_collapse_test_exit(mm) || !vma) { >+ if (hpage_collapse_test_exit_or_disable(mm) || !vma) { > /* > * Make sure that if mm_users is reaching zero while > * khugepaged runs here, khugepaged_exit will find > This one looks better. But the sad thing is we can't remove this mm from scan list, since user may toggle this flag later. > >-- >Cheers > >David -- Wei Yang Help you, Help me