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 B56C3C5478C for ; Sat, 24 Feb 2024 01:47:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FDCC6B0074; Fri, 23 Feb 2024 20:47:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4AD6E6B0075; Fri, 23 Feb 2024 20:47:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39D226B007B; Fri, 23 Feb 2024 20:47:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 26B266B0074 for ; Fri, 23 Feb 2024 20:47:16 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E8AB116019D for ; Sat, 24 Feb 2024 01:47:15 +0000 (UTC) X-FDA: 81825009630.23.135229B Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf07.hostedemail.com (Postfix) with ESMTP id 22D0140012 for ; Sat, 24 Feb 2024 01:47:13 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UGoRqrkv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of shy828301@gmail.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=shy828301@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708739234; 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=qkj8iOEXqlkPOJBxGRSAsQOYHNO+Nb1TKrnbkl8DtW8=; b=CxcfTFJG0eImR+fxf05f4LjKwZQ5wjexD4h3kSYI58Io/VO56P910gvTiYhwQ70cVwgfK1 ZOhWdz3FZzy9CAz1Kn3/aJOxC5BI86fe97pSxl0yNI3lccZmlOOEbmgggn57K9o2eJ3S2X SDfjCd+8drBi/3/dWsb3ZpTG/cfK6V4= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UGoRqrkv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of shy828301@gmail.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=shy828301@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708739234; a=rsa-sha256; cv=none; b=Z2oB2fgJKYqLhU/8J1PdI1ZqDvCZKFYnwJAwDmH3QLHF3/1RDlnPaMqEiX42O6hO1GCIEo McmFenSmZYaAQSwkktzaL1sUZdEV7DydzGlsbjo+zby9cKIwi9DquCnRADCjflVobGypKS vLqGzcv5ueuCcYiYY5e4zbmUHe6RrXU= Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-5ce942efda5so1073008a12.2 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=kvack.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=UGoRqrkvhJYAn+gT4A03Fs0fV7QwLWjSSL/NZcJx8TfiKzh8BBjy6Ajoegb25/77VY kh4cy0eBKWxWviQIU1U4u6yOk+1z/8mN6JBDsW9Lwd/WoqBDFIUUPpTuJt2p8pFF3kV8 hs0epKyfBDEzUrE1UVpKem91cyrFD1PfHhv+aexMDBGklWVkFim0hnug/of0BfkGmlZQ su4a7FOeS/x3YR0d2T5z4sUpsrRRf/Ejqmqs+XsvTsF+kslGvdxiN9SXd5hn5P0u27hw Gy4eMrcEwi17nudjwGMwL8uz8a8YzUOcmPERW6HlQlI1nOoEgCOo75cfddXMeaTodrwh 3Avg== 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=CvuhalhliWFKu3CsyLdpxK2JEppFLuQQ48OJcOw++r2U+jUIwonW1m3YQAK8fAPZdJ sjrsbtaw3ovEa+YvM1BOxKlXFuHzm1qdkM7rtvgcPJIr0xM9mp/GXfd9GcOX6/Vq0uvB QnEFU9sRrDqMOguKgFSVXkzC+z90l5Gp+SVrOgj/Za7IExF9GRZt/Kp7moK9KMcIDEuL 0Llnab7S8fqrpncgjE+uEAkdANG0eWDPAw5Y3PaZHSwDjm5ySclv8uDddB+TE/LmwAhY RLrpTCWeD0XFaK28GMxxHuzSNXteM1sNBVeszrSmIBZZFLzQNs5NbASncdkVUvzDBIHn 2lhg== X-Forwarded-Encrypted: i=1; AJvYcCXlbgK/OOvBpE+QSa7qWW+mt3/D+H1ctQ+GpOq09+6DE6TbaNQjThLmyVUCQVVydqLAxY1tyHKKAnIZKNOhJnKQ1Hs= X-Gm-Message-State: AOJu0Yx3qTk6wH9BsHTLPUpuu87J2tx8MJiy98JFowigfxCM+KO2ShIf Q0rmGaE+MfkFs3+iV31Fq0MpkzmCuUjB9m/o6sooYxZshCvqUBMVtMl/cAblpeYtlIOMLAtW9Te 90+iHT0FJv2Npk3DWHJU4RxJv3bQ= X-Google-Smtp-Source: AGHT+IEP7gcCCpQNjrEB28hlDf4J34twTAsEPpYz/mnuIH65dfjWR+Yl75K0kg95K+//RlWFyXjwqXAG9AS0OZ8vnmU= 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) 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 X-Rspamd-Queue-Id: 22D0140012 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 41ce7n3kftq9wyebrn81xsarg1knxxzu X-HE-Tag: 1708739233-639238 X-HE-Meta: U2FsdGVkX18DaTSRtLZJtHDNYOju6e4g7IWgHiDk0pB9zgooxEnkC/G7dD0Jxbdi99ICyMU5fZoW8kQ1OvcWq5Uc//jbdzt/HZqLfVNW+pmJ3QXDZgWeHwU0AHgVyaV/n5mW10qc13rnRt/QkonPmrT/0bJbo4gLN79uJonQDuNoYm7SLMRNiypcUGV+weuX93yUgTDvMvrUamALn8ANU9bqM1QSzp41Yb6Aa6OpHO1lWPveK5eBzQ10EBMG4mHTflHWsbCHhYzMMi1g6B7SYj6ihqVgRpg7fMOttlNvH3zYOl3RCThFtdooh7xkh+Q9M/nQrypMEU3PqP58rBbiPVfj2wUohVXotdMrcBNlt3cw7F2ekwiPSaKvzLlt42hucR2aua2QLesoUBeZvDIz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ham, tests=bogofilter, spamicity=0.000038, 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, 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. >