From mboxrd@z Thu Jan 1 00:00:00 1970 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 CCE3DE77197 for ; Thu, 9 Jan 2025 04:08:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A2006B009B; Wed, 8 Jan 2025 23:08:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 652416B00A5; Wed, 8 Jan 2025 23:08:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F37D6B00AC; Wed, 8 Jan 2025 23:08:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E6F996B009B for ; Wed, 8 Jan 2025 23:08:52 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 92818141633 for ; Thu, 9 Jan 2025 04:08:52 +0000 (UTC) X-FDA: 82986582504.24.3AB3C5F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id BEB60100002 for ; Thu, 9 Jan 2025 04:08:50 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IQg8gHtB; spf=pass (imf14.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736395730; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YpqnNWtnqX1CS7aEp9ZkzUNo9A+wCwhiPb2NoLw6TdA=; b=A/r7zuqhVDEaGP1pLExNOkpgjpSh3saC109zuUTHwGfUl72kCrwgOS1ROUISSxltV5ftv+ WE7uDBpZA9xbtA0YGtP0GydV61ho2cBtFleCdVAk8L4zpuwOJjtgyCe/M5Oxjb/FYF3Bys +UmQCc2GkE08EN2NQ1FOWqfnfGzKsYo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736395730; a=rsa-sha256; cv=none; b=JFMj6SxuEcsRgGPM3pHBZs/rhKK7rBZm+aL/qGva5o2h1pRvaTO0Z4re+evZ4i09e35BG8 vQN1F6ZV79Pdfn7ZD8/Hu+zl6XnC7unb6G+Fitv7ox9k0A9JluiH989Zncssu3zz7NNEQr PtP9UZM0Jdyzd5oYGuAfGBzjQuyzANo= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IQg8gHtB; spf=pass (imf14.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736395730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YpqnNWtnqX1CS7aEp9ZkzUNo9A+wCwhiPb2NoLw6TdA=; b=IQg8gHtBRP3BmGzVz9nISnRs/N1QR4yghGD2Qk3h0PgacavornXNDhAp7sYAYRs9Jf0/7k psjsqgU2IgYNEe8eezfrdgriXcIuI8bU0S6pyiHKx8GdKDxS2frb9Y9Byt0nG6Kw0mQUc7 opr0zjsTKwmSpfnEKxhHEcxycz9Kty8= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-270-R_i4hYF8MFSfjxacjvLZqQ-1; Wed, 08 Jan 2025 23:08:45 -0500 X-MC-Unique: R_i4hYF8MFSfjxacjvLZqQ-1 X-Mimecast-MFC-AGG-ID: R_i4hYF8MFSfjxacjvLZqQ Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A283C1955F2D; Thu, 9 Jan 2025 04:08:20 +0000 (UTC) Received: from localhost (unknown [10.72.112.99]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4FAFE19560AE; Thu, 9 Jan 2025 04:08:18 +0000 (UTC) Date: Thu, 9 Jan 2025 12:08:15 +0800 From: Baoquan He To: Kairui Song Cc: linux-mm@kvack.org, 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 Subject: Re: [PATCH v3 05/13] mm, swap: clean up device availability check Message-ID: References: <20241230174621.61185-1-ryncsn@gmail.com> <20241230174621.61185-6-ryncsn@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241230174621.61185-6-ryncsn@gmail.com> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: BEB60100002 X-Stat-Signature: 1y5f6bf1xni3s8y7u141jy9c45bfwcfw X-Rsp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bBdl+s0taucyAsUDHmwj8ATpG5T/QhqXBlhYLapoop2d0lFJPQLBIKx3gVeV6PRiWPCfRXY60pQwXt2EUq4k0teH5crnloqG1+m7LPEQakROXXBpgyRQCUd1JuxOsSh3q/xPHU1vfvCnmmLub4Vdlt3mNqjJZIBHsk53T98LpmI8hCatC5ox6OSf/JlD4IMbfBVpIuAKxwI7ptryx8/C9EWcC7KL0lNOu4Hwn7laa3k8yRwj37MNmS/mNPvZNL+iVEnguVyut81j0MC26BoM+cm2jH2/oiRxq86nh7cbmPabooaRPSt86uO43d0UfqoaIttebM= 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: On 12/31/24 at 01:46am, Kairui Song wrote: > 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/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(-) Reviewed-by: Baoquan He > > 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_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/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_struct *sis, > cur_lblock = 1; /* force Empty message */ > sis->max = cur_lblock; > sis->pages = cur_lblock - 1; > - sis->highest_bit = cur_lblock - 1; > out: > if (not_aligned) > f2fs_warn(sbi, "Swapfile (%u) is not align to section: 1) creat(), 2) ioctl(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 *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 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 location */ > 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 = 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 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 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, > @@ -650,7 +650,7 @@ static bool 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) { > @@ -888,19 +888,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 (si->cluster_info && vm_swap_full()) > @@ -933,15 +925,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; > @@ -1051,15 +1036,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); > @@ -2441,8 +2423,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); > } > > @@ -2606,7 +2588,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); > @@ -2941,8 +2922,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) { > @@ -2959,7 +2938,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; > -- > 2.47.1 > >