Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1431714lql; Tue, 12 Mar 2024 18:17:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW3dfLhv/dkvi/3uYvTcbebM3MYfg0H8Uu4xqdfFEGp9+X+9g3lykUKmVu2ZEXZIhoHxmaJ7rFbgraVWJWZW7d4WQWuBEDVWYowDPRXcQ== X-Google-Smtp-Source: AGHT+IFWVukRYKsYin4dW88zPStvVsS2YL3UWp5AcSc7USWMCH3NwQyDc7QzogpEY9Go7pG6IYNR X-Received: by 2002:a05:6830:610:b0:6e4:f92f:811d with SMTP id w16-20020a056830061000b006e4f92f811dmr1886144oti.34.1710292654495; Tue, 12 Mar 2024 18:17:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710292654; cv=pass; d=google.com; s=arc-20160816; b=baS5zdbs1U86YribSvrUFjGWjoGx/EQB7sYeFqUr6XsBO8yi0maakP7MnKY0M3SmHX 8X44wUC91NrW/hQ4Li/fvO0PQejq2oy0yIKNy5ihUz/1RDz2AvNLp1cKPWHUFB8Pv9WR DHn593XPByqaO917nE8UwWYsXptWD4SPcVFAh8L3PtIM5WCfd+UG3lHkMElxL9R7iRtZ LFHJ5s3Uta8S0ji/UdJsEicHEP8M/rETZqM4yRIWVZcHLhGgOMZDF9lIzKFyGIqOep9e O3J2b/w8iQT1toB6p6A8q27lwgrxvk+snnTpzX/vRGsZjMXDauVgkDBDmNni2JyuQqRD eu/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:message-id:date:references:in-reply-to:subject:cc:to :from:dkim-signature; bh=+yJ/AFkHp9kESjqXq3yaUeoIjsYNv8q+TugsPsnpgNM=; fh=wfcGb27y55Qic+8hN/vldt97uHFOgVim6iizhmNvH9M=; b=pbAG0ECOg0ANJ0Ct8PT+/54ElkjpzTvR1SXljmyOIt+QDDYg7Ud5DJxJDLLYI8X+in kXHRhcXKHtGTV486BwEBzViK8FQlErtuZIny/D37ivVLLZkvmzdwfRs5C0y3652uSdfP xHfFPOYZOrH+9Q6zFXTzxKtWhmN8tPKvPvIQ4lA/YC2Vmx2uAdcAuxyAB6/9kQjbylJf 2p/i7e0GWgQDkHFNUqOzgN/8M0/WysQhqAyKDBj0tqsFVM35DzE8oYQ6AMuFaKpGA6Jl L7esM3hlXwZYO8vsBH7LKaCCbKlAzaiGXmsJeX8vpUKJQfVZwsh8739XmMiityKD+ior eglQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TU+j76oW; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-100997-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100997-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id de43-20020a05620a372b00b0078836698a50si9663552qkb.106.2024.03.12.18.17.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 18:17:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100997-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TU+j76oW; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-100997-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100997-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 3A1191C232B0 for ; Wed, 13 Mar 2024 01:17:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64948B660; Wed, 13 Mar 2024 01:17:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TU+j76oW" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80DE98BE0 for ; Wed, 13 Mar 2024 01:17:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710292649; cv=none; b=b4kIEVMoTo6/kHZACYN4UtxXP5EnoNXsKPfUhXr3/V328+sGp7j91YFLDbPqnappN6xMZCVCMttTwwf3UFQfoJXc0aO7fPRWCjYVMMzo50EuhHCwUlF1Dvzp/C0BLqYpBy6++oS7+6rdKKR98XA9Pw9Fn5cE9gbPZ7r7gCol30Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710292649; c=relaxed/simple; bh=xEGbOoNHJhjnq2qS3X1dBXqH+R61Z8ym2sUNKikj51A=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=DYvk62Go35ss1rdUz5FM+PS05jPrJ/oY4XT73jv3JUEkwkpXxhkGyy70aNH2BKEwfd6bMhwxzawAlp5NzUGw1NOFYwdMgZnr888LK4TzvFKp6GkqX4Gtd5b6Vgb0zyNAK71uY6DxwLlKQhY9AAEAMBcnIvBUm3ulvXA4EMu8+Sk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=TU+j76oW; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710292647; x=1741828647; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=xEGbOoNHJhjnq2qS3X1dBXqH+R61Z8ym2sUNKikj51A=; b=TU+j76oWktLX19SVo2oRqbFebtP8aKndPe+9EpGS69AeO4E9vg+zb2js ldgNrWZa6+9dXYtOVRJSqRevdxmwWFmb8STMI9xSbIpo9+6GffN0e1Cts 4Zb5OuIDFW6WC5Xi0GHj22C4cy0C1p6tWoo7ugg7ChDThcIa8xgsRp0na ZZt3RzoL5oqKye5rejTa6pojatwLAAZxiaIbmMmPoMnaz9akTlXG48Il7 R5VIDpzpznHbEhg086QaoFiOXF9MDJXkfYpN+xQkM3FTT5QA4nF0TbzIa 8F5NbeHoAf68TFF8voTeC+CQajrFSuzr70/e3os2pJoNUQbP5W+I4HMyv Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11011"; a="4903259" X-IronPort-AV: E=Sophos;i="6.07,119,1708416000"; d="scan'208";a="4903259" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2024 18:17:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,119,1708416000"; d="scan'208";a="11802862" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2024 18:17:23 -0700 From: "Huang, Ying" To: Ryan Roberts Cc: Andrew Morton , David Hildenbrand , Matthew Wilcox , Gao Xiang , Yu Zhao , Yang Shi , Michal Hocko , Kefeng Wang , Barry Song <21cnbao@gmail.com>, Chris Li , , Subject: Re: [PATCH v4 0/6] Swap-out mTHP without splitting In-Reply-To: <2fbc83bf-2e51-40fa-8865-499911ba8102@arm.com> (Ryan Roberts's message of "Tue, 12 Mar 2024 13:56:58 +0000") References: <20240311150058.1122862-1-ryan.roberts@arm.com> <878r2n516c.fsf@yhuang6-desk2.ccr.corp.intel.com> <28914585-80bd-4308-b3aa-dd0dbb2cb201@arm.com> <2fbc83bf-2e51-40fa-8865-499911ba8102@arm.com> Date: Wed, 13 Mar 2024 09:15:28 +0800 Message-ID: <87zfv32aq7.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Ryan Roberts writes: > On 12/03/2024 08:49, Ryan Roberts wrote: >> On 12/03/2024 08:01, Huang, Ying wrote: >>> Ryan Roberts writes: >>> >>>> Hi All, >>>> >>>> This series adds support for swapping out multi-size THP (mTHP) without needing >>>> to first split the large folio via split_huge_page_to_list_to_order(). It >>>> closely follows the approach already used to swap-out PMD-sized THP. >>>> >>>> There are a couple of reasons for swapping out mTHP without splitting: >>>> >>>> - Performance: It is expensive to split a large folio and under extreme memory >>>> pressure some workloads regressed performance when using 64K mTHP vs 4K >>>> small folios because of this extra cost in the swap-out path. This series >>>> not only eliminates the regression but makes it faster to swap out 64K mTHP >>>> vs 4K small folios. >>>> >>>> - Memory fragmentation avoidance: If we can avoid splitting a large folio >>>> memory is less likely to become fragmented, making it easier to re-allocate >>>> a large folio in future. >>>> >>>> - Performance: Enables a separate series [4] to swap-in whole mTHPs, which >>>> means we won't lose the TLB-efficiency benefits of mTHP once the memory has >>>> been through a swap cycle. >>>> >>>> I've done what I thought was the smallest change possible, and as a result, this >>>> approach is only employed when the swap is backed by a non-rotating block device >>>> (just as PMD-sized THP is supported today). Discussion against the RFC concluded >>>> that this is sufficient. >>>> >>>> >>>> Performance Testing >>>> =================== >>>> >>>> I've run some swap performance tests on Ampere Altra VM (arm64) with 8 CPUs. The >>>> VM is set up with a 35G block ram device as the swap device and the test is run >>>> from inside a memcg limited to 40G memory. I've then run `usemem` from >>>> vm-scalability with 70 processes, each allocating and writing 1G of memory. I've >>>> repeated everything 6 times and taken the mean performance improvement relative >>>> to 4K page baseline: >>>> >>>> | alloc size | baseline | + this series | >>>> | | v6.6-rc4+anonfolio | | >>>> |:-----------|--------------------:|--------------------:| >>>> | 4K Page | 0.0% | 1.4% | >>>> | 64K THP | -14.6% | 44.2% | >>>> | 2M THP | 87.4% | 97.7% | >>>> >>>> So with this change, the 64K swap performance goes from a 15% regression to a >>>> 44% improvement. 4K and 2M swap improves slightly too. >>> >>> I don't understand why the performance of 2M THP improves. The swap >>> entry allocation becomes a little slower. Can you provide some >>> perf-profile to root cause it? >> >> I didn't post the stdev, which is quite large (~10%), so that may explain some >> of it: >> >> | kernel | mean_rel | std_rel | >> |:---------|-----------:|----------:| >> | base-4K | 0.0% | 5.5% | >> | base-64K | -14.6% | 3.8% | >> | base-2M | 87.4% | 10.6% | >> | v4-4K | 1.4% | 3.7% | >> | v4-64K | 44.2% | 11.8% | >> | v4-2M | 97.7% | 13.3% | >> >> Regardless, I'll do some perf profiling and post results shortly. > > I did a lot more runs (24 for each config) and meaned them to try to remove the > noise in the measurements. It's now only showing a 4% improvement for 2M. So I > don't think the 2M improvement is real: > > | kernel | mean_rel | std_rel | > |:---------|-----------:|----------:| > | base-4K | 0.0% | 3.2% | > | base-64K | -9.1% | 10.1% | > | base-2M | 88.9% | 6.8% | > | v4-4K | 0.5% | 3.1% | > | v4-64K | 44.7% | 8.3% | > | v4-2M | 93.3% | 7.8% | > > Looking at the perf data, the only thing that sticks out is that a big chunk of > time is spent in during contpte_convert(), called as a result of > try_to_unmap_one(). This is present in both the before and after configs. > > This is an arm64 function to "unfold" contpte mappings. Essentially, the PMD is > being split during shrink_folio_list() with TTU_SPLIT_HUGE_PMD, meaning the > THPs are PTE-mapped in contpte blocks. Then we are unmapping each pte one-by-one > which means the contpte block needs to be unfolded. I think try_to_unmap_one() > could potentially be optimized to batch unmap a contiguously mapped folio and > avoid this unfold. But that would be an independent and separate piece of work. Thanks for more data and detailed explanation. -- Best Regards, Huang, Ying