Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp810630rdb; Thu, 22 Feb 2024 23:59:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXTrDJJsJBaZTR26+9oIuwx/F+MtQmpu6xJBrp38gVepkVZWOqDeOtxhJLT/IRg3dhmjfM3DxL5OqRwjxDLCRyt5KRgkTXWnICPmcyMBw== X-Google-Smtp-Source: AGHT+IGpkCJVLi4neF0HzIxjGAdPVh6kgPtKpFwi+43hYmoTz55DN2gbnh/gdJuQ92tKA9O0gB7w X-Received: by 2002:aa7:d958:0:b0:565:50f8:bad5 with SMTP id l24-20020aa7d958000000b0056550f8bad5mr685013eds.30.1708675169189; Thu, 22 Feb 2024 23:59:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708675169; cv=pass; d=google.com; s=arc-20160816; b=TpixVKOs7te3wfrqpMb6mwksfJdEQcoE07CIhJoR3Ug9O5ef7kJpzBd6KMELXjSI/5 MX8A0vkl09wWQA1oP4TxaRnx/pefxQQTBGATJIQCfOsGwputFZC8G8f4gn090depAkOh 7Z4x6JY6C+E3FrWuI+sSZ4EOt6Cy3X2F7054z70HTYVwXKYludDAXRYM8cSLxbELQT12 Ur7+fCV3YLaVa+tjq8M+lZ0eViV3b/Kzy4oS7BzqfClRIQcvbWum0RL3JE2HZ0xuOCJY H+TIpVqRrWvB7PQZW+itjyY/s4PlAZWHip7SeRib7DJJNXebC39XRWTs78N+xa2eepfj xU5A== 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=G20CYRRkwpc4XiQtt15MXyHAMAhYgyffA964Je/jszk=; fh=1iIXQOVxnSHkufpCFLiNi/0JxUb2dTZkyfwPpbHQwhY=; b=QNrf8IFgVGarNaKY1tvKiQx3lPoJR3eYv2cXfp/D9kI1nA7LjpkA+ukb34EFWvYGcF bJi6UOyZVrQTC0PB2X1pxRbv56NtV/Sf36NXQk1KBMGOneFbodl9mcG+Znx09V33fdr+ q7rc01DtN2W2TalEf+zU12tqUEEwp/lfBW4e0qDdxhMw75e6zz1TgzyPYM/HB106beo5 OPNJkflpsnAVMcnxsDksyhx001RA/4JxNaFIY6RjwZP5VA8/TOyUUWRAkNxM7MN5kKml MlE1nfHao6Na9Dfz5xVsMbb5rYIC3vV6tHKJfE2zTG6h9gOooGkJokIunM341AUgG8z8 zo3g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jlGz9uju; 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-77890-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77890-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u15-20020a50c04f000000b0056388cf32basi5839423edd.229.2024.02.22.23.59.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 23:59:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77890-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jlGz9uju; 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-77890-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77890-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 am.mirrors.kernel.org (Postfix) with ESMTPS id EBAF01F23D47 for ; Fri, 23 Feb 2024 07:59:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A8D61642A; Fri, 23 Feb 2024 07:59:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jlGz9uju" Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) (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 4A29513AED for ; Fri, 23 Feb 2024 07:59:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708675161; cv=none; b=l3Eqo4dRQ9HA7uUlyrJBhoKZSVV8dbgQSsIsgx4czOgDb+Es4lio7JBQD5TjWxkBP/XjmZgiBY5I0lZzGAh8vrmiGUzR/dA1QRRNH6BUw7PxCSnNZ62yAI/HSA+0eqPKv99079p/or6K54ois0F8kLJ9m5Y5+lRZqB+un7W9E80= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708675161; c=relaxed/simple; bh=58pIforKk3pYU+TpwduX/a4NUM9YeG6awVJjgoWgrqQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=jv9dz9SgbhMAvK5jVxFESJz0rzUryxVzrbkdOTJO9OR0+NZiG4b+3ffyxjOo6t8AyIlC/U0UnelW810wTSsQAnU3WZIkCd5//UE2tb/JVKrdsmnMm6S26F5/nIE66eO212wyCBgHWLIHxMMde1tGhlhSQuhtmHL9XZG0GbObS+M= 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=jlGz9uju; arc=none smtp.client-ip=209.85.219.176 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-yb1-f176.google.com with SMTP id 3f1490d57ef6-dc74435c428so77456276.2 for ; Thu, 22 Feb 2024 23:59:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708675159; x=1709279959; 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=G20CYRRkwpc4XiQtt15MXyHAMAhYgyffA964Je/jszk=; b=jlGz9ujuBL0OVwwnb6+1lhy+p2v9dIuN6gO6lSkDB3ayuFGNmntSj8aD9IIhBMOPjX 8lt7MR9kblpE0PMAEsKJuO81zM/YWKLICQ/UywGQgV0oKk6mqaXpzAgKwVnQUMLRHGqQ Ya+0atAznO7JUT2qDR26Rl7geGTHBomY2V2hN844uQC7Ers49QIfnt8EnkQXyW917rCz 0VLEB1s4qumZYUtTJam+NrvoaFh0n1JtbmUrJoedGxbrG6uClQcSn43hlLEHftPCl/dA OB2OolZrk2EJhaORIFMrUZTKJkR6Sxue38LBYM06epbmVJPv4zNUF0W4y8RXOaVfzkfc L7zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708675159; x=1709279959; 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=G20CYRRkwpc4XiQtt15MXyHAMAhYgyffA964Je/jszk=; b=Wne7CGKD3R2j6H8AaP2IajMerGTUkgEKEEb0Rt0CBUIsWb4WyN0wrFi/1o1ykf0yMG XAYYzqY8lDZdjeM7uHrU8WZcVWu8MKVfwi6pHpSGlI08Cfcf6h8WtGBjXs74etmTNXkt NwWgCEvDn5AVu+1SxEMCymu48Uf7EwyzvvHAUhNFdozV7rsyDyIgWjT9EJfJuBmDk4a3 tYDlV6PWLJDs6NMTAPmflskYl2/dW9YBIcMryhppOrB5u3hZ7NRbT7Tuvk7Q4pNSGg15 4SDL3xNQ8oNGaOQ4I8SUiVMkuXaw7di7G+SCP6EzpzD0KdvdbG7rv5ObZD2G66R4i3hB 1YaA== X-Forwarded-Encrypted: i=1; AJvYcCWHTbsts4jxSxyFx4bw7rEc8mb3jtoO8PV/awoRFBdmM249fZMrVnO0gRqIK49/66tgovGx/nT+6MW1hEVbB/dK1PDalBnm+2aNjdMP X-Gm-Message-State: AOJu0YzOd9R5fSPt6ISP+nSc9tAFYRmgf01pUroj8M2DnfCA21CPxjcb YjBXq/oI/Eap+tDFBtosVMsjU1iIOfoagLjUEGTXRd9SOQFX0kIEvjjcHK+yyKIVyfvMRwSBNvA Sv9aDfwVxT5573iuQbErEpl34870= X-Received: by 2002:a05:6902:1b85:b0:dcf:30d9:1d7b with SMTP id ei5-20020a0569021b8500b00dcf30d91d7bmr1453488ybb.45.1708675159252; Thu, 22 Feb 2024 23:59:19 -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: Lance Yang Date: Fri, 23 Feb 2024 15:59:07 +0800 Message-ID: Subject: Re: [PATCH 1/1] mm/khugepaged: bypassing unnecessary scans with MMF_DISABLE_THP check To: Andrew Morton , Yang Shi Cc: 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 Thanks for taking the time to look into this! Thanks, Yang and Andrew! Best, Lance On Fri, Feb 23, 2024 at 5:11=E2=80=AFAM 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. > + > 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. >