From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 91792340280 for ; Mon, 4 May 2026 08:40:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777884042; cv=none; b=czQ8SCGe/UmNTp8hGkabNvAexVBbAwudveUWThL5QYj9Ak1HTcpQGJ9mBTpi9/o90picqeGep+p0HmMefuYpDDYOuvpbx51jE93nbGYUCdepMSnJSvf8HUZ0P/ExgYIJ5ndFDsGeTrKPY8HseOacMam57UpdrOk61wQOvHyGQ00= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777884042; c=relaxed/simple; bh=AEBp6cqsU2NC/EJ9dpdmJCMK+EBcHnW+AEAVD7H4OKA=; h=Subject:To:Cc:From:Date:Message-ID:MIME-Version:Content-Type; b=qH614QOnmHyrUIxAhsVN14HT05Jz7mZ+QOScxyPCa9VJVK9z79Z63nxSf7i7K9L9BtIIeuBEAmYGBcj60/oIZ2iomViPDffAuL/j3gMFb5c2OWMQdyPLtth3EMuaG3B+jdiEnajgANVTA1AX1QzJGKY0MPkR9i8yFG9VHa/mmDY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=aUjKtnRo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="aUjKtnRo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19E6FC2BCB8; Mon, 4 May 2026 08:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1777884042; bh=AEBp6cqsU2NC/EJ9dpdmJCMK+EBcHnW+AEAVD7H4OKA=; h=Subject:To:Cc:From:Date:From; b=aUjKtnRoZTMXN/TgayI1yERbSiIJ283LNefoJ0xW4hPDcStl6TaonoXEHnKKyLqhV ONxCBai3xkvNAap2VrDKwqr91GUqNro48lEPYAU12oH2ohntZN3uSFnvtXxK50RXDx mXd2uQlZdCtfSLtjTUkyad/ZKNrKd//ga5rTU7+4= Subject: FAILED: patch "[PATCH] mm, swap: speed up hibernation allocation and writeout" failed to apply to 6.18-stable tree To: kasong@tencent.com,akpm@linux-foundation.org,baohua@kernel.org,bhe@redhat.com,chrisl@kernel.org,mail@carstengrohmann.de,nphamcs@gmail.com,shikemeng@huaweicloud.com,stable@vger.kernel.org Cc: From: Date: Mon, 04 May 2026 10:40:40 +0200 Message-ID: <2026050440-judgingly-glandular-5a54@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.18-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y git checkout FETCH_HEAD git cherry-pick -x 396f57b5720024638dbb503f6a4abd988a49d815 # git commit -s git send-email --to '' --in-reply-to '2026050440-judgingly-glandular-5a54@gregkh' --subject-prefix 'PATCH 6.18.y' HEAD^.. Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 396f57b5720024638dbb503f6a4abd988a49d815 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 16 Feb 2026 22:58:02 +0800 Subject: [PATCH] mm, swap: speed up hibernation allocation and writeout Since commit 0ff67f990bd4 ("mm, swap: remove swap slot cache"), hibernation has been using the swap slot slow allocation path for simplification, which turns out might cause regression for some devices because the allocator now rotates clusters too often, leading to slower allocation and more random distribution of data. Fast allocation is not complex, so implement hibernation support as well. Test result with Samsung SSD 830 Series (SATA II, 3.0 Gbps) shows the performance is several times better [1]: 6.19: 324 seconds After this series: 35 seconds Link: https://lkml.kernel.org/r/20260216-hibernate-perf-v4-1-1ba9f0bf1ec9@tencent.com Link: https://lore.kernel.org/linux-mm/8b4bdcfa-ce3f-4e23-839f-31367df7c18f@gmx.de/ [1] Signed-off-by: Kairui Song Fixes: 0ff67f990bd4 ("mm, swap: remove swap slot cache") Reported-by: Carsten Grohmann Closes: https://lore.kernel.org/linux-mm/20260206121151.dea3633d1f0ded7bbf49c22e@linux-foundation.org/ Cc: Baoquan He Cc: Barry Song Cc: Chris Li Cc: Kemeng Shi Cc: Nhat Pham Cc: Signed-off-by: Andrew Morton diff --git a/mm/swapfile.c b/mm/swapfile.c index 94af29d1de88..90132b74d6a0 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1926,8 +1926,9 @@ void swap_put_entries_direct(swp_entry_t entry, int nr) /* Allocate a slot for hibernation */ swp_entry_t swap_alloc_hibernation_slot(int type) { - struct swap_info_struct *si = swap_type_to_info(type); - unsigned long offset; + struct swap_info_struct *pcp_si, *si = swap_type_to_info(type); + unsigned long pcp_offset, offset = SWAP_ENTRY_INVALID; + struct swap_cluster_info *ci; swp_entry_t entry = {0}; if (!si) @@ -1937,11 +1938,21 @@ swp_entry_t swap_alloc_hibernation_slot(int type) if (get_swap_device_info(si)) { if (si->flags & SWP_WRITEOK) { /* - * Grab the local lock to be compliant - * with swap table allocation. + * Try the local cluster first if it matches the device. If + * not, try grab a new cluster and override local cluster. */ local_lock(&percpu_swap_cluster.lock); - offset = cluster_alloc_swap_entry(si, NULL); + pcp_si = this_cpu_read(percpu_swap_cluster.si[0]); + pcp_offset = this_cpu_read(percpu_swap_cluster.offset[0]); + if (pcp_si == si && pcp_offset) { + ci = swap_cluster_lock(si, pcp_offset); + if (cluster_is_usable(ci, 0)) + offset = alloc_swap_scan_cluster(si, ci, NULL, pcp_offset); + else + swap_cluster_unlock(ci); + } + if (!offset) + offset = cluster_alloc_swap_entry(si, NULL); local_unlock(&percpu_swap_cluster.lock); if (offset) entry = swp_entry(si->type, offset);