From patchwork Tue Dec 24 14:38:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13920191 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 2E059E77188 for ; Tue, 24 Dec 2024 14:39:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C9EF6B008C; Tue, 24 Dec 2024 09:39:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 829626B0092; Tue, 24 Dec 2024 09:39:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 654986B0093; Tue, 24 Dec 2024 09:39:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 38A616B008C for ; Tue, 24 Dec 2024 09:39:45 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6D3308165A for ; Tue, 24 Dec 2024 14:39:44 +0000 (UTC) X-FDA: 82930110312.24.FA6D5BD Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf05.hostedemail.com (Postfix) with ESMTP id 39E1F100012 for ; Tue, 24 Dec 2024 14:38:27 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bQo89+zx; spf=pass (imf05.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1735051137; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7vSxPva/IzAffauQhXhMBUxAGj3ydaL87rJATVq3axg=; b=6ruF/ySyhTLM8npKPlMtMdqM/Pdrn5Xh694UAPWLbQcpViTy8x9pGs0cuRSG+vKgpA9jNs DtRyjyhrWw1RkiKgi9ooNzTd+DxnfP6Bpmk4G2QAFY6ttELSc6JNb3dKZjQ5UfoQv7ayFw ZIaOSW19uyqnyehYyVsnVufgRLjUpCo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735051137; a=rsa-sha256; cv=none; b=N0PrXmJqLkS+0cqvAMsBAPkg/vtCqkfMrXzbweuGWttEC32ssuRbcrkVjZhIOTJvaZPJK1 fHCz+lcOlx7Vpt8Is8EfxKUNpfVjDLEzsTOyd0W8HTfsdDBdCK6IVEQRKGAXG+IM/RZ71p BURW8Tfl1quXiGAWaB/+qk9Bqttsz+w= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bQo89+zx; spf=pass (imf05.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-21683192bf9so58662175ad.3 for ; Tue, 24 Dec 2024 06:39:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735051181; x=1735655981; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=7vSxPva/IzAffauQhXhMBUxAGj3ydaL87rJATVq3axg=; b=bQo89+zx3pZJlSlz6j7WigyLbeDpYD1uGNcec/G7Du0czDHL7BCg43i9g31tEu5Aqz DssEWyZppF7jxZ+xbwA46jRyGAGQQCkR4a7fIFX/fPd7/z/KSW0uhsgfH8HFcsyzz9vt qkVnb4XyBqxSODLB0FnXsUOxSxOdHTtLcdrPinIBEeOoV7vI15cyWkQzVMXHwAnboaMJ wvXfsdMF+redtVzvH/MfonF9NFLZne6rOHG+iML3YQjcvuwUI4Ppnrb2GE4K8fRw6q3k thvfEe0bDpEzWNDZ4pvArasL4thGtq1gwTmFzKCs4rpsiNXL/9h2x+B/ObZy2pOxe0k3 mDrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735051181; x=1735655981; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=7vSxPva/IzAffauQhXhMBUxAGj3ydaL87rJATVq3axg=; b=cNPbDlZALNoe6Ok4pobdezJRBWVtjrxhaT9BFh63iyGkJ8+bS+j+9otXKUVzFZ199j MCiEHnii+X/70GdML853iNhpooS1bvH+9KBAYaQOKYzm6NmNZYDGusPhx5IzLCjUzniL EQ57GDphETXNaRFs2Goul3SZdPCvZif7TAyUPOPw+0uLqDc6UbflhfzYNxdPvfTf6uKp rAJHnzE4UsBpQXtPz+x2pjPxuPrzPxX4bZqCuaOqdKkqtf/e5CxFZB6G1JtLuFLowPbE JH39OhwDy9oKWUGYUXq9fV12fOOMhWuiEuKutjM6vKiWyS53lDOqPK9aTsYYJkseev0j vdnw== X-Gm-Message-State: AOJu0YyofEQVLL7LELAtooms5314paSHKBUQFqJW3SaDhqPNfK+Sspt/ 1Q4kvc0amBlFm+Nu+N3i/VK1XSDQaHkVz58kIo60+bPEv0BVFW/AVIBY0T381Ow= X-Gm-Gg: ASbGncuvlDQGdNF5MmGvAQllf7G4J33acb9SjICZFfbcpmz0WG8zEPFOPan81M4gO5y QGaYgjC3aB8EJbxFLlDRTkJT03F6Oxuf/66vJf2s9FnBNa5r5esDbqCSqt+/vf6JLXzuSPm+ZHW /JAmENHGnKF/bNmIjsK+BbWASpLzoQCLPmAB7XxnCPIPUM6IZxIRoQ4YUKUlhx4oPU6sMiWPuV6 0A+c7pUKLEJ54uuzXFD1Je5uUg24dzCK6Yt+cBRmYZk1O99Y7d9D655B0mTzj2bm/NPc6cg/Sab jA== X-Google-Smtp-Source: AGHT+IFUIbkJj2uiK0mi+sirzvJ+kxdlR40mR42wJ1gQTLR/qHCcG61l6wFzaFQioRKEUmA2LCan7A== X-Received: by 2002:a17:903:2442:b0:211:7156:4283 with SMTP id d9443c01a7336-219e70c0085mr249317255ad.43.1735051180901; Tue, 24 Dec 2024 06:39:40 -0800 (PST) Received: from KASONG-MC4.tencent.com ([115.171.41.189]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9cdec1sm90598735ad.136.2024.12.24.06.39.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 24 Dec 2024 06:39:40 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Chris Li , Barry Song , Ryan Roberts , Hugh Dickins , Yosry Ahmed , "Huang, Ying" , Nhat Pham , Johannes Weiner , Kalesh Singh , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v2 03/13] mm, swap: remove old allocation path for HDD Date: Tue, 24 Dec 2024 22:38:01 +0800 Message-ID: <20241224143811.33462-4-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241224143811.33462-1-ryncsn@gmail.com> References: <20241224143811.33462-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Queue-Id: 39E1F100012 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: gnjgyuyc4y4haso74idiqp66m1bz91hj X-HE-Tag: 1735051107-375251 X-HE-Meta: U2FsdGVkX18tfdTM/LbMlQlWHE3+wCqf9dLfwkvQfennTCnVVf/KBOWU1IZDj6C682GaS17DqXMMJUB3HtpO1Alwvez8EZTplP3ZAhF6StW6eRx9cU2YJzSMkpYUR8dEVL7JiX8V82LFwnZCwAmqcVcSGpNnvc4+csBwLy5/QmkTGoqYU0jwWraD5vOA35kt7s6BAsYYIfdRcivKQ1dMvvjFXkvuwqkKBpdYz4OqWk6DuzO8sdOiJEQV2UXQcJPq4fNncLiqtUWFFRqCuE5X9DPvZbtaDkzjR1ywr1xydAU36kmEvpmdLDSakOnX3E1362D5lbpBLR9GvdRZm/Pfj+wAPCHFCHoAs8O9pwITvfU1QD3hN38gc6V1EkEXGW22EOiTnB5pwvDFSX15g3lEdyQnB8pOx2YHvqOqwvPy0xyvo56mc/T7paBoAOJhbWLHkLzdAzM2IB7X5efh+1cSTF21Wnt7D77aVFnYnyEUAkEn5e0F5OO/zUL1r4s34VqpqguZnJhzyhW1WB5a9bWVwBPCtxCgllTYut/PbV9IoYHI2OsVRACKGM2tnAwDQPlKhJvFQxpHylJ6DSdSqQ4GTRQmvsIZwcjxWeJzRKQwSG186g1i2fbFlhY+b2MbXcdFQG2lhOICwnX1v2o0Nvi09/fhJAqC2WQiGWi+IYakGhspCWQxYQuYbD4DiloGDycpv/iC62o9E8t30LMY5UHGRrmqgUeERO3gkvb0t4C5QyqFAmfHnxWlyJ0K0hzJUR9d8/+es1OKYCx/92XpZk2xdKxVkrQ1TatY09h3H5T3c1TaLBRadTtxcEaFTRyJCbj700m++fF87oRmWaFbRtO/4jM7hY8JKgRDWG+GyhSvt3wsYlk8t77r0ImHgEsz94xz3TvrIQCnPN0xtLpBmqoiLv7iauMTE6XG+E+1jEnk8NUUnvgyqewS1Y1/f2aFJMQcB6Vil/ZGazGkonR5JHq u5Ah355v 43QjdGKS2s2ACUKa3zDeB3dd0AP2VQm8JVAmchu5M26xK1mAq19/wMljLLSnXtYkwnBSorvzMBIkqV9sNdpzNS+ChIF8IHidhwGmH1AKQSFz8nGPEu6Eo9240BlfsDpIZNL1uBMnGSeu29e6Dq39FmDTBh3BFK76csA9vgJ3x2Bf8CPrWv6wXQGKbzWdoLnvRIpKAbluiifNPmmGwUQyQlrOX11oAfUgZnec626OIGwnjO7zP2TL2DTLElJPY1Rnh/Uo/xdDmpAqNYTzT8z3hItZxW9hnPST3aJHkPcHiO6f4Fq1d3vuo9TIQ/NuKXghzN/CwYblkV/EC3fvKPTAMYTQHF9m3l3yezpYqhfcTguDqs1SUvdhux9WxKEJtXb662hiGkc5mSSdnKFfbv/8DqOYskjoVm2b97awfsqQ/P1QpXbrrsum0ta3wME8dpP10N8oDzLLuWBNMK0Pt//ff0MZwd6iRLyUDu2Fr0dGEipzyxD09Oll6P8SpU75rz4B2SzY42l5L1PC6MWwgcUxyPTi2bQpkMluRtCoeGlLMvgcgcMJwjwZa2dO9oYyZQjeveFh8 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: From: Kairui Song We are currently using different swap allocation algorithm for HDD and non-HDD. This leads to the existence of a different set of locks, and the code path is heavily bloated, causing difficulties for further optimization and maintenance. This commit removes all HDD swap allocation and related dead code, and uses the cluster allocation algorithm instead. The performance may drop temporarily, but this should be negligible: The main advantage of the legacy HDD allocation algorithm is that it tends to use continuous slots, but swap device gets fragmented quickly anyway, and the attempt to use continuous slots will fail easily. This commit also enables mTHP swap on HDD, which is expected to be beneficial, and following commits will adapt and optimize the cluster allocator for HDD. Suggested-by: Chris Li Suggested-by: "Huang, Ying" Signed-off-by: Kairui Song --- include/linux/swap.h | 3 - mm/swapfile.c | 235 ++----------------------------------------- 2 files changed, 9 insertions(+), 229 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 187715eec3cb..0c681aa5cb98 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -310,9 +310,6 @@ struct swap_info_struct { unsigned int highest_bit; /* index of last free in swap_map */ unsigned int pages; /* total of usable pages of swap */ unsigned int inuse_pages; /* number of those currently in use */ - unsigned int cluster_next; /* likely index for next allocation */ - unsigned int cluster_nr; /* countdown to next cluster search */ - unsigned int __percpu *cluster_next_cpu; /*percpu index for next allocation */ struct percpu_cluster __percpu *percpu_cluster; /* per cpu's swap location */ struct rb_root swap_extent_root;/* root of the swap extent rbtree */ struct block_device *bdev; /* swap device or bdev of swap file */ diff --git a/mm/swapfile.c b/mm/swapfile.c index 574059158627..fca58d43b836 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1001,49 +1001,6 @@ static void swap_range_free(struct swap_info_struct *si, unsigned long offset, WRITE_ONCE(si->inuse_pages, si->inuse_pages - nr_entries); } -static void set_cluster_next(struct swap_info_struct *si, unsigned long next) -{ - unsigned long prev; - - if (!(si->flags & SWP_SOLIDSTATE)) { - si->cluster_next = next; - return; - } - - prev = this_cpu_read(*si->cluster_next_cpu); - /* - * Cross the swap address space size aligned trunk, choose - * another trunk randomly to avoid lock contention on swap - * address space if possible. - */ - if ((prev >> SWAP_ADDRESS_SPACE_SHIFT) != - (next >> SWAP_ADDRESS_SPACE_SHIFT)) { - /* No free swap slots available */ - if (si->highest_bit <= si->lowest_bit) - return; - next = get_random_u32_inclusive(si->lowest_bit, si->highest_bit); - next = ALIGN_DOWN(next, SWAP_ADDRESS_SPACE_PAGES); - next = max_t(unsigned int, next, si->lowest_bit); - } - this_cpu_write(*si->cluster_next_cpu, next); -} - -static bool swap_offset_available_and_locked(struct swap_info_struct *si, - unsigned long offset) -{ - if (data_race(!si->swap_map[offset])) { - spin_lock(&si->lock); - return true; - } - - if (vm_swap_full() && READ_ONCE(si->swap_map[offset]) == SWAP_HAS_CACHE) { - spin_lock(&si->lock); - return true; - } - - return false; -} - static int cluster_alloc_swap(struct swap_info_struct *si, unsigned char usage, int nr, swp_entry_t slots[], int order) @@ -1071,13 +1028,7 @@ static int scan_swap_map_slots(struct swap_info_struct *si, unsigned char usage, int nr, swp_entry_t slots[], int order) { - unsigned long offset; - unsigned long scan_base; - unsigned long last_in_cluster = 0; - int latency_ration = LATENCY_LIMIT; unsigned int nr_pages = 1 << order; - int n_ret = 0; - bool scanned_many = false; /* * We try to cluster swap pages by allocating them sequentially @@ -1089,7 +1040,6 @@ static int scan_swap_map_slots(struct swap_info_struct *si, * But we do now try to find an empty cluster. -Andrea * And we let swap pages go all over an SSD partition. Hugh */ - if (order > 0) { /* * Should not even be attempting large allocations when huge @@ -1109,158 +1059,7 @@ static int scan_swap_map_slots(struct swap_info_struct *si, return 0; } - if (si->cluster_info) - return cluster_alloc_swap(si, usage, nr, slots, order); - - si->flags += SWP_SCANNING; - - /* For HDD, sequential access is more important. */ - scan_base = si->cluster_next; - offset = scan_base; - - if (unlikely(!si->cluster_nr--)) { - if (si->pages - si->inuse_pages < SWAPFILE_CLUSTER) { - si->cluster_nr = SWAPFILE_CLUSTER - 1; - goto checks; - } - - spin_unlock(&si->lock); - - /* - * If seek is expensive, start searching for new cluster from - * start of partition, to minimize the span of allocated swap. - */ - scan_base = offset = si->lowest_bit; - last_in_cluster = offset + SWAPFILE_CLUSTER - 1; - - /* Locate the first empty (unaligned) cluster */ - for (; last_in_cluster <= READ_ONCE(si->highest_bit); offset++) { - if (si->swap_map[offset]) - last_in_cluster = offset + SWAPFILE_CLUSTER; - else if (offset == last_in_cluster) { - spin_lock(&si->lock); - offset -= SWAPFILE_CLUSTER - 1; - si->cluster_next = offset; - si->cluster_nr = SWAPFILE_CLUSTER - 1; - goto checks; - } - if (unlikely(--latency_ration < 0)) { - cond_resched(); - latency_ration = LATENCY_LIMIT; - } - } - - offset = scan_base; - spin_lock(&si->lock); - si->cluster_nr = SWAPFILE_CLUSTER - 1; - } - -checks: - if (!(si->flags & SWP_WRITEOK)) - goto no_page; - if (!si->highest_bit) - goto no_page; - if (offset > si->highest_bit) - scan_base = offset = si->lowest_bit; - - /* reuse swap entry of cache-only swap if not busy. */ - if (vm_swap_full() && si->swap_map[offset] == SWAP_HAS_CACHE) { - int swap_was_freed; - spin_unlock(&si->lock); - swap_was_freed = __try_to_reclaim_swap(si, offset, TTRS_ANYWAY | TTRS_DIRECT); - spin_lock(&si->lock); - /* entry was freed successfully, try to use this again */ - if (swap_was_freed > 0) - goto checks; - goto scan; /* check next one */ - } - - if (si->swap_map[offset]) { - if (!n_ret) - goto scan; - else - goto done; - } - memset(si->swap_map + offset, usage, nr_pages); - - swap_range_alloc(si, offset, nr_pages); - slots[n_ret++] = swp_entry(si->type, offset); - - /* got enough slots or reach max slots? */ - if ((n_ret == nr) || (offset >= si->highest_bit)) - goto done; - - /* search for next available slot */ - - /* time to take a break? */ - if (unlikely(--latency_ration < 0)) { - if (n_ret) - goto done; - spin_unlock(&si->lock); - cond_resched(); - spin_lock(&si->lock); - latency_ration = LATENCY_LIMIT; - } - - if (si->cluster_nr && !si->swap_map[++offset]) { - /* non-ssd case, still more slots in cluster? */ - --si->cluster_nr; - goto checks; - } - - /* - * Even if there's no free clusters available (fragmented), - * try to scan a little more quickly with lock held unless we - * have scanned too many slots already. - */ - if (!scanned_many) { - unsigned long scan_limit; - - if (offset < scan_base) - scan_limit = scan_base; - else - scan_limit = si->highest_bit; - for (; offset <= scan_limit && --latency_ration > 0; - offset++) { - if (!si->swap_map[offset]) - goto checks; - } - } - -done: - if (order == 0) - set_cluster_next(si, offset + 1); - si->flags -= SWP_SCANNING; - return n_ret; - -scan: - VM_WARN_ON(order > 0); - spin_unlock(&si->lock); - while (++offset <= READ_ONCE(si->highest_bit)) { - if (unlikely(--latency_ration < 0)) { - cond_resched(); - latency_ration = LATENCY_LIMIT; - scanned_many = true; - } - if (swap_offset_available_and_locked(si, offset)) - goto checks; - } - offset = si->lowest_bit; - while (offset < scan_base) { - if (unlikely(--latency_ration < 0)) { - cond_resched(); - latency_ration = LATENCY_LIMIT; - scanned_many = true; - } - if (swap_offset_available_and_locked(si, offset)) - goto checks; - offset++; - } - spin_lock(&si->lock); - -no_page: - si->flags -= SWP_SCANNING; - return n_ret; + return cluster_alloc_swap(si, usage, nr, slots, order); } int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_order) @@ -2871,8 +2670,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) mutex_unlock(&swapon_mutex); free_percpu(p->percpu_cluster); p->percpu_cluster = NULL; - free_percpu(p->cluster_next_cpu); - p->cluster_next_cpu = NULL; vfree(swap_map); kvfree(zeromap); kvfree(cluster_info); @@ -3184,8 +2981,6 @@ static unsigned long read_swap_header(struct swap_info_struct *si, } si->lowest_bit = 1; - si->cluster_next = 1; - si->cluster_nr = 0; maxpages = swapfile_maximum_size; last_page = swap_header->info.last_page; @@ -3271,7 +3066,6 @@ static struct swap_cluster_info *setup_clusters(struct swap_info_struct *si, unsigned long maxpages) { unsigned long nr_clusters = DIV_ROUND_UP(maxpages, SWAPFILE_CLUSTER); - unsigned long col = si->cluster_next / SWAPFILE_CLUSTER % SWAP_CLUSTER_COLS; struct swap_cluster_info *cluster_info; unsigned long i, j, k, idx; int cpu, err = -ENOMEM; @@ -3283,15 +3077,6 @@ static struct swap_cluster_info *setup_clusters(struct swap_info_struct *si, for (i = 0; i < nr_clusters; i++) spin_lock_init(&cluster_info[i].lock); - si->cluster_next_cpu = alloc_percpu(unsigned int); - if (!si->cluster_next_cpu) - goto err_free; - - /* Random start position to help with wear leveling */ - for_each_possible_cpu(cpu) - per_cpu(*si->cluster_next_cpu, cpu) = - get_random_u32_inclusive(1, si->highest_bit); - si->percpu_cluster = alloc_percpu(struct percpu_cluster); if (!si->percpu_cluster) goto err_free; @@ -3333,7 +3118,7 @@ static struct swap_cluster_info *setup_clusters(struct swap_info_struct *si, * sharing same address space. */ for (k = 0; k < SWAP_CLUSTER_COLS; k++) { - j = (k + col) % SWAP_CLUSTER_COLS; + j = k % SWAP_CLUSTER_COLS; for (i = 0; i < DIV_ROUND_UP(nr_clusters, SWAP_CLUSTER_COLS); i++) { struct swap_cluster_info *ci; idx = i * SWAP_CLUSTER_COLS + j; @@ -3483,18 +3268,18 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) if (si->bdev && bdev_nonrot(si->bdev)) { si->flags |= SWP_SOLIDSTATE; - - cluster_info = setup_clusters(si, swap_header, maxpages); - if (IS_ERR(cluster_info)) { - error = PTR_ERR(cluster_info); - cluster_info = NULL; - goto bad_swap_unlock_inode; - } } else { atomic_inc(&nr_rotate_swap); inced_nr_rotate_swap = true; } + cluster_info = setup_clusters(si, swap_header, maxpages); + if (IS_ERR(cluster_info)) { + error = PTR_ERR(cluster_info); + cluster_info = NULL; + goto bad_swap_unlock_inode; + } + if ((swap_flags & SWAP_FLAG_DISCARD) && si->bdev && bdev_max_discard_sectors(si->bdev)) { /* @@ -3575,8 +3360,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) bad_swap: free_percpu(si->percpu_cluster); si->percpu_cluster = NULL; - free_percpu(si->cluster_next_cpu); - si->cluster_next_cpu = NULL; inode = NULL; destroy_swap_extents(si); swap_cgroup_swapoff(si->type);