From patchwork Mon Jan 13 17:57:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13937871 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 11891C02180 for ; Mon, 13 Jan 2025 18:00:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FE326B009D; Mon, 13 Jan 2025 13:00:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9AEAD6B009E; Mon, 13 Jan 2025 13:00:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 84FEF6B009F; Mon, 13 Jan 2025 13:00:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6478D6B009D for ; Mon, 13 Jan 2025 13:00:14 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 10EDD80219 for ; Mon, 13 Jan 2025 18:00:14 +0000 (UTC) X-FDA: 83003192748.09.8F2BA41 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf14.hostedemail.com (Postfix) with ESMTP id 0C36F100023 for ; Mon, 13 Jan 2025 18:00:11 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ls+M2d2n; spf=pass (imf14.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.172 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=1736791212; a=rsa-sha256; cv=none; b=gPxrSZsGThAz4BD1k9nouA5OlkfLR68XPfncL+f6UPeAlZirJ1QfV+/XgIZWRJVGjwyhoy eT+tNHaSTMu+xsb0tk51/9uUkH0nAMLjdnjgOrRuDS/9P4U7owYyu9HZZia+v3tEBNtJYy 2aBrb1QhpA0tJEf65Yqon04Fxwfmvbk= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ls+M2d2n; spf=pass (imf14.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.172 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=1736791212; 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=caiI/VOqAJNiDWWa2+iKhM4Oze87dUQbCW5ZECHeaJM=; b=ckYiWg4VnbO9LbqPK19sf4aEuw0s2CQUmDtfWfr2dOx9N2oiY33/mUHHxQNHWJrWQxLoi1 y5o7GH0sJL6XeKBK9OCnRFCb+Y4C4r+iAjKtLvwH1PO9AWtbcopwlbIDGiOvTgg8OlcDST N3awL4e2htGpyvSU+slsJEe6s/IUBpU= Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-21636268e43so107039105ad.2 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=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=caiI/VOqAJNiDWWa2+iKhM4Oze87dUQbCW5ZECHeaJM=; b=Ls+M2d2noTjh55aYCIrWGEF2I+pIJ3A2LVrdWtl8p5kZhKCtW51MWDjq2xaRtYB5kO bQUctumUwD/3lDTFWs1G5kjHx2gsR+9MaCWkB+UXhuP9V51XJXHh2ZzlGmzkTLlnL2/S iHfvjrnUcyUS3on/bQpDln3LoQuHQVxp3ngcKrEexPVUHLKEOEqBYptCS7Zg6Duwk7hw RqMkNtrjUdtBNyyH5qUwLYWbvloY8va8yX+UTbjKdP1aUq0Qbz5SoB5hmntk+AQEUS7I hzfvodWI2qHedcRitbwBvN43hYEN8IYOvt0zyUSh4TucmEitG217P/kZe9suPUod/+Ts rY4A== 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=DelOB1l/sxbuMDblMc539y3mIp/CWM8xVkauIddHefgTzQh4C/a2Pvuhw/RKbQ6QQ+ joc+CnhI81SWCp06BFc7YvoIwkho/IDpuBOM65p8SHGslqAfhP234vg6YKrwU33ckkho FJ2vk9kvBCkUY+cxsiLk+WCVH/EthGr99xk0dUAR7XPW8cpp8uatk5dul2gI+tkhWpOf be8csmeSPp9whI3dBsCcECK1iM8Q1cDzDy0A7LhTXCKZdEp21ag+9eldh0xJ31z9An7A Q1gpHgP6vyno/wXIeDlGRbK6oIfrk4nenjCKJlV+qVeXf7QRw9neDfJDc3raA0ZiJOKm mLWw== X-Gm-Message-State: AOJu0YxFzRvzb1aqAK33fSjJasYHeOs+kDCjrFFVgmU5RqKK7BlIHRDQ MuW77FPvCaIhcGXsgI21n7GkAkCTo/PDs2KrESdeVkZV+kx2R02XB9pNafS1ciw= X-Gm-Gg: ASbGncvnRCM8gsXUl0mE0/1fq3WXukF3J03Ibf2/QkWMZycQQW1siksKBGStPz+rjdI LwnaW0FAy8eJ9WkFs/5G4N6FbTRKHVpSlV7W6m79IOL/YZZwJ3LK6V6hJC7bPc+RPrt7AyjG42F Q2hrxhQH1jl6E4g4KgcA2mjzi1ZqfSOIJ3DWdUbFNaW46bC+Dy3vId7NwFBCaccaMt0yiFc2Nt+ HGhxToWeU/7oDkzVLhxOoT5mmowVuSy2tYHka7KFeKZATRxCRu75gXRq4Fv9x+tar7mJFRumsLy Ig== 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 MIME-Version: 1.0 X-Rspamd-Queue-Id: 0C36F100023 X-Stat-Signature: m9ame8nnd9ewejwonecw5zgpq17uj6ij X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1736791211-512758 X-HE-Meta: U2FsdGVkX19JQ6RW1/cKxaiyalWQ/ximilb0IbD3N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NQrwWSzoDcGKAkHCXdiC9u8FeQke7AThByZd/r2+Uvf/BKsvHXQgGRCkGsHHWh9Lyb13GFeAKOK1+ojhd1cBJTY818tIjjxcvlxN/qH4+zvfW9xBrfxKfIhNzVdsUlZgjMHyANUvtrIZDVXomgr5nXom9CO/m9flAskddqst4ZkEa7tfi3gcA3Qyxr/FL2elAD97lg6pCSPRLrgAI1zhXctJcwdltcxM5Q0OGN+MR6Y+u/zOSQCQhzdvmh3jQw5ROo1zSk5OGCNLsILAZObisL/lnbC5Kc+VAVQI8NJT68Mk6ogK0VUblmq0vyMJDySLpPwHDVmNRMcWOcKFDkxIXrMjvL/s21DIR5rHtTVGNYcVLVcoOnN6y6JOrAh/KoNh7q3S3cm/ytuTz/PgQ6SF1mu7esDQRE1BI3hiJJDzrppOLGlrWoVg= 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 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_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 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 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 (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;