From nobody Thu Dec 18 20:36:29 2025 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6692E1C4A20 for ; Mon, 13 Jan 2025 18:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736791213; cv=none; b=f90T9aBH4UGvR1vA9OEsZ6/RE9IzqADn7iCDsAEnNw3KqRb5cw3gNn4v0EM8PNNNCm6L86Twe90+id2DimnaFd8vSwO8kfVcfAh2MVA+W/JbzyL0sNHwR/Ho1FY1rkAYDrNs8nREmxB9kSs5v2jGgT4KeeE2njSsswf/9r6Q8CQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736791213; c=relaxed/simple; bh=6KYQITAfq02WCUP/VkTZrmdu/jT+2h8D7j6IYd56acQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MG70o/i0X1Lixmyzfu2utBF+krykqWiPvdXCqh8qJXv0TIo4M3ExU2WnN2thXwJ9vS8Coubb7mNzdDM9hs6yv3zvDMY0GofyW6h/e261zNqvmZEiWPJimE2JMHpd/MpKCTu8y+2HBKpZLBx4FcAL3DmUtQnBCC8smi0ndlObgnA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jTtASz0r; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jTtASz0r" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21644aca3a0so101075495ad.3 for ; Mon, 13 Jan 2025 10:00:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736791210; x=1737396010; darn=vger.kernel.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=caiI/VOqAJNiDWWa2+iKhM4Oze87dUQbCW5ZECHeaJM=; b=jTtASz0rfYS07aT7R4/TdjeR1xrxM9WgdkZHljt+oTarFm8yxy/E1CpfmzP2SHajyF qLjgn9qD2mioYILcdpGM/gUuUcW7UxTUocfL15ORYfdiiMyqAx4FYYeyYDlMfTh3vFi/ 8Me4/hwI1M5nRy/ZKRHRDGm+5ZegpTvisb9wmXa0jF7K/P8yeJiNtUlK9iS9tWsISGlx Wcz8DJi2hFJkRwEgH8hyPQsV9/JBgXJQutf/T5FiE5F5qGCYhTXF+QCJKnSzI41wRkZJ NDSlSzjq2qa1wSBXJPnlfQDjHBk++SB4RpfHPZUuSnyyWcRqbgJK1nI2veB41pocBHNr jnMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736791210; x=1737396010; 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=caiI/VOqAJNiDWWa2+iKhM4Oze87dUQbCW5ZECHeaJM=; b=cp05Xa7tP48h8O4s0t0DfZCbAMogC5ZG2qbucNrpgUh+/vW3D+GJqHJTLQc0oS//Ie 6q+5a8fzwZlwYdD9n5zS8l7g4MU14mv9HVtqR8LMp9tG7+4njEvUnnu0/3dR+a+uR5IG ooFALzYpGSRZ/nwA32ZJ78nMJj5JSlj/qm5me4N9/455M1NDa3mZpEd4FQpYfkjV7aNU 3elEK569C749hU2l4X+I3X1IWyL5z+MyjTKuAkaJMb918rxfPXcoIJyfjIyjv41IxmSw yKui7S2t0T88i2keQ0tBaKL2myA04F7oPKOnuWqUPodrKPtcTG39RseqsNr3QOInHSfJ egMg== X-Forwarded-Encrypted: i=1; AJvYcCWrmen0iJ4/OvAQNrYp1CasOGMUeFVX+Fc60RT4CJKymbZ3AXNrSxu+6wRDFYV42te9WE9hff8pfdLL/Qw=@vger.kernel.org X-Gm-Message-State: AOJu0YzG07ndxJjSBh1k5L8nD0iZh3ih/FmtXNkrTfJcauNYlpGB45/f L/qD1zYYr1ifNHN3rtqnkNh2GNEnmLdVauMNj+rZUJY44xrw3xxm X-Gm-Gg: ASbGnct0yZyaSxCADi59c2iAzcRlgz+hUfNUDWnZ4u3UBYo3iL/NhUmnaa7Jm7Z1QyA i2wN2v9wltusZa3Gfuo+56y1k5Lv490C+HT8fYa2/ZDmqkkOa5p5Rkf/FA7R4RMqH86gAXuOpXs hrhxIo3k8iL7W7eWyH2As4p+bfATMNdwFs1FoqLVexe60Sa7uUHlO+u/J/RxCuS3BneFgnpBSM6 0jWu+uZHfqWAoR+fXpiBZitsgtOvOoD488cRpbgjJk1N3ADThpdPCwy4D4lUMyiAm/D/bY5h1BN 9A== X-Google-Smtp-Source: AGHT+IHY2pN1dmNgQ/jErEKoR8jYGQXUl/IK9P33gRI+ptN1dWK+uFbMLz+TQgZSbpLd4QV4khSiBw== X-Received: by 2002:a17:902:d48a:b0:216:4064:53ad with SMTP id d9443c01a7336-21a840109d2mr324618055ad.48.1736791210057; Mon, 13 Jan 2025 10:00:10 -0800 (PST) Received: from KASONG-MC4.tencent.com ([115.171.41.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f21aba7sm57023635ad.113.2025.01.13.10.00.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 13 Jan 2025 10:00:08 -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" , Baoquan He , Nhat Pham , Johannes Weiner , Kalesh Singh , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v4 05/13] mm, swap: clean up device availability check Date: Tue, 14 Jan 2025 01:57:24 +0800 Message-ID: <20250113175732.48099-6-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113175732.48099-1-ryncsn@gmail.com> References: <20250113175732.48099-1-ryncsn@gmail.com> Reply-To: Kairui Song Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kairui Song Remove highest_bit and lowest_bit. After the HDD allocation path has been removed, the only purpose of these two fields is to determine whether the device is full or not, which can instead be determined by checking the inuse_pages. Signed-off-by: Kairui Song Reviewed-by: Baoquan He --- fs/btrfs/inode.c | 1 - fs/f2fs/data.c | 1 - fs/iomap/swapfile.c | 1 - include/linux/swap.h | 2 -- mm/page_io.c | 1 - mm/swapfile.c | 38 ++++++++------------------------------ 6 files changed, 8 insertions(+), 36 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 27b2fe7f735d..3b99b1e19371 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -10110,7 +10110,6 @@ static int btrfs_swap_activate(struct swap_info_str= uct *sis, struct file *file, *span =3D bsi.highest_ppage - bsi.lowest_ppage + 1; sis->max =3D bsi.nr_pages; sis->pages =3D bsi.nr_pages - 1; - sis->highest_bit =3D bsi.nr_pages - 1; return bsi.nr_extents; } #else diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index a2478c2afb3a..a9eddd782dbc 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -4043,7 +4043,6 @@ static int check_swap_activate(struct swap_info_struc= t *sis, cur_lblock =3D 1; /* force Empty message */ sis->max =3D cur_lblock; sis->pages =3D cur_lblock - 1; - sis->highest_bit =3D cur_lblock - 1; out: if (not_aligned) f2fs_warn(sbi, "Swapfile (%u) is not align to section: 1) creat(), 2) io= ctl(F2FS_IOC_SET_PIN_FILE), 3) fallocate(%lu * N)", 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 *si= s, *pagespan =3D 1 + isi.highest_ppage - isi.lowest_ppage; sis->max =3D isi.nr_pages; sis->pages =3D isi.nr_pages - 1; - sis->highest_bit =3D 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 0c681aa5cb98..0c222017b5c6 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -306,8 +306,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 locatio= n */ diff --git a/mm/page_io.c b/mm/page_io.c index 4b4ea8e49cf6..9b983de351f9 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 =3D 1; /* force Empty message */ sis->max =3D page_no; sis->pages =3D page_no - 1; - sis->highest_bit =3D page_no - 1; out: return ret; bad_bmap: diff --git a/mm/swapfile.c b/mm/swapfile.c index 83ebc24cc94b..2686032d3510 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 of= fset, +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, @@ -650,7 +650,7 @@ static bool cluster_alloc_range(struct swap_info_struct= *si, struct swap_cluster } =20 memset(si->swap_map + start, usage, nr_pages); - swap_range_alloc(si, start, nr_pages); + swap_range_alloc(si, nr_pages); ci->count +=3D nr_pages; =20 if (ci->count =3D=3D SWAPFILE_CLUSTER) { @@ -888,19 +888,11 @@ static void del_from_avail_list(struct swap_info_stru= ct *si) spin_unlock(&swap_avail_lock); } =20 -static void swap_range_alloc(struct swap_info_struct *si, unsigned long of= fset, +static void swap_range_alloc(struct swap_info_struct *si, unsigned int nr_entries) { - unsigned int end =3D offset + nr_entries - 1; - - if (offset =3D=3D si->lowest_bit) - si->lowest_bit +=3D nr_entries; - if (end =3D=3D 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 =3D=3D si->pages) { - si->lowest_bit =3D si->max; - si->highest_bit =3D 0; del_from_avail_list(si); =20 if (vm_swap_full()) @@ -933,15 +925,8 @@ static void swap_range_free(struct swap_info_struct *s= i, unsigned long offset, for (i =3D 0; i < nr_entries; i++) clear_bit(offset + i, si->zeromap); =20 - if (offset < si->lowest_bit) - si->lowest_bit =3D offset; - if (end > si->highest_bit) { - bool was_full =3D !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 =3D=3D si->pages) + add_to_avail_list(si); if (si->flags & SWP_BLKDEV) swap_slot_free_notify =3D si->bdev->bd_disk->fops->swap_slot_free_notify; @@ -1051,15 +1036,12 @@ int get_swap_pages(int n_goal, swp_entry_t swp_entr= ies[], 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 =3D=3D 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); @@ -2441,8 +2423,8 @@ static void _enable_swap_info(struct swap_info_struct= *si) */ plist_add(&si->list, &swap_active_head); =20 - /* 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); } =20 @@ -2606,7 +2588,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, special= file) drain_mmlist(); =20 /* wait for anyone still in scan_swap_map_slots */ - p->highest_bit =3D 0; /* cuts scans short */ while (p->flags >=3D SWP_SCANNING) { spin_unlock(&p->lock); spin_unlock(&swap_lock); @@ -2941,8 +2922,6 @@ static unsigned long read_swap_header(struct swap_inf= o_struct *si, return 0; } =20 - si->lowest_bit =3D 1; - maxpages =3D swapfile_maximum_size; last_page =3D swap_header->info.last_page; if (!last_page) { @@ -2959,7 +2938,6 @@ static unsigned long read_swap_header(struct swap_inf= o_struct *si, if ((unsigned int)maxpages =3D=3D 0) maxpages =3D UINT_MAX; } - si->highest_bit =3D maxpages - 1; =20 if (!maxpages) return 0; --=20 2.47.1