From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3712CC48BF8 for ; Thu, 22 Feb 2024 21:11:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A02A56B0075; Thu, 22 Feb 2024 16:11:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B2B96B007B; Thu, 22 Feb 2024 16:11:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87A706B007D; Thu, 22 Feb 2024 16:11:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 78AC36B0075 for ; Thu, 22 Feb 2024 16:11:55 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1B14F1A0F84 for ; Thu, 22 Feb 2024 21:11:55 +0000 (UTC) X-FDA: 81820686990.26.877BA27 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id 7064680017 for ; Thu, 22 Feb 2024 21:11:53 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=uOCurYCA; dmarc=none; spf=pass (imf30.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708636313; a=rsa-sha256; cv=none; b=pOElf/kXyPnIN0mPvqyBDlLRa1DSzcNWkg3ikZzh6B0FFEgYLEUGW/WLNKW0YTiFdsJcd7 Cbsq0s0+TLPo3zAXFQ8j3zsg3owvm0AKpFJ9w/qhhkQPJ1/fCLf8yHq9H3MHty7MVOjmem G/aL9wSCU5iRqc/a5DJZGaLZ2qbUSUM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=uOCurYCA; dmarc=none; spf=pass (imf30.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708636313; h=from:from:sender: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:dkim-signature; bh=dCz+26ue1hh55hxWEbpki7V+HOYxyF6lV/YceK3G+7Y=; b=qThk9G54MjFBfEJlVvJwRyRRw7GxiMwIhlvuOJu56g8jV5yHDDcgZtoj9yT4P4J5RBcZs9 W9Jb5b/DkntXbwFvfCmj6nLhlFZHiwK4X5xt7dP0DP0p8ujXlDCyTJ/8ps1HCn9h1Bd0tM qUoL+/mo3SzmpG5mvu25NfpnCuKOjg8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 51F3163331; Thu, 22 Feb 2024 21:11:52 +0000 (UTC) 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) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7064680017 X-Stat-Signature: ra64rwbujkdrj5shzoyghsfha59y9tt3 X-HE-Tag: 1708636313-394809 X-HE-Meta: U2FsdGVkX18Rem/Ahe1WOX4Bbe121e+RouuLM88qEap/Ca1m+LdtyfgYzrv7KfecjCaR+f+/FN6I+Zrx+BHuWJUWhbGsoDTSpDw8stbOfdYmUTFz8AtrosAMiSd74CYCCdFdxYeO+3TxqCt08oOp6zBP3eOUA1mHd4rlpSLtv7G4kZ20AxpQvC+kkdjl+SWG+WZIZy/XlLWX7DLmESYisHLR1Hn5pXFQt40txRnLaVIHAyKuJPdlyJ2MlBDH9p29i0zfVFjNsBJl4IXWSehMxVMvvb1n1OpPOtl2WCepel8IqF/aiMsZEx9tWzqEoTWiwaApRnsirkb97fUjlBRTqOGy/X7Oh+WawI4RIkDzI1CFKTPPi1ugVxP9G31FgOLPOI36rcHMhSiIigkUtHF6YoQrVgtutg20UqNJYBDUEZlABnQykrdDzfoOHiuYMB/nj5OopCd9VVesISl+pps2fgS11oMh9V1E725sk8W1L9aw578HXbCX0O5qCcE4GNLAqmESTg7Q7FqihLiVOty91nTA3ChyoTpWalSWY8OL2u4h+IA/PYItyqrTR9z3KdHZRAw8vGX1GrimeFeVeZSDotJoYARk5R7a816DNs76sG8ALW5gK4IS9/xqR+2+Gsq7ZmfWSZCdJ+uWBS7cHhX2VSzHtIMvd2ChY8q4iCwU5ahvxXRWi8If+udzx45O5W7OMLYk4FpWqWA9qSyl+/+9IQS4JaHR4jz+rXHnnzAY12uXBq7z0/z+JxqQo9x8qafaawSDMOoDN+CtGjOwyAuwTh8aIlGefZSGWFoo1hFZKxiOGYNbM7i+17ESFT57BxleplI2UE9xYh9FjJZol/6bAsORLSYFCrhmT17BrnY8My26bCRAt10pwI7xUxK2a4LtP9IzVT7f9+OJWvKwzCKs1j2YELiauwgLsB0rqU3q6tlJou0oF7EFJyimlEc6i/9huzgW7fOh+8pLnzJkXjl l1C8rlH5 eDY7hw6iKxWws6kdbyMiLg1SVynFcCLirZAbPXWoySi2h1sQ+Rr5zYN6qLQYrxIhCiI7FUA7+0APasv4GpKZzZOEW64KXROqbe1F+2+XCdYS4/yPr/BbQ0SCsL1bbbxnpBGmAeR0kSSv1B6Azut4ZE1kJXZ1a238mhrccfehl3DO+ZsVpMD0hCOvmggKcKCrUAZvslGnGf5+23ZvHdug4jySgq193rWxKY1uIYRqFJMRH9nFTrP09e9nOQ0cq6SgGsgdSXnloBLMX1e4fW27qI7cbzvfomc9q/6Y8exUw5HqTYe0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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.