Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp597003rdb; Thu, 22 Feb 2024 13:12:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVZ89LGDX0t87MSCqzRLUyk7X7s9VVtWhrQ2VHXETn5u/h6founJHLh0fUz7CGcd9zDQXcBU6ZGM1NV6xVyv3SfEn+/UqwJtY8gCGU7sg== X-Google-Smtp-Source: AGHT+IE/MYGi4iTHMgc2R9xFLEEzEq1bovezC1ul9E16kBWAa38Yxecq/xO8l5EMN/QZcDyAETiv X-Received: by 2002:ac8:570e:0:b0:42d:c9e6:4b40 with SMTP id 14-20020ac8570e000000b0042dc9e64b40mr403562qtw.25.1708636362968; Thu, 22 Feb 2024 13:12:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708636362; cv=pass; d=google.com; s=arc-20160816; b=jZfLf5nFqNC+dDKnW2ZnoSjMGDzs6npJnOm4MAbbXqU/GfW1o3sYE8VCmAp1d+Ct1/ QLQMPnXYMi2Q7VSVBUN9nkmzJez7rUeRAVCSGF27TRi1JhG1zLz03m7dViWC4mXAAF3Z FJxJ+RK1iK8BHJOdM59dYQWMdou700HjByRbKoUrj4Rk8/sX1VU3brNtXftB9WrHTD5I 6T7ZYs1Zm7Vjp3c1K+HwTVKfiY2uQUbOxigM+zBJXlfo/Xx5sRAmSF1ySrrX+75dAq9+ YQKqeDPkVK/LNVC94cVAAN503dKl8n5fYoEPr8cWPSKg8kqHRfefvHrGVI59viGDYq+j HRrg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=dCz+26ue1hh55hxWEbpki7V+HOYxyF6lV/YceK3G+7Y=; fh=PuqIOWASU958P47wItTytgvdSY4f8OIU0LlYKrkgzIk=; b=AAKUqj1hdHyyhQFvvW5EXpZsP1d2RQiD9G53+T3ttKJkxjTB5hmisS1uJ5mOzuZCiE rb35EAx8oK9mVbXtsskfMu8It3kNohSfA0Sr8zpU7JnYUcNkRVPmIEFlp5xDQmS3y+yU OfL9Kat+HgwbNhXSbrYCO+uzPdWu9+ycm5V4wH4khPpQ0+6j+sPC16MTdbONxW0GF+Cs nSGSY8xQddhZv4DL1OYqitNFMBuH2Fhc9MH+SrhvOwoUEWUxEkbhI+xCL3DPkTS3G+lD omrvub23I3gBj9RyNriCuJ8DvTFOpCmH/bL7Sr1oF9gvJi57nN1tnVcZNZJ+mKLZiNc2 WUvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=uOCurYCA; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-77372-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77372-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b7-20020ac84f07000000b0042db68d985asi13075084qte.647.2024.02.22.13.12.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:12:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77372-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=uOCurYCA; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-77372-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77372-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id ADA7E1C2274E for ; Thu, 22 Feb 2024 21:12:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6527373F28; Thu, 22 Feb 2024 21:11:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="uOCurYCA" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6EA3D73F14 for ; Thu, 22 Feb 2024 21:11:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708636312; cv=none; b=OnSmvt+h/GXBwbTgR+8XkcZTLv1D3wiUK0lLi+crU9t/GPF2RjJL0O+bzNOqxarEIdsMUz9xvJlprWYwkK5zgfF/cXbAgpfDPv0JtiRdgCfaUTUyjBLswZ4ivBXyD0GJbyl7aimU9dQqlRSYFzScEZALAMrm8G3z8uHl7Ah002g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708636312; c=relaxed/simple; bh=cO5FbUIKoUo6Fi1BzfMozcCS1a1h9addtucmfkKRLD8=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=WpuPrq0qBYXTCog/OedxomdkQOuesR4QHXL6g5y1Z5RGP/6J+tHzDc01O2VxmVliyzpuoKHdx6PTY43TLZpkmS4ZKqoALASduZFEw9JHLhk9KFVyx0q2aJcNOklPtFE7ZRN/4H2kaDfXy99lyXkrRHPRiQ5uMgxkRB2zOfYyd9o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=uOCurYCA; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CF91C433F1; Thu, 22 Feb 2024 21:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1708636312; bh=cO5FbUIKoUo6Fi1BzfMozcCS1a1h9addtucmfkKRLD8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=uOCurYCA3JUZdI59VEhC1RuEHY1LYkqNKjw0wYTsLgfZ7airMIyJSlpmK0cG5wHs+ AKTx147BNNmldjDLlOXpW6eXB9Np2nTLb5tPWYoY+yTOffZTM00LQg32AOeHBLi3q/ 3J2F7unRhZ9oGnhrSzODp+eOjGrHNOWTZR3KikYA= Date: Thu, 22 Feb 2024 13:11:51 -0800 From: Andrew Morton To: Yang Shi Cc: Lance Yang , mhocko@suse.com, zokeefe@google.com, david@redhat.com, songmuchun@bytedance.com, peterx@redhat.com, minchan@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] mm/khugepaged: bypassing unnecessary scans with MMF_DISABLE_THP check Message-Id: <20240222131151.4d24563d58240e76a3b535db@linux-foundation.org> In-Reply-To: References: <20240129054551.57728-1-ioworker0@gmail.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Thu, 22 Feb 2024 12:23:21 -0800 Yang Shi wrote: > > VMA Count | Old | New | Change > > --------------------------------------- > > 50 | 23us | 9us | -60.9% > > 100 | 32us | 9us | -71.9% > > 200 | 44us | 9us | -79.5% > > 400 | 75us | 9us | -88.0% > > 800 | 98us | 9us | -90.8% > > > > IIUC, once the count of VMAs for the process > > exceeds page_to_scan, khugepaged needs to > > wait for scan_sleep_millisecs ms before scanning > > the next process. IMO, unnecessary scans could > > actually be skipped with a very inexpensive > > mm->flags check in this case. > > Thanks for following up on this, can you please capture all the > information in the commit log? I added it. --- a/txt/mm-khugepaged-bypassing-unnecessary-scans-with-mmf_disable_thp-check.txt +++ b/txt/mm-khugepaged-bypassing-unnecessary-scans-with-mmf_disable_thp-check.txt @@ -9,6 +9,24 @@ and the MMF_DISABLE_THP flag is set later, this scanning process becomes unnecessary for that mm and can be skipped to avoid redundant operations, especially in scenarios with a large address space. +On an Intel Core i5 CPU, the time taken by khugepaged to scan the +address space of the process, which has been set with the +MMF_DISABLE_THP flag after being added to the mm_slots list, is as +follows (shorter is better): + +VMA Count | Old | New | Change +--------------------------------------- + 50 | 23us | 9us | -60.9% + 100 | 32us | 9us | -71.9% + 200 | 44us | 9us | -79.5% + 400 | 75us | 9us | -88.0% + 800 | 98us | 9us | -90.8% + +Once the count of VMAs for the process exceeds page_to_scan, khugepaged +needs to wait for scan_sleep_millisecs ms before scanning the next +process. IMO, unnecessary scans could actually be skipped with a very +inexpensive mm->flags check in this case. + This commit introduces a check before each scanning process to test the MMF_DISABLE_THP flag for the given mm; if the flag is set, the scanning process is bypassed, thereby improving the efficiency of khugepaged.