From patchwork Tue Oct 22 19:24:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13846079 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 A54EBCDD0D7 for ; Tue, 22 Oct 2024 19:30:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 322A46B0095; Tue, 22 Oct 2024 15:30:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D1C16B0096; Tue, 22 Oct 2024 15:30:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 124376B0098; Tue, 22 Oct 2024 15:30:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DEABB6B0095 for ; Tue, 22 Oct 2024 15:30:05 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A57FEAA386 for ; Tue, 22 Oct 2024 19:29:32 +0000 (UTC) X-FDA: 82702228602.28.7F97EF4 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf25.hostedemail.com (Postfix) with ESMTP id 27629A001A for ; Tue, 22 Oct 2024 19:29:51 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Rt/XPyMU"; spf=pass (imf25.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.169 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=1729625251; 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=XKHLsBzhzCnbiPIqKsShhAk0UHdn03icCPe/yHcoGTQ=; b=mEE4fohCrV2XOI3QeTb7kxJcbBhnAw6ZrimIFnMr9R4ZiIMzGVRgxxA1YVIjZbhzFB5qLK hDZDsIvbkitCGYx9cBmFfEeNbP6yDSL6d52fu0tW4eKZvQNuJaLNnGnnwOZWKAMlUcvJ4C 21DikQvHOeO9H2bSATlHK8KabSR7Ad0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729625251; a=rsa-sha256; cv=none; b=XmPwG6t7iwUGCTmK3KgFtdfpp85aJdeyKhOjCiyPOM8siHea3RC9t37shK9ZeF9sZZb6Xw R1kPuDNOFdHiVtf9MJt3iU90zD1tsq6qOAUHvnsV9yMIvPfUpaagCc3NXYV5rbQNvPzbtH mfPtJHjJco274XSC6sW69Bb/TolSCL0= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Rt/XPyMU"; spf=pass (imf25.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-20c6f492d2dso69674985ad.0 for ; Tue, 22 Oct 2024 12:30:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729625402; x=1730230202; 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=XKHLsBzhzCnbiPIqKsShhAk0UHdn03icCPe/yHcoGTQ=; b=Rt/XPyMUJGga9XhOphmgIvkREBuGyVuIlFNioNslNK4KXn2GizAzfo28h67bku+Wc1 FBNPFt6yQ90I3+ZoBWZM1xVItdPjJ/eZqKbtDzm5zt2Mb4ZrpCPeEA9RfZrYrNp5ClOI E+WABNPkN9hwYlOHElFNqsxmuciNziuahVrHhXIGIPWLqmLkcugBTKkPDkIcXnd2K2l1 HUVwN9os4wKDOtETtgSwb8cc5d2bcd8OnMXN+ak8IwuHfBFHsxJS9iPar4kfQKSRufV4 xrL5DNo+/e+8rX7iUCfv1uvkFJ+UNJgEtch1p8XZwGjsgVb5XXqSvkflyq1A5MSEaWs8 UzHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729625402; x=1730230202; 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=XKHLsBzhzCnbiPIqKsShhAk0UHdn03icCPe/yHcoGTQ=; b=Sy27OZ1t9r4s50GTYYRBswr+PbF+qM3MF97AXj0w/lTLmsXyhx+yNtZ5Z+ivGSGDss IpzPtKyHW4qJknUws3NFxPS2qPvTkFpKWHsbYXpDqsNmov0eDKUxk38WqBMHRifK3DhA t1VMa1Lmv1d87vWz2df5XW65a+y2OgSfWkNtdFqYxpikb3qJca/zgOQmAZ6ZtDEoYktx rO75MGgQY8ZODV7fsnGS93PSeQepR8j10hwTlQoO3lXlN6oCpNnpsYqFX8uOedibfxGY 1Yuhm4hFh7N6l9Ovogb1cWLP8XbdzPaf0BxD6fPIX1yu1h2UoONDb4vR3lqmKKnMx0Py KS9Q== X-Gm-Message-State: AOJu0YyBpXx+Cy2pVWTXL+er2dIr13R/1ra+tpnbpd/GToDp+w4qY1u4 UoSJRUbihmJIlPaQfG+a6DGJAei097A6zv8o/ln/RdBvTafoFuEv38MqpPoZ+Ao= X-Google-Smtp-Source: AGHT+IH5d48HG7yM1vsiLoHlHuj/5dQGaeruEyz0B4KacEW852FH1mXkSs1tEGlqkW7GrlSz5sKaZA== X-Received: by 2002:a17:902:ec82:b0:20b:4875:2c51 with SMTP id d9443c01a7336-20fa9e5c6f7mr2808315ad.27.1729625401890; Tue, 22 Oct 2024 12:30:01 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([106.37.123.36]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7f0d9f05sm45895305ad.186.2024.10.22.12.29.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Oct 2024 12:30:01 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Chris Li , Barry Song , Ryan Roberts , Hugh Dickins , Yosry Ahmed , "Huang, Ying" , Tim Chen , Nhat Pham , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH 05/13] mm, swap: clean up device availability check Date: Wed, 23 Oct 2024 03:24:43 +0800 Message-ID: <20241022192451.38138-6-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241022192451.38138-1-ryncsn@gmail.com> References: <20241022192451.38138-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Stat-Signature: 8j3ofb751kimz18ujb8m5szxuqwn1tzg X-Rspamd-Queue-Id: 27629A001A X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1729625391-830763 X-HE-Meta: U2FsdGVkX19Pua8YZdxb8SDUnyV8WE1r+0cFE/q9U6EL+FVaDKpv6itb9hGWId2Q3H5yTQwG60P47yMI6nQuCOqdSTUayMJcqJFPOb3Da1I6C+lSoOEa6XfLWD/jE39hvKc7A8tvoxg5R6uGa4pT/EK3bR8E3aWHBsq6Cb29j282z3Cx7eHEj+XePe9FJgD8KIJci5W0K6UxgBKaxtdIGggwSGACZfJPwNqs9G1715qPfKT0a0OS3cDVLGDeFq+aXdFBI7vYZUyu0bByDYWLTMn7iExw2GtIf3pqWlgrM4bHznivLljcrWWNpuyo5oOXEtbbfIpMBrWBEjUc0bjszGy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HeVo5LnzU1ZwtH6X1mkJuXrJfQ2dH2yU4wn7gbevCJyzSBAYcKC3e/3SUiYa0RT694z3aj9HvOu/i3hvjAlAEhLAZ3v+XV0WoGhqBPiUPAz8VjgdpcMze5+Q== 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 Remove highest_bit and lowest_bit. After HDD allocation path is removed, only purpose of these two fields is to judge if the device is full or not, which can be done by checking inuse_pages instead. Signed-off-by: Kairui Song --- fs/btrfs/inode.c | 1 - fs/iomap/swapfile.c | 1 - include/linux/swap.h | 2 -- mm/page_io.c | 1 - mm/swapfile.c | 38 ++++++++------------------------------ 5 files changed, 8 insertions(+), 35 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 5618ca02934a..aba9c0d58998 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -10023,7 +10023,6 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file, *span = bsi.highest_ppage - bsi.lowest_ppage + 1; sis->max = bsi.nr_pages; sis->pages = bsi.nr_pages - 1; - sis->highest_bit = bsi.nr_pages - 1; return bsi.nr_extents; } #else diff --git a/fs/iomap/swapfile.c b/fs/iomap/swapfile.c index 5fc0ac36dee3..b90d0eda9e51 100644 --- a/fs/iomap/swapfile.c +++ b/fs/iomap/swapfile.c @@ -189,7 +189,6 @@ int iomap_swapfile_activate(struct swap_info_struct *sis, *pagespan = 1 + isi.highest_ppage - isi.lowest_ppage; sis->max = isi.nr_pages; sis->pages = isi.nr_pages - 1; - sis->highest_bit = isi.nr_pages - 1; return isi.nr_extents; } EXPORT_SYMBOL_GPL(iomap_swapfile_activate); diff --git a/include/linux/swap.h b/include/linux/swap.h index 3a71198a6957..c0d49dad7a4b 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -305,8 +305,6 @@ struct swap_info_struct { struct list_head frag_clusters[SWAP_NR_ORDERS]; /* list of cluster that are fragmented or contented */ unsigned int frag_cluster_nr[SWAP_NR_ORDERS]; - unsigned int lowest_bit; /* index of first free in swap_map */ - 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 */ struct percpu_cluster __percpu *percpu_cluster; /* per cpu's swap location */ diff --git a/mm/page_io.c b/mm/page_io.c index a28d28b6b3ce..c8a25203bcf4 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -163,7 +163,6 @@ int generic_swapfile_activate(struct swap_info_struct *sis, page_no = 1; /* force Empty message */ sis->max = page_no; sis->pages = page_no - 1; - sis->highest_bit = page_no - 1; out: return ret; bad_bmap: diff --git a/mm/swapfile.c b/mm/swapfile.c index f8e70bb5f1d7..e620b41c3120 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -55,7 +55,7 @@ static bool swap_count_continued(struct swap_info_struct *, pgoff_t, static void free_swap_count_continuations(struct swap_info_struct *); static void swap_entry_range_free(struct swap_info_struct *si, swp_entry_t entry, unsigned int nr_pages); -static void swap_range_alloc(struct swap_info_struct *si, unsigned long offset, +static void swap_range_alloc(struct swap_info_struct *si, unsigned int nr_entries); static bool folio_swapcache_freeable(struct folio *folio); static struct swap_cluster_info *lock_cluster(struct swap_info_struct *si, @@ -647,7 +647,7 @@ static void cluster_alloc_range(struct swap_info_struct *si, struct swap_cluster } memset(si->swap_map + start, usage, nr_pages); - swap_range_alloc(si, start, nr_pages); + swap_range_alloc(si, nr_pages); ci->count += nr_pages; if (ci->count == SWAPFILE_CLUSTER) { @@ -876,19 +876,11 @@ static void del_from_avail_list(struct swap_info_struct *si) spin_unlock(&swap_avail_lock); } -static void swap_range_alloc(struct swap_info_struct *si, unsigned long offset, +static void swap_range_alloc(struct swap_info_struct *si, unsigned int nr_entries) { - unsigned int end = offset + nr_entries - 1; - - if (offset == si->lowest_bit) - si->lowest_bit += nr_entries; - if (end == si->highest_bit) - WRITE_ONCE(si->highest_bit, si->highest_bit - nr_entries); WRITE_ONCE(si->inuse_pages, si->inuse_pages + nr_entries); if (si->inuse_pages == si->pages) { - si->lowest_bit = si->max; - si->highest_bit = 0; del_from_avail_list(si); if (vm_swap_full()) @@ -921,15 +913,8 @@ static void swap_range_free(struct swap_info_struct *si, unsigned long offset, for (i = 0; i < nr_entries; i++) clear_bit(offset + i, si->zeromap); - if (offset < si->lowest_bit) - si->lowest_bit = offset; - if (end > si->highest_bit) { - bool was_full = !si->highest_bit; - - WRITE_ONCE(si->highest_bit, end); - if (was_full && (si->flags & SWP_WRITEOK)) - add_to_avail_list(si); - } + if (si->inuse_pages == si->pages) + add_to_avail_list(si); if (si->flags & SWP_BLKDEV) swap_slot_free_notify = si->bdev->bd_disk->fops->swap_slot_free_notify; @@ -1035,15 +1020,12 @@ int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_order) plist_requeue(&si->avail_lists[node], &swap_avail_heads[node]); spin_unlock(&swap_avail_lock); spin_lock(&si->lock); - if (!si->highest_bit || !(si->flags & SWP_WRITEOK)) { + if ((si->inuse_pages == si->pages) || !(si->flags & SWP_WRITEOK)) { spin_lock(&swap_avail_lock); if (plist_node_empty(&si->avail_lists[node])) { spin_unlock(&si->lock); goto nextsi; } - WARN(!si->highest_bit, - "swap_info %d in list but !highest_bit\n", - si->type); WARN(!(si->flags & SWP_WRITEOK), "swap_info %d in list but !SWP_WRITEOK\n", si->type); @@ -2425,8 +2407,8 @@ static void _enable_swap_info(struct swap_info_struct *si) */ plist_add(&si->list, &swap_active_head); - /* add to available list iff swap device is not full */ - if (si->highest_bit) + /* add to available list if swap device is not full */ + if (si->inuse_pages < si->pages) add_to_avail_list(si); } @@ -2590,7 +2572,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) drain_mmlist(); /* wait for anyone still in scan_swap_map_slots */ - p->highest_bit = 0; /* cuts scans short */ while (p->flags >= SWP_SCANNING) { spin_unlock(&p->lock); spin_unlock(&swap_lock); @@ -2925,8 +2906,6 @@ static unsigned long read_swap_header(struct swap_info_struct *si, return 0; } - si->lowest_bit = 1; - maxpages = swapfile_maximum_size; last_page = swap_header->info.last_page; if (!last_page) { @@ -2943,7 +2922,6 @@ static unsigned long read_swap_header(struct swap_info_struct *si, if ((unsigned int)maxpages == 0) maxpages = UINT_MAX; } - si->highest_bit = maxpages - 1; if (!maxpages) return 0;