Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp193678rbb; Fri, 23 Feb 2024 17:47:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX3+311ZHfFScqBj4szMAGaZvAT5Px+lp3Su5FUi0x1GIGIqnqCDok1c82q4LEnNytcKXTi+NbDkT13Aia9/0PptWDUALpeepxtIYoxmg== X-Google-Smtp-Source: AGHT+IEilRuJcDMGm+0HrkhDVtPwn4uHVblJZ6IqW4gL1oMcvggjfV1mxgL4DxagPfhbl64Bn32a X-Received: by 2002:a05:620a:575a:b0:787:ad31:d3c8 with SMTP id wj26-20020a05620a575a00b00787ad31d3c8mr1376291qkn.29.1708739238464; Fri, 23 Feb 2024 17:47:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708739238; cv=pass; d=google.com; s=arc-20160816; b=bgS62P4ddm3Zb3EmSW4wd2dTNe57MX5Ywws9FbCTnNjP+wH9fOXrQWLJI7yuxuEs3M ALNal8oPvm+lgCoQQwHG6TN7J8qVDwkasDnU86okygrCcDQYayJjvEuBKAWiTWi0oi9c peWSVJaPL4PPKlHmK3anqwEmgzNn2ZoiFOIfVmGsWrwqqdalq6TfVchoZmZLAL92wfK+ mzMGkJOBpTLToM9SKaWpXd/AW0ggeWpnQCrxG5gVzdvT/d6o6QlOWwQ/SubUttQhu8GL OqjLYDLKFgJ4fgiQt0m8WKkxOD37h+e6nEEQBqd0gSGsSeN8wBefDz1bdtPI/IO/1hN2 2QYg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=qkj8iOEXqlkPOJBxGRSAsQOYHNO+Nb1TKrnbkl8DtW8=; fh=3QakHPtr1allQPdk2/T/zLqib6zGbHZlNECE42dVoyk=; b=zfxdUnoWqNpzzf5/GyKPy9RHn60EFb0JWRaJzgglz5qmJYvRMwwtpYgdsTDE8X2L7u 37nYFvP7cxmLcOFA7ih1qRQ16DJ6JUWKHMLdJyhxQanvcjsQhK8xBpi0Txi1grrwy6ao a7hPuFJ3tLFZIu1JTvMlr2pzTFUTv2iTOdlVTPXln193Sm/78SDx5n2QOfn7LpPjcNFX 53d9+doiL0XIpyoAg0c6GnXtdT5oNyhurzIlr2ikS/tI9HcpncYbEHMWUXybktfb+VJ+ NaNMbQ7XRAPU/qzkH35sxcz0NQQtnOIqfredRu0U3TNiu8dZlqgh+dQhTHGX+njYh8Jy zqAg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KBwhNIaF; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-79428-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79428-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m3-20020a05620a24c300b007873af4a4e7si178222qkn.764.2024.02.23.17.47.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 17:47:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79428-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=@gmail.com header.s=20230601 header.b=KBwhNIaF; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-79428-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79428-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 3B7771C23ACB for ; Sat, 24 Feb 2024 01:47:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB486C15B; Sat, 24 Feb 2024 01:47:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KBwhNIaF" Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 A2576C122 for ; Sat, 24 Feb 2024 01:47:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708739235; cv=none; b=HaslJO+zZzlHostsv0O36RWbZveh7xB/H8We3GZHmisx2nbj/Dsa0dTv/ImWHF6YmU/+JpVmyQ68S1HHOeTQ60/NwGXENWDClBsOWeeuRrDPiZVo7lx0ln13cBW8lFygBgmFjLUktHIkuGJGSewOJ973sK2FB9iw2OTb8EMc2No= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708739235; c=relaxed/simple; bh=vFpzgojmUbe9cDCthy2dUr66zBP2Jp8OIks+itwmIvk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=OpKff5D3mFSRXtvlq+1s69H0AMIbL6wKX0CeA89TYbCSypBUQleXqUG2ugjSZhk2cduJDPixvwcsHc10+AOjBr7Kj7VPYhqkql6gCvaZMkemcScU5ijGcFWNz/+SN3a24tGkPF1lrgPSYv54j247+nOSwNAPvIQdHbmvpjCcs5Q= 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=KBwhNIaF; arc=none smtp.client-ip=209.85.215.180 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 Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso1276726a12.3 for ; Fri, 23 Feb 2024 17:47:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708739233; x=1709344033; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=qkj8iOEXqlkPOJBxGRSAsQOYHNO+Nb1TKrnbkl8DtW8=; b=KBwhNIaFn1MgQccK0rj2Da9sg98BGI06ownBvdVtmNTlbqzRHBsY5nMplxLHj1pCwQ p1rHFaqOj9JTTIDBUaiNOml8PYKF+xaF/3u5FqZi/n5yjL5qelHckCOSAw9HQm+WaaAx kA7JpZbMZHkqBF/5N/oC2LeEDGxqyFr4UqU2tTFtGlMMpBVkpY/x/Oi4KlctPAgnHzgL HpkyK/8QIyDVE5myjBbKLxx7PgARLyVPWjSNw+cdyCqKxyfbugkryo9r4kQBpiipz6a+ w1lclmEnGGgBjDPWEZo14agZ/E7bb1+Dy2fFMOo2F3WXxKFVMybkiqJurOLZPGoqkfiu oEuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708739233; x=1709344033; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qkj8iOEXqlkPOJBxGRSAsQOYHNO+Nb1TKrnbkl8DtW8=; b=ABixtZ/4NR8t6FaaXCIe/kauy78kx0xQxam99p/nJCwC6Jvcf5ziObZ4EbMZeIVi2A cZXe31Ny3ZlIapD+zfwHi3za6s/p/W6vUJeb44dKFxAIehLfyG++gb8peYhxmGKVJx+5 8FZMWquz1YncIUfNgCzkk/FVwAHgT35EvAs+p6G+AWej6X6QKMxto+be0f5lBSlDwQhp 8ngJl2gDOo1i/bXVwen0cS1cNAAOtY0+1zjX8CGTV+MX1ReaiPTIAw/fkbRwFD/dMJCF NWujFcOKfL0xPh5LQUAmDEZ+PczApgrMXaA5n5Hrm0DKOqU5xSSjETnUKsmGosOJ5yyX ioRg== X-Forwarded-Encrypted: i=1; AJvYcCU8KkQLcM1C7WPpEA5FLj28z6YoxahmM7wkpJYDcd2+wA2TmQWIwmvv6SEp9lA73d3rOHo+ax6bbnhwJSnpXTT2WwoGRoDYCnYwRDJF X-Gm-Message-State: AOJu0Yzaa919Pfrf2ibNMWMancaajTyh9lwKDn9A9WkWa4pUr2sb7Jm+ Az7Bs3DCbuS6QA6W/TnuvnepoFIEl70bP/To3SBKh0bAKpc7wn3fHeNreFXHL/cc5LLVTxWsECy 0hukD/yQssY976RTM+dFx6Wd8Ioc= X-Received: by 2002:a17:90a:d242:b0:299:4a62:548a with SMTP id o2-20020a17090ad24200b002994a62548amr1690765pjw.34.1708739232891; Fri, 23 Feb 2024 17:47:12 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240129054551.57728-1-ioworker0@gmail.com> <20240222131151.4d24563d58240e76a3b535db@linux-foundation.org> In-Reply-To: <20240222131151.4d24563d58240e76a3b535db@linux-foundation.org> From: Yang Shi Date: Fri, 23 Feb 2024 17:47:01 -0800 Message-ID: Subject: Re: [PATCH 1/1] mm/khugepaged: bypassing unnecessary scans with MMF_DISABLE_THP check To: Andrew Morton 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 22, 2024 at 1:11=E2=80=AFPM Andrew Morton wrote: > > 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. > + Thanks, Andrew. > 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. >