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 5D593C2BA15 for ; Wed, 19 Jun 2024 09:32:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C54328D007B; Wed, 19 Jun 2024 05:32:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDC308D007A; Wed, 19 Jun 2024 05:32:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A55D28D007B; Wed, 19 Jun 2024 05:32:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 85CB88D007A for ; Wed, 19 Jun 2024 05:32:05 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1DAC5C05CD for ; Wed, 19 Jun 2024 09:32:05 +0000 (UTC) X-FDA: 82247121810.30.3480C69 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 12054180007 for ; Wed, 19 Jun 2024 09:32:02 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718789519; a=rsa-sha256; cv=none; b=lEwDLfHXDLpxCgDn0yHLHP4Df1S1RFbAWIyxwXZNSDfyhAuxECeOmqygOhUUSWhwYmUGz4 Un5NruTSMxLX07odPPEvxNcDQT4sEbbJeY0B4auOpUuZ95w4tD6b8lxvB2Ge4YA+arcxNM DfFogxjZne6xiTOFdY3KkkoiYp94y4M= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718789519; 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; bh=i91op43v62smANOIRqU+q4Aa+/zudbmKuHA8mJMfR7I=; b=qzxT6SG58ngPfWIqdcnz8YmbhUHafNe5TEiBSEBp8QLEePWcidiHxKY9Zh4nSf869DfSuu XsWTPvIby4pvf4JBiUGzVf8IHWDk/bljy2vohAgMYl/pByn6HCJyQAO73iA1/XXzWIWfTr jpBWrfyHpFPPvsqlEoRXWgVTFZPdMiY= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D2325DA7; Wed, 19 Jun 2024 02:32:26 -0700 (PDT) Received: from [10.1.36.163] (XHFQ2J9959.cambridge.arm.com [10.1.36.163]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 246B53F64C; Wed, 19 Jun 2024 02:32:01 -0700 (PDT) Message-ID: <1f02756f-a753-459b-8e8b-85fbbe5c5126@arm.com> Date: Wed, 19 Jun 2024 10:31:59 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 0/2] mm: swap: mTHP swap allocator base on swap cluster order Content-Language: en-GB To: Chris Li , Andrew Morton Cc: Kairui Song , "Huang, Ying" , Kalesh Singh , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Barry Song References: <20240619-swap-allocator-v3-0-e973a3102444@kernel.org> From: Ryan Roberts In-Reply-To: <20240619-swap-allocator-v3-0-e973a3102444@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: kujaw75bz1an5ob73x4k9u8skofoxou4 X-Rspamd-Queue-Id: 12054180007 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718789522-460270 X-HE-Meta: U2FsdGVkX1+3ObU8a+u36SbG4jZXNNYlYaWfwM4oaZyVY9tg9khnHvQEa2eZsgvinFw5oQh7yDGfQMjVXd/a9EZn6fPway/84UpwUh92h329KPTnedvSaqm5UP/S0g/AIJryWqzkfAtGTOt594F0XsgM3a0QItLxFOeGpVoqQHGdBGc7EbAl52oAfQWrzx96mRqavLybKnJP6R4yOK8jEXBYsjCqdlMXdiqOU4O3h7G8akEhvV330N+NrdWHAU7rn31WM5eOfGeza5v99aTcdeisORbjYTO+yXfdBnD7ouKCm2aHTjCz2tbhG7yefI49OtWGaJMg5vxE5xwMOE7Zf+kdpoXGXebfiHPttq4zd1dtiXyKJYEkEqtQWGgGFhcGXyTJ3G3lysrIS0Y7TbsITQlKQ3U8uLWjLTH41AUV5kIn/etHBj95iFhdVZG8G+otoObyFmoUiah80sU9uBJ6ehGmoxjxXGlc7RUC1X+fZBAgqiJIvx3D3GnA4rsn98Hk8n4c05Un87KdM9TPtgz5r2rNDZrYvb99ZPhQjuHGhM8JzQls4WzqqV6zTY0QGIgaNf6UVYK7qiNJA89sZKzgaW/1rVhX7pCDUndZ8laNuUEWukfXJzDEjrc7HxmfvzmbqzjJZxQqBF+WFUVIzaGGFsK8iojvjUT4TYCVy7lN6CRZH9EQ8rYVPOFcxCKrAsExjeNH2RQaLzBKi3CEjyPdFAT5WDrA/RpFKTogYovD5f8P6fREqVQbkMPY7LfkH9hLSYxlk+X5lMG/IiScy3qclLZnCi+Udox1B/atfstPe3ZOTuLhbjlF9D7YOiRgLOjPr/3Dq0Uc+xgEWGmvm0T6T2M+vyDRmqVoaqPtS8FDAZHCrD6T7i1RWJ1qS7CofJlAWXGUxQLd7LqMkrd4w3YUQUvTzeHYBHGgTCfF/Bg2shad2mQCVJMYTBr97NxSfmea2Jjyvo8wH7gJrwtbXmI gdI8ywNp GaWTuiOrXbW731pjqWPg/nUfgeHYQY3DXd6SSSki/Y2MngOiV5E+HnERQTp/eLUXuhLteW4uLqBzhGB02L1yfAKIY5uuR2dfILrPxS4NcOPdTRMExaaoy+Zt+mzaOe96HHlHxP4Gq9L5WZtOzyDt9HGkSqhgWZ8AeQc+fL6JX5C3a62iAPTHTgR6WTzrT50CqqZ0fWxQ2ZWIzqSA1qZdCSGAZPE6fbZbcDNYj X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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 19/06/2024 10:20, Chris Li wrote: > This is the short term solutiolns "swap cluster order" listed > in my "Swap Abstraction" discussion slice 8 in the recent > LSF/MM conference. > > When commit 845982eb264bc "mm: swap: allow storage of all mTHP > orders" is introduced, it only allocates the mTHP swap entries > from new empty cluster list. It has a fragmentation issue > reported by Barry. > > https://lore.kernel.org/all/CAGsJ_4zAcJkuW016Cfi6wicRr8N9X+GJJhgMQdSMp+Ah+NSgNQ@mail.gmail.com/ > > The reason is that all the empty cluster has been exhausted while > there are planty of free swap entries to in the cluster that is > not 100% free. > > Remember the swap allocation order in the cluster. > Keep track of the per order non full cluster list for later allocation. > > User impact: For users that allocate and free mix order mTHP swapping, > It greatly improves the success rate of the mTHP swap allocation after the > initial phase. > > Barry provides a test program to show the effect: > https://lore.kernel.org/linux-mm/20240615084714.37499-1-21cnbao@gmail.com/ > > Without: > $ mthp-swapout > Iteration 1: swpout inc: 222, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 2: swpout inc: 219, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 3: swpout inc: 222, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 4: swpout inc: 219, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 5: swpout inc: 110, swpout fallback inc: 117, Fallback percentage: 51.54% > Iteration 6: swpout inc: 0, swpout fallback inc: 230, Fallback percentage: 100.00% > Iteration 7: swpout inc: 0, swpout fallback inc: 229, Fallback percentage: 100.00% > Iteration 8: swpout inc: 0, swpout fallback inc: 223, Fallback percentage: 100.00% > Iteration 9: swpout inc: 0, swpout fallback inc: 224, Fallback percentage: 100.00% > Iteration 10: swpout inc: 0, swpout fallback inc: 216, Fallback percentage: 100.00% > Iteration 11: swpout inc: 0, swpout fallback inc: 212, Fallback percentage: 100.00% > Iteration 12: swpout inc: 0, swpout fallback inc: 224, Fallback percentage: 100.00% > Iteration 13: swpout inc: 0, swpout fallback inc: 214, Fallback percentage: 100.00% > > $ mthp-swapout -s > Iteration 1: swpout inc: 222, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 2: swpout inc: 227, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 3: swpout inc: 222, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 4: swpout inc: 224, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 5: swpout inc: 33, swpout fallback inc: 197, Fallback percentage: 85.65% > Iteration 6: swpout inc: 0, swpout fallback inc: 229, Fallback percentage: 100.00% > Iteration 7: swpout inc: 0, swpout fallback inc: 223, Fallback percentage: 100.00% > Iteration 8: swpout inc: 0, swpout fallback inc: 219, Fallback percentage: 100.00% > Iteration 9: swpout inc: 0, swpout fallback inc: 212, Fallback percentage: 100.00% > > With: > $ mthp-swapout > Iteration 1: swpout inc: 222, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 2: swpout inc: 219, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 3: swpout inc: 222, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 4: swpout inc: 219, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 5: swpout inc: 227, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 6: swpout inc: 230, swpout fallback inc: 0, Fallback percentage: 0.00% > ... > Iteration 94: swpout inc: 224, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 95: swpout inc: 221, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 96: swpout inc: 229, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 97: swpout inc: 219, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 98: swpout inc: 222, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 99: swpout inc: 223, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 100: swpout inc: 224, swpout fallback inc: 0, Fallback percentage: 0.00% > > $ mthp-swapout -s > Iteration 1: swpout inc: 222, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 2: swpout inc: 227, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 3: swpout inc: 222, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 4: swpout inc: 224, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 5: swpout inc: 230, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 6: swpout inc: 229, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 7: swpout inc: 223, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 8: swpout inc: 219, swpout fallback inc: 0, Fallback percentage: 0.00% > ... > Iteration 94: swpout inc: 223, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 95: swpout inc: 212, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 96: swpout inc: 220, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 97: swpout inc: 220, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 98: swpout inc: 216, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 99: swpout inc: 223, swpout fallback inc: 0, Fallback percentage: 0.00% > Iteration 100: swpout inc: 225, swpout fallback inc: 0, Fallback percentage: 0.00% Excellent! > > Reported-by: Barry Song <21cnbao@gmail.com> > Signed-off-by: Chris Li > --- > Changes in v3: > - Using V1 as base. > - Rename "next" to "list" for the list field, suggested by Ying. > - Update comment for the locking rules for cluster fields and list, > suggested by Ying. > - Allocate from the nonfull list before attempting free list, suggested > by Kairui. Sorry I didn't follow this original conversation. But the original intent of having a per-cpu current cluster was to prevent interleving pages from multiple processes and therefore optimize IO. See commit ebc2a1a69111 ("swap: make cluster allocation per-cpu"). I wonder if this change could lead to a swap performance regression in the common order-0 case? Thanks, Ryan > - Link to v2: https://lore.kernel.org/r/20240614-swap-allocator-v2-0-2a513b4a7f2f@kernel.org > > Changes in v2: > - Abandoned. > - Link to v1: https://lore.kernel.org/r/20240524-swap-allocator-v1-0-47861b423b26@kernel.org > > --- > Chris Li (2): > mm: swap: swap cluster switch to double link list > mm: swap: mTHP allocate swap entries from nonfull list > > include/linux/swap.h | 30 +++---- > mm/swapfile.c | 248 +++++++++++++++++---------------------------------- > 2 files changed, 95 insertions(+), 183 deletions(-) > --- > base-commit: 19b8422c5bd56fb5e7085995801c6543a98bda1f > change-id: 20240523-swap-allocator-1534c480ece4 > > Best regards,