Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2472900rdh; Sun, 29 Oct 2023 18:55:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJyA8sOczedLCs23a+ytm8Eg/+X/8f4ukX52hXWpXpvRNMETlKjtGhpu2SckorTIFxenIs X-Received: by 2002:a25:abb0:0:b0:da0:e250:15ad with SMTP id v45-20020a25abb0000000b00da0e25015admr8160486ybi.30.1698630935314; Sun, 29 Oct 2023 18:55:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698630935; cv=none; d=google.com; s=arc-20160816; b=Rqv628jILEIutxoPm3k4vEQ5geCw4LJa/JG/4RqFYtOxiUp37GewYMCKDREdX6T3KK aQQQ2FjIjWNO8v5Jb6oJBVa+f/YHMfXjAy+LV0EiRMoTx6GQRUV+GMmlC7P1sp+5Y9Fz NJfI3jvnBgCTiz1ZVX/fXJ0CEPWPXkqjdOWoqhJ97ATFUrOtxkJMI66iQReHXbBd9Nb4 mU3dGTeZfkVZhiUjvaYzLY+i4jZXCT3IspMZr8hhUIBvYeCkPdU97c+zT1ANQJJs+g2G X68kEtiujr5VeBI1he0DJv6paDkvl+MIDe59ALxTlGkn0atCzceFDBraTwtLQ6ce2xfX Urgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:dkim-signature; bh=/ZOhQkhSb9mtEzPBRTLdPtqRJ6zBjawZu30hGole3M0=; fh=P9iThq4uyrzMvK/gIqzu/q8jW4Yt6+WkTH2s2ERGWn8=; b=UFIpfxHU5+TxVivQyUzWI+zX/rI9TdXwWFLVluWCxxo8B3X2+maByX1CoZoowWVRBw dFLOKKhqM2a9tzeA0etufOteIHp0oTot8t0wYEQ/JrA1OpIXPb6ApwqHDTwN5WtX62Xv KT2So7dn9FGTIGsbK1fbdq9cknivbVuZzvxM+oYLr9e7vlvvIlm3LKaJ6I8+55cM6dCR UZcCwZqG/M8ss0dpXKRHwgR5+/7VRkK56OewLmdr91/pXVjQrIMnQtV5IId9nMawfRTu phuujRTxSG8jxfnS4Uk75wOgkEss3PWj+jPNLRNBcLw1WC39EVHthGd7qnZkYF457JIi 6nYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RI7IjVXH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id y22-20020a056a00191600b006b8e367ed42si4300502pfi.54.2023.10.29.18.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 18:55:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RI7IjVXH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id C24B88055AF0; Sun, 29 Oct 2023 18:55:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229662AbjJ3BzS (ORCPT + 99 others); Sun, 29 Oct 2023 21:55:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229801AbjJ3BzR (ORCPT ); Sun, 29 Oct 2023 21:55:17 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF8E0BF for ; Sun, 29 Oct 2023 18:55:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698630914; x=1730166914; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=4z9cc4o/HwXQhG6Oi7EH4mIi1M0DulyFnn9b0G5P/MQ=; b=RI7IjVXHe06LTxHTqOYWURzAVrM9QcQGVEYX46pzmbrWWlZdIAFY3nx2 R+7OGPM3GJCKJ3ZXDM2NmMdN6jB4Uvhj0JOk6YhzKSQOD7RF+iNcTwonD dpBnlpai6Ya9tvEoI1CsAndClMZ/2fYWbofxUKbrykudhgVBAn0rQL+JL v7ZNduMvCa23gS7FT05LrVn6yhPb4pOBwkzAdLtzycuIC5+jCuW6Fa5UP evmzGdbT+Jn9Z9FKw2jAtHZ8ypxmw59dOCugHkwmO5w+hChDnMMK/IBfR ip4uIxkEQdJcmbwCZUtbRpgNwGa45UBKUwu1pWlWnlilOCFA8oPQbmUZy w==; X-IronPort-AV: E=McAfee;i="6600,9927,10878"; a="390854918" X-IronPort-AV: E=Sophos;i="6.03,262,1694761200"; d="scan'208";a="390854918" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2023 18:55:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10878"; a="789317352" X-IronPort-AV: E=Sophos;i="6.03,262,1694761200"; d="scan'208";a="789317352" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2023 18:55:12 -0700 From: "Huang, Ying" To: Baolin Wang Cc: , , , Subject: Re: [PATCH] mm: huge_memory: batch tlb flush when splitting a pte-mapped THP In-Reply-To: <431d9fb6823036369dcb1d3b2f63732f01df21a7.1698488264.git.baolin.wang@linux.alibaba.com> (Baolin Wang's message of "Mon, 30 Oct 2023 09:11:47 +0800") References: <431d9fb6823036369dcb1d3b2f63732f01df21a7.1698488264.git.baolin.wang@linux.alibaba.com> Date: Mon, 30 Oct 2023 09:53:10 +0800 Message-ID: <87bkcgev09.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sun, 29 Oct 2023 18:55:33 -0700 (PDT) Baolin Wang writes: > I can observe an obvious tlb flush hotpot when splitting a pte-mapped THP on > my ARM64 server, and the distribution of this hotspot is as follows: > > - 16.85% split_huge_page_to_list > + 7.80% down_write > - 7.49% try_to_migrate > - 7.48% rmap_walk_anon > 7.23% ptep_clear_flush > + 1.52% __split_huge_page > > The reason is that the split_huge_page_to_list() will build migration entries > for each subpage of a pte-mapped Anon THP by try_to_migrate(), or unmap for > file THP, and it will clear and tlb flush for each subpage's pte. Moreover, > the split_huge_page_to_list() will set TTU_SPLIT_HUGE_PMD flag to ensure > the THP is already a pte-mapped THP before splitting it to some normal pages. > > Actually, there is no need to flush tlb for each subpage immediately, instead > we can batch tlb flush for the pte-mapped THP to improve the performance. > > After this patch, we can see the batch tlb flush can improve the latency > obviously when running thpscale. > k6.5-base patched > Amean fault-both-1 1071.17 ( 0.00%) 901.83 * 15.81%* > Amean fault-both-3 2386.08 ( 0.00%) 1865.32 * 21.82%* > Amean fault-both-5 2851.10 ( 0.00%) 2273.84 * 20.25%* > Amean fault-both-7 3679.91 ( 0.00%) 2881.66 * 21.69%* > Amean fault-both-12 5916.66 ( 0.00%) 4369.55 * 26.15%* > Amean fault-both-18 7981.36 ( 0.00%) 6303.57 * 21.02%* > Amean fault-both-24 10950.79 ( 0.00%) 8752.56 * 20.07%* > Amean fault-both-30 14077.35 ( 0.00%) 10170.01 * 27.76%* > Amean fault-both-32 13061.57 ( 0.00%) 11630.08 * 10.96%* > > Signed-off-by: Baolin Wang LGTM, Thanks! Reviewed-by: "Huang, Ying" > --- > mm/huge_memory.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index f31f02472396..0e4c14bf6872 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -2379,7 +2379,7 @@ void vma_adjust_trans_huge(struct vm_area_struct *vma, > static void unmap_folio(struct folio *folio) > { > enum ttu_flags ttu_flags = TTU_RMAP_LOCKED | TTU_SPLIT_HUGE_PMD | > - TTU_SYNC; > + TTU_SYNC | TTU_BATCH_FLUSH; > > VM_BUG_ON_FOLIO(!folio_test_large(folio), folio); > > @@ -2392,6 +2392,8 @@ static void unmap_folio(struct folio *folio) > try_to_migrate(folio, ttu_flags); > else > try_to_unmap(folio, ttu_flags | TTU_IGNORE_MLOCK); > + > + try_to_unmap_flush(); > } > > static void remap_page(struct folio *folio, unsigned long nr)