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 532ACE77188 for ; Tue, 24 Dec 2024 14:39:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF8486B0096; Tue, 24 Dec 2024 09:39:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D81FE6B0098; Tue, 24 Dec 2024 09:39:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD49C6B0099; Tue, 24 Dec 2024 09:39:53 -0500 (EST) 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 981646B0096 for ; Tue, 24 Dec 2024 09:39:53 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 111841619F4 for ; Tue, 24 Dec 2024 14:39:53 +0000 (UTC) X-FDA: 82930110984.05.4CD4757 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf01.hostedemail.com (Postfix) with ESMTP id 40EEA40007 for ; Tue, 24 Dec 2024 14:39:21 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JjsVYGVJ; spf=pass (imf01.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=1735051150; 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=wrLhjYRLlutCAl1gCOYOsbHS82zDx2LhvG3HLqe+qww=; b=SC2js8KeCXrNQ4kIl/i3JiutSV7/UsUAX7rUsDuxBpr0LxiUgZGyObVHZAhUzu0sqt97bM F2bNv8TiTcLN7ZtLnp3z8SNGfvrVHwqdU9H/Hic9vRZ4e6p/bvnQh4bmCZoLPfqcCVkObV wF6YreQC5e/mHSmy/L3AyqdKI7HXSJM= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JjsVYGVJ; spf=pass (imf01.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735051150; a=rsa-sha256; cv=none; b=Bq8jDBwWkHbltHhdY8bVO++4g7maoT8yRt5SA1tMbZi8OGo5R/08NkqGQArUnqLuFxBZjP 9/A1HJj1xA80vKRL/qdYusRhii3+iNi+4TRp0VXPvexnUd8ix8d5JjeHVp3WLGdEhVNa6Y hwzAidolkgiMEA90v6tWtGxnRE3D+Jk= Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2166022c5caso47527825ad.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=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=wrLhjYRLlutCAl1gCOYOsbHS82zDx2LhvG3HLqe+qww=; b=JjsVYGVJrz2mN2jlRT5ngMybCM2DxFJM217NyOViXK5pdmiEkEgrVZa3CAQv7kvs8x E6qR5kCK1eXa+FXLrkkQqH0f8Q6B9A8rlMbAd228o75MnxCMBQ6qxpk+1BVEeiHi3EnW DSjSvxUgsyLlO5+FZvYfsK690kn1MAZ8d9z3378dBoS/9XGy/bu3DrVSzFIZPEyamE3U maAg8vZGyAjI8dEY6jUCqgs+KF2HbrmIZlBwXIbUZGlarsqs4Bx7Lk0LFN3vL1XrDtNF AtQNp7h1k1cmuaq5d5ZiqhIRvv0c60mMEG/gZnponiD3wwyI3ENC/XvgS5fMAXO5pQ1r Bi4w== 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=kXeiiLctnrg54wwo0O+vCTOmwifoCd9gV9HYKXN9ymUni8E+C1s9wJCi5vs39Herq+ z1mLSrJIBUg8XQZlhfuY7t4bh0y/NCfTH5r7jLQVsRdJxIVZrzQas/EyBOB0sJkCfs+h Pk19DkbUFFowTE4/KNUjgd3FTj4trnNlH0YcY55ClSb2gqNsRKiHIewTsRWkn6INiS7a k2YBuxrScMSgiInlXHoYGoGg/f/WoGurb+W/QW8b/V8NAMN+g8vU+92PpMGQKGin/Fm0 yUTD6LBRnNKYLcb2aJk06iAMYFub25iIqk/ecBv4ewJGCndLHtWQWjuNVTIi1DD6VnUu 92Mw== X-Gm-Message-State: AOJu0YxlcnMjXrApFRVGG1SNbDkqqRIDc5BiZzuwta1ge/xhHr5yq4Yo tC5nV/M0Rx/tHQXRgpeT72hUzxngfeGbxJUMcEcyWjyqts/fSk/kMl7xwplOkuc= X-Gm-Gg: ASbGncvpSkyTnzxKMCLI4UtTGjWEHvJzMDhvo1WXBci31OKWynR9jF8jFQCzy0h3QgQ S7OX8iFQpR4mHIq+bjUWqEUanTU3hK6UXSgBELKtABDgBIeT2YdkEx3ujHyx6ShusT+SQ5dyuQs WsntgsRTFDxQcZxNL433AHrZ5BieEjOgXXpy9bUr+RLAeOc11rJJMk1oI5hOOrnayqq2+3rd6ku wFIp1k6aoDUKYYx5uTIEHuCFcs2sh6zL5B6VLYyUkCewoq1MlAv3I+fSTkPGuNVfTTpTCKLFj+f /Q== 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 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 40EEA40007 X-Rspam-User: X-Stat-Signature: 9n6e87hjj8oum3wig4r9uw1afbhg1kcd X-HE-Tag: 1735051161-265401 X-HE-Meta: U2FsdGVkX189M01ND0EygpcnpDmDIDKk2ECDJGq8h2z4bx37YjOdvmkbW4U+wZWENPWf6oiHgBRAD30ioL5BjyK8YQqUEZjQoRahxZNqyZGw9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5knPcTMO3rv+TsJix03JF8ySlq3CmSBllTN38LFbIFUIhYAkgCUNyZyt+0uKoocaTugSFeKWnDXKcwdNN0Xuo1se0id8T/ouBSqwILtIezsB3raSfw6yU6OTtDdPi0w7ckr29RukcQhvZ80gTdQzmqYRVHrXI1X0s7bQQXMe6BILBQRbSwO4+S174XSkClE5HyVMPlByddtC+OA/rvplR5x0VfoAsXJiYUnxgP/7dJWufXA/TcnZA7dR6U9NGBJjHLB6mjRJUXe/LBIp40+OfskAp785OVCvYzMdRUyJY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000041, 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 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_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 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