From nobody Mon Feb 9 07:20:53 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 44C171D86C0 for ; Tue, 24 Dec 2024 14:39:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735051191; cv=none; b=iXqF0jQoebR6yIrs+d/O1j0vSQ7Ck4AFgWbMdeO5A7951zDhudiQzVeD/q0qsrpkvz48dS7TQUdzR3UlDS9SOrL9sOpOXYliNf74wXAeGEcrwknjajJymbTsyLuz/WUAa/I+7A7lVi3OHIeNennCQ8172ODNZhYQTvyiIInGhsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735051191; c=relaxed/simple; bh=dtNcCmTYRKXK6CZ3QO3jZvfGSnOtB9P7pdG0quS09Qs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vkv4/DlC8yS0zvZl1nAHdhz05GpCapSfDhlhVJKQZDYESJT6q9XNylrH98O8UsAKQRawCoX2zAiy9P7ro0rF+Xts+tJ7V3bnwQAJbsUm5E6b7lBGVuwTFG/xkuctBPb5ta+eNOEctSXm+RlvCwFOUGGhIV8HFiOphG283PmrqQo= 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=eadvbEpL; arc=none smtp.client-ip=209.85.214.177 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="eadvbEpL" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2166022c5caso47527755ad.2 for ; Tue, 24 Dec 2024 06:39:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735051189; x=1735655989; 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=wrLhjYRLlutCAl1gCOYOsbHS82zDx2LhvG3HLqe+qww=; b=eadvbEpL4k9En66vlQtk0DOwjKuZ4KyivUnnnvsG7fLO/1C+JM+ukM08/A/V+uCWUp pcb7J8Z7VVvXmNx5lj0m1UQI4wKODu0wRWx6e2S5ZwByNjgPwyRLUdmyAgqJi7ZygpX5 vSV6gs4doxTAValogamOOMDvjxzeLeEqYOvFMrqa4FnpQUHyiyMlmlhyOnYP1HNCgUTs 31Zfffl/mBj7Ft467eW6iPWdvxW8mpUrKOsuRJItXOrtrZlXAuUMWiDZoNtbQsZaG/bt qIAH3mjoRUb+LkaDdTRMqdpZlmNJ6e2mZA6gMvtlqckWhrieRSC+V/rqMQWmlF+aOOxt ji3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735051189; x=1735655989; 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=wrLhjYRLlutCAl1gCOYOsbHS82zDx2LhvG3HLqe+qww=; b=IOVghXu9wTXxoUydWlkIFL4kGlc7BY6gqC4pdJFBVEsJZch0zRlO/syKB9WAQC5dhh jyMNzjdWu6TUXdIXJEmijbbj8FeN8X90ABZp+WJNNsw3KedIWj6LyfCY+PNQH5wf8wT5 l77E4K8+ugyzxC+VXonxpwZljdPh9nlN03Oelt9lTnt2tb49JoSaqPqd+CFCLqCiA5zK x8pw/uuiH3W9ATHXdm4g4P9ycz/cKoVLWyJTOn4sdKIwiZ5bgaJuA3lbJ3bxzkahfuN0 p60UTa3N9ReX24HQ9MGgKuusAyHww8jQAC6ee2CnhXflhY+ACVGa5SWCUkqHSjvAEdgx oCtA== X-Forwarded-Encrypted: i=1; AJvYcCUXt5ix1iQWk5hdEYlu+CkomwAZHq6cmFxS8JeB7f5BJOfmUHDNmByAT1+k3XUG9PdY4AsiJRpb/n4MyVg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9DTfNQTyD/V0AzvQio0AmlWHbl+Ex4LjVDfJnGtgZDFY0bJRI hg/Fg2nMWfw+6YhLDdqWd+k9oVGSF3rh6JGkJ1oP26LDlZ2T4DhT X-Gm-Gg: ASbGncvYijh+TNzPDDX8K8v1f1+JzXZvnXJlOeKcp2SqNjoyr+aZyWHWty4X7D10oG3 SAFuYf6cY5JHmfLzlXQ+3lQvwu8CLBo/ZKjHLn2irOglFTzyY1cZsRToePzh8OU/JsANbydWMNp Xt/6/ohic4XDfUaqAniJ8tDquPzJFxTHhCwFW+XxHHFkogY2WMJXrZpuMjiMIPOapSQpBP+IuQL LR0kcSWARLsILSj8/oQekm8Hlu+xdxZ7XT6T9gIPzCAtEQUd/6dLZ5nkD3/iwf5w/DgeRRuiA0R 4w== X-Google-Smtp-Source: AGHT+IGNGHWwQc63B1avFd+9enD0tjMC22ByFTa2Ud87N8om2hjQ66akQBxyJtCo/qcrn+jE1mHd2w== X-Received: by 2002:a17:902:d501:b0:216:6f1a:1c81 with SMTP id d9443c01a7336-219e6e8c975mr258344285ad.2.1735051189528; Tue, 24 Dec 2024 06:39:49 -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.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 24 Dec 2024 06:39:49 -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 05/13] mm, swap: clean up device availability check Date: Tue, 24 Dec 2024 22:38:03 +0800 Message-ID: <20241224143811.33462-6-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 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 --- 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 488edca8333a..a1ba78afab2c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -10044,7 +10044,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/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 d0e5b9fa0c48..7963a0c646a4 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 (si->cluster_info && 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