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 919D6C27C6E for ; Fri, 14 Jun 2024 23:48:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FFA26B010C; Fri, 14 Jun 2024 19:48:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B9AC6B0120; Fri, 14 Jun 2024 19:48:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09DFD6B0128; Fri, 14 Jun 2024 19:48:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DFD5D6B010C for ; Fri, 14 Jun 2024 19:48:16 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 84FE11A0998 for ; Fri, 14 Jun 2024 23:48:16 +0000 (UTC) X-FDA: 82231135392.03.A78AF14 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id DC088140021 for ; Fri, 14 Jun 2024 23:48:14 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=r55ZX3Wn; spf=pass (imf26.hostedemail.com: domain of chrisl@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=chrisl@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718408893; a=rsa-sha256; cv=none; b=vweZN8OGboCIk6yr4Nwdj3dgHrYBkpTJi8UxZE5mSzikQZ+jItbEAeyQxSvnDqsevl+3Im w/vdVBPa91N7fiCgUNS369KTuRtPTZJH4DnF1nwSuLLkuDLop44DRUG2zmBlVRNh/YAk+2 Z4Lbd8YThsR4p2zWnHILo10KUgWQtXU= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=r55ZX3Wn; spf=pass (imf26.hostedemail.com: domain of chrisl@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=chrisl@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718408893; 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: references:dkim-signature; bh=RNUZEroLGCsgwX/+UkP/8XOnUTP9CktqzB4cM/vKslk=; b=YpSeNGjOUDdaT2UKhHHROGe7ml+v72disxaTareExMj5jdUEJiYbEqf5KRVu5BunPBv3wZ N+KZZqpn1Cizq0h/l76tOn4qRHiLBl/4ZV3c7mupkdLddyskKaru4RupNhZ6NP6UiNkkkm M5da5NB/Zqp6MrCzjrt5TDMd+VJUXxE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B5A8362047; Fri, 14 Jun 2024 23:48:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17185C2BD10; Fri, 14 Jun 2024 23:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718408893; bh=7rZ0unu2/SVRtrNWYASpCkCRRJyZVysK1s+WYY0kNN4=; h=From:Subject:Date:To:Cc:From; b=r55ZX3WnPgw2PioxOEVDpxu2C4ufHfovPXKCkdh5qkWsOcbcLhfaPy/AmT3ZYC8wQ yNdArvsz71CUMzj/iLraHfGW+rDJtCYN4UxzgN6ejlJsKgjC/opaar//dpgBeWqboI hl9iPNBCR4XV3/SccizoJ5jkHftRub5y+D7kQXFi00ob139M7DV7uB+7DCWTeGW3gE 3/T7kOY9UQ0IIjKr1pR7WD7BPt+PZT7qgEeA4PR6P5HfJfHpnorWgZZOOMHYGYSZuT 69xjzQoboPiPj/+D9AuN4zGgOzXqeJFLNyfOiJxU3OAfPWKcwt6gHvz2efk36XBZh7 slo3mnfMM77JQ== From: Chris Li Subject: [PATCH v2 0/2] mm: swap: mTHP swap allocator base on swap cluster order Date: Fri, 14 Jun 2024 16:48:06 -0700 Message-Id: <20240614-swap-allocator-v2-0-2a513b4a7f2f@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIALbWbGYC/13MTQrCMBCG4auUWRvJz7QWV72HdJHGsQ2GpCQSl ZK7GwtuXL7DfM8GiaKlBOdmg0jZJht8DXlowCzaz8TstTZILpG3UrH01CvTzgWjHyEy0So02HM yhFBHa6Sbfe3gZay92FTf3rufxff6o/CfyoJxhqe+ExNKNcluuFP05I4hzjCWUj5nyDiUrQAAA A== To: Andrew Morton Cc: Kairui Song , Ryan Roberts , "Huang, Ying" , Kairui Song , Kalesh Singh , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chris Li , Barry Song X-Mailer: b4 0.13.0 X-Stat-Signature: y8yjzbo7t138edc1cxmhzc1qhkz5f7fj X-Rspamd-Queue-Id: DC088140021 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718408894-194328 X-HE-Meta: U2FsdGVkX18KaOHdWJDZL5Oy2Ft40miDmOOgvBH2qAowpJ9cwb74lvTUzd1MP994JbpNJuhfGkSoYyeUokWTZ9svCnNZ4sKBLAPuvUkaRS5RggBvflxAS5HMpJ85NzSH4GW6nvwa43YtreC8V9WsVZZOdQ4MCc/JzRD413y8KrD1Ib5xIPDrIu128VDl/qCzKsEM+59gv2plvjcalzAbBYqNUrpAdxy8+wUJL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Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 mTHP allocation failure rate raises to almost 100% after a few hours in Barry's test run. 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. This greatly improve the sucess rate of the mTHP swap allocation. There is some test number in the V1 thread of this series: https://lore.kernel.org/r/20240524-swap-allocator-v1-0-47861b423b26@kernel.org Reported-by: Barry Song <21cnbao@gmail.com> Signed-off-by: Chris Li --- Changes in v2: - Add the cluster state field to track the different phases of cluster allocations. - Rename "next" to "list" for the list field, suggested by Ying. - Update comment for the locking rules for cluster fields and listi, suggested by Ying. - Nonfull list avoid cluster on the per cpu active cluster. - Allocate from the nonfull list before attempting free list, suggested by Kairui. - 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 | 31 +++--- mm/swapfile.c | 270 ++++++++++++++++++--------------------------------- 2 files changed, 107 insertions(+), 194 deletions(-) --- base-commit: 19b8422c5bd56fb5e7085995801c6543a98bda1f change-id: 20240523-swap-allocator-1534c480ece4 Best regards, -- Chris Li