Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp653718rdb; Tue, 31 Oct 2023 20:10:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEwJjp3iE2zi2gFfog5lvVH2V4cG7G79AIXaWBvvNkqL1GWiiF0qC83IJkf+6S5CEGhq6ZH X-Received: by 2002:a9d:69d9:0:b0:6b9:4516:7d1e with SMTP id v25-20020a9d69d9000000b006b945167d1emr12083769oto.30.1698808214639; Tue, 31 Oct 2023 20:10:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698808214; cv=none; d=google.com; s=arc-20160816; b=ekqEOfxPRByB68Gx0jNoO9ebyMDaUfB74KYUXWQ481wDD1+cRlVcB+qn4pZ8CYdRDh i7cjZWc/g/68wSLlH6SIafkT7UkmLWz2fMGfJHMkZewbvQZ+xO1tpQD7O3Vna2IQvrq2 Gd3PUkG9eyNmNRQ+eveklpJIB9kxeZCE/Uymz9oGXpdYUmNvnkLFrnl9i9JfR/zIskMr qUu4f9qIAY0JoktJGn+rJJdy+5V5XHwMmov4ErEpzW38dlqVPjlfVzzvzDEgWjRb3k11 n/nVjEOgp2NB1TGToA+R6wL7mbcMbUBi/8wUULJoaPz5s4+qosQbAeLeSLACltcCEshf 7x9g== 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=Yi8M41v5JjpwPXkiTOfPEzBFN0Vy7pywHD6+kdsqvIM=; fh=X0Fn7SXR4kpNMCQX7txGNDciPaXyr2yw6IOztvakkzk=; b=y9OTBJB3IrHvWvJ0+IxlfQzbS2ehLqYVgKMZTSvZHpELep7c+VskeBfyjeOikkKVbI JRXt1BW1hAG3v7rQyvjLUCbipITK5IlnOdh2Dwy1w6v26kHh+SlJpTlbQqtCrjHbLdBo 4TXwqNXAn2kpxiPpqGnlakZrEFGSdFNKKQv/wMR7LfWrchMBkj0hxR84X71NKKJISZCm 9o7FhLh1e/NnEaZ9OfPZVWypk7h+i8XXglXitMyHDCgxOnKBrOLjeBrxPBOLz6PK77H/ d00r7nRiJbbnn+aUCBdwQAYA/AKtORUbLp6TthpLHWMxlSJ1zhYPJ0sfYOBev88ITdHm WFLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LXtPBV64; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id s13-20020a056a00194d00b006c0e3332528si722749pfk.30.2023.10.31.20.10.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 20:10:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LXtPBV64; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 1EB948026E39; Tue, 31 Oct 2023 20:10:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231252AbjKADJF (ORCPT + 99 others); Tue, 31 Oct 2023 23:09:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229731AbjKADJE (ORCPT ); Tue, 31 Oct 2023 23:09:04 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD95BA4 for ; Tue, 31 Oct 2023 20:08:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698808138; x=1730344138; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=7oU5zP/ORh3VkaRH+O4IqYYm4jA/RodQFLfi2B7JOSo=; b=LXtPBV64jMXOtPcCud4Jsf8RfQDfawn72srAVe6G4KKP36NpckbZExsf rIDCGAzh0a0uAjBpr0+IZIU2RVZOafqbinmp7mWEmIVJAAw9Y4zbu78Ng P31QPrxWR7TVyJd5ZslIGpQRglK23z1cXnIFoAY9C9rkPx9P20pwLw26l Q5LdLTRZ5fw/Y9Os1zbQIJukDmWfmihrMTFSrN8BUuyjoLrphxlvfYbtY SuIG827MGSqCB27Qy/rLLLssOLqA4VEotMTII7O9OgiiWC57YbZLTEa56 dYKfgh3CSIoRonwgojw/IKWzlvUyz9NylPwvHGNGO1De60+Za3WxiASZC g==; X-IronPort-AV: E=McAfee;i="6600,9927,10880"; a="474664458" X-IronPort-AV: E=Sophos;i="6.03,267,1694761200"; d="scan'208";a="474664458" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 20:08:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10880"; a="884409636" X-IronPort-AV: E=Sophos;i="6.03,267,1694761200"; d="scan'208";a="884409636" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 20:08:53 -0700 From: "Huang, Ying" To: Byungchul Park Cc: David Hildenbrand , , , , , , , , , , , , , , , Subject: Re: [v3 2/3] mm: Defer TLB flush by keeping both src and dst folios at migration In-Reply-To: <20231030095803.GA81877@system.software.com> (Byungchul Park's message of "Mon, 30 Oct 2023 18:58:03 +0900") References: <20231030072540.38631-1-byungchul@sk.com> <20231030072540.38631-3-byungchul@sk.com> <20231030095803.GA81877@system.software.com> Date: Wed, 01 Nov 2023 11:06:51 +0800 Message-ID: <87edha6uk4.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,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Tue, 31 Oct 2023 20:10:09 -0700 (PDT) Byungchul Park writes: > On Mon, Oct 30, 2023 at 09:00:56AM +0100, David Hildenbrand wrote: >> On 30.10.23 08:25, Byungchul Park wrote: >> > Implementation of CONFIG_MIGRC that stands for 'Migration Read Copy'. >> > We always face the migration overhead at either promotion or demotion, >> > while working with tiered memory e.g. CXL memory and found out TLB >> > shootdown is a quite big one that is needed to get rid of if possible. >> > >> > Fortunately, TLB flush can be defered or even skipped if both source and >> > destination of folios during migration are kept until all TLB flushes >> > required will have been done, of course, only if the target PTE entries >> > have read only permission, more precisely speaking, don't have write >> > permission. Otherwise, no doubt the folio might get messed up. >> > >> > To achieve that: >> > >> > 1. For the folios that map only to non-writable TLB entries, prevent >> > TLB flush at migration by keeping both source and destination >> > folios, which will be handled later at a better time. >> > >> > 2. When any non-writable TLB entry changes to writable e.g. through >> > fault handler, give up CONFIG_MIGRC mechanism so as to perform >> > TLB flush required right away. >> > >> > 3. Temporarily stop migrc from working when the system is in very >> > high memory pressure e.g. direct reclaim needed. >> > >> > The measurement result: >> > >> > Architecture - x86_64 >> > QEMU - kvm enabled, host cpu >> > Numa - 2 nodes (16 CPUs 1GB, no CPUs 8GB) >> > Linux Kernel - v6.6-rc5, numa balancing tiering on, demotion enabled >> > Benchmark - XSBench -p 50000000 (-p option makes the runtime longer) >> > >> > run 'perf stat' using events: >> > 1) itlb.itlb_flush >> > 2) tlb_flush.dtlb_thread >> > 3) tlb_flush.stlb_any >> > 4) dTLB-load-misses >> > 5) dTLB-store-misses >> > 6) iTLB-load-misses >> > >> > run 'cat /proc/vmstat' and pick: >> > 1) numa_pages_migrated >> > 2) pgmigrate_success >> > 3) nr_tlb_remote_flush >> > 4) nr_tlb_remote_flush_received >> > 5) nr_tlb_local_flush_all >> > 6) nr_tlb_local_flush_one >> > >> > BEFORE - mainline v6.6-rc5 >> > ------------------------------------------ >> > $ perf stat -a \ >> > -e itlb.itlb_flush \ >> > -e tlb_flush.dtlb_thread \ >> > -e tlb_flush.stlb_any \ >> > -e dTLB-load-misses \ >> > -e dTLB-store-misses \ >> > -e iTLB-load-misses \ >> > ./XSBench -p 50000000 >> > >> > Performance counter stats for 'system wide': >> > >> > 20953405 itlb.itlb_flush >> > 114886593 tlb_flush.dtlb_thread >> > 88267015 tlb_flush.stlb_any >> > 115304095543 dTLB-load-misses >> > 163904743 dTLB-store-misses >> > 608486259 iTLB-load-misses >> > >> > 556.787113849 seconds time elapsed >> > >> > $ cat /proc/vmstat >> > >> > ... >> > numa_pages_migrated 3378748 >> > pgmigrate_success 7720310 >> > nr_tlb_remote_flush 751464 >> > nr_tlb_remote_flush_received 10742115 >> > nr_tlb_local_flush_all 21899 >> > nr_tlb_local_flush_one 740157 >> > ... >> > >> > AFTER - mainline v6.6-rc5 + CONFIG_MIGRC >> > ------------------------------------------ >> > $ perf stat -a \ >> > -e itlb.itlb_flush \ >> > -e tlb_flush.dtlb_thread \ >> > -e tlb_flush.stlb_any \ >> > -e dTLB-load-misses \ >> > -e dTLB-store-misses \ >> > -e iTLB-load-misses \ >> > ./XSBench -p 50000000 >> > >> > Performance counter stats for 'system wide': >> > >> > 4353555 itlb.itlb_flush >> > 72482780 tlb_flush.dtlb_thread >> > 68226458 tlb_flush.stlb_any >> > 114331610808 dTLB-load-misses >> > 116084771 dTLB-store-misses >> > 377180518 iTLB-load-misses >> > >> > 552.667718220 seconds time elapsed >> > >> > $ cat /proc/vmstat >> > >> >> So, an improvement of 0.74% ? How stable are the results? Serious question: > > I'm getting very stable result. > >> worth the churn? > > Yes, ultimately the time wise improvement should be observed. However, > I've been focusing on the numbers of TLB flushes and TLB misses because > better result in terms of total time will be followed depending on the > test condition. We can see the result if we test with a system that: > > 1. has more CPUs that would induce a crazy number of IPIs. FYI, the TLB flushing IPI number reduces much with commit 7e12beb8ca2a ("migrate_pages: batch flushing TLB") if multiple pages are migrated together. -- Best Regards, Huang, Ying > 2. has slow memories that makes TLB miss overhead bigger. > 3. runs workloads that is harmful at TLB miss and IPI storm. > 4. runs workloads that causes heavier numa migrations. > 5. runs workloads that has a lot of read only permission mappings. > 6. and so on. > > I will share the results once I manage to meet the conditions. > > By the way, I should've added IPI reduction because it also has super > big delta :) > >> Or did I get the numbers wrong? >> >> > #define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages) >> > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h >> > index 5c02720c53a5..1ca2ac91aa14 100644 >> > --- a/include/linux/page-flags.h >> > +++ b/include/linux/page-flags.h >> > @@ -135,6 +135,9 @@ enum pageflags { >> > #ifdef CONFIG_ARCH_USES_PG_ARCH_X >> > PG_arch_2, >> > PG_arch_3, >> > +#endif >> > +#ifdef CONFIG_MIGRC >> > + PG_migrc, /* Page has its copy under migrc's control */ >> > #endif >> > __NR_PAGEFLAGS, >> > @@ -589,6 +592,10 @@ TESTCLEARFLAG(Young, young, PF_ANY) >> > PAGEFLAG(Idle, idle, PF_ANY) >> > #endif >> > +#ifdef CONFIG_MIGRC >> > +PAGEFLAG(Migrc, migrc, PF_ANY) >> > +#endif >> >> I assume you know this: new pageflags are frowned upon. > > Sorry for that. I really didn't want to add a new headache. > > Byungchul