From patchwork Wed May 29 08:28:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13678363 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 2265FC25B75 for ; Wed, 29 May 2024 08:29:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA6AE6B009E; Wed, 29 May 2024 04:29:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2E786B009F; Wed, 29 May 2024 04:29:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 881B66B00A0; Wed, 29 May 2024 04:29:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6427F6B009E for ; Wed, 29 May 2024 04:29:02 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 21D5C1C1280 for ; Wed, 29 May 2024 08:29:02 +0000 (UTC) X-FDA: 82170758124.23.446E961 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf05.hostedemail.com (Postfix) with ESMTP id 4D62C100013 for ; Wed, 29 May 2024 08:29:00 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AlgVVsfW; spf=pass (imf05.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=21cnbao@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=1716971340; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=o8PkNiQW/mkvjIvpLEp+EBywhuNk7TaiPl+XTuB214I=; b=LV0J2Ys1Qw75Gx4OhgzCKSYI6WbDjnRtBQ5AdIOUPY4MH3yRFE+tDvFLdC+S4KSwh7jJnZ S9cVjo4w/l6jI3VQel3syaJSAGHrd1whk2gOioEg0G2uORvP3JLJs3joHvwTQGLt0Ut8v7 G20hnhl+zVNsnwWj2mrnRhlIdgcDYTw= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AlgVVsfW; spf=pass (imf05.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716971340; a=rsa-sha256; cv=none; b=A2LubWcLIEuKgbjJ1KRbe0KGqRP3yJs0LySHp4NoT5Q/O7+zrbv4NHg38jbvc+CH2xz2GO ox1OeSgWDggjZzmb9qUjyzXVRtjnYWYaudSOlgj08I8T6LTOslXJUqu+ZFJ36CYV4hV1/h +DtdFGwe3x8b0WoFkfsM01O8+WHVOGA= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6f966840af7so1522922b3a.2 for ; Wed, 29 May 2024 01:29:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716971339; x=1717576139; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o8PkNiQW/mkvjIvpLEp+EBywhuNk7TaiPl+XTuB214I=; b=AlgVVsfWqb6vlqXPsumcxd/U7AmW8o70PNC8JSkBjJKtRSeKuZ7XknTzNp7A4omj5f hURdBgsBQE2tuN8EFuDpus6jzioWMhshAHd0tomTDfbljXJ870oiEhG9YeI1tA6OoC4F PtEoOBVrMJlWAoSchYfu9Zv34MHSmMTf9buZDMvS8eFT0ft1Vw79eafK0Wh1kyn7Sq+v uOkbYSbSX0Lv/S+FE2virtoSz6D12eHsl/eYc12I7Sg1pnsiKdyO6iKkjSwGccX1Oc3t 3NzqX0EqH9POPTlinP/cK8g1R5iSdUkek4A6xGsEwBhhTHLL1OA3Q69XVlcaQ7cXUya4 QOfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716971339; x=1717576139; h=content-transfer-encoding:mime-version: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=o8PkNiQW/mkvjIvpLEp+EBywhuNk7TaiPl+XTuB214I=; b=XB3UcRUh4Tgh1ImTsFbxjfXY1N21HxX/hHqKKcFr5tJVdlLJZ1V802fqMUOwZzD452 upxCp1/owR5kHo1jsqLcmKV003DSy9GojorItYlYAAUluW/IAMDiXqvRAl/LPo2q2DEA 3QmhqbauWEvQX/Y/vh9DaMmJjLeBYCLuGVjHS+5EtCWebAdf0yTnT9qq+LcFfgDLOy73 YctOdxKIuDTZcbKnh7QVS+64Bd60Etvfgzto5zthl07/eeUAzq1SKJaBLM3U+DcJVpYg N7r65R1firHQwEvPnb9hF+gngpiEopaAIEGIHiz2v+RVVxzz2z2IHLV3MM2d/b7w2YkM 8dvA== X-Forwarded-Encrypted: i=1; AJvYcCVBbnACKwZLFPvEfUZebyxxHd7kEd5jmOhhzDgutwBzBLL21csUeMlPIQWHE65WNvw9fegCw5H/K67I88+9EVZxPlw= X-Gm-Message-State: AOJu0YwrcDtMLlceyjvw/oKHQXtnSh1KR39wg+zTCf54TrJUxGiPwtbs fFyKMP37WFG1gmkirpw4EwAivZpyBGewfKlb1ecWJWcbRB8zT+DO X-Google-Smtp-Source: AGHT+IFIIMwl+a1BFU1LURBAWUDnpnOzYB+DE372n3RJK0yLX+C7PJpG+VjhO1aGqsG0jKGc/xlpAg== X-Received: by 2002:a05:6a00:4405:b0:6f8:caf2:8f4f with SMTP id d2e1a72fcca58-6f8f45d2624mr16218543b3a.33.1716971338932; Wed, 29 May 2024 01:28:58 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-702220d948bsm174916b3a.131.2024.05.29.01.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 01:28:58 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: baolin.wang@linux.alibaba.com, chrisl@kernel.org, david@redhat.com, hanchuanhua@oppo.com, hannes@cmpxchg.org, hughd@google.com, kasong@tencent.com, linux-kernel@vger.kernel.org, ryan.roberts@arm.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yosryahmed@google.com, yuzhao@google.com, ziy@nvidia.com, "Rafael J. Wysocki" , Pavel Machek , Len Brown , Christoph Hellwig Subject: [PATCH v5 2/6] mm: remove the implementation of swap_free() and always use swap_free_nr() Date: Wed, 29 May 2024 20:28:20 +1200 Message-Id: <20240529082824.150954-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529082824.150954-1-21cnbao@gmail.com> References: <20240529082824.150954-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: x5cgfndziqo4fms9er6odggwwy7oxdhr X-Rspamd-Queue-Id: 4D62C100013 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1716971340-370988 X-HE-Meta: U2FsdGVkX1/kUqAYv0dNEA1AdTdwi+m+7/yedSLoFx9Myed4jBuZflZw9N5PkempZAcp0SKnXBrlhxfBGiuPTVNTJngnAJg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xqEAafAviKJwrqKCVEyXQLzftdPFIiUimqMlIGtUdMD3+yMNCfUCTFR+17zkH5SS+kvU9a6IhFJN4pKmydtNPbdbz6yT1Ceggm+HU/IhbQreWzHrL+q/Z0yRrmdfFelWeU4xJ7PqOG/CY476LnHkogu2qQL1NacH0YkIIt0ZunXU0mxh1jLV3Tc6Jb12IN8/f2mqH7su9enUgURAhD66r0u0mdn+8fDwpqIfCnRQaVRDhxhs2BCfp/YlWe2YeagGVzLuXoLLbLakvK1w3oSk2bgefcXiDH0casSjkyIJA9lN+y/K695UXX+G9IuM810Yje0bthMQGmtGiC7iV5JL3dcrhSKh7bWdySovTDxfNsESHEJRnRo+gZ4v5pDGUToLRdrE0vO0xDV1YSX7ADdWirKAuXaGb7KtRzQOlJPgHDita9bSBDrQ72QoRkx6KtepOJUumhCpYOjAlaWm8frhbyCIUwK78b3P7iZGP7C1PqlJfjIRQmArsmt8ViK+cUJwCBSwfbbmMmQflt0/ENnxpltelhElP1QbMPf7wwcxkpInXD7mrUuhDtqW3rzID7p6xDz7OjigZXnU6CBxKEYtZlbhkrWKrNMl7kvoAGe5ms7umsS3X4Glpna0h+v0Pw00= 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: Barry Song To streamline maintenance efforts, we propose removing the implementation of swap_free(). Instead, we can simply invoke swap_free_nr() with nr set to 1. swap_free_nr() is designed with a bitmap consisting of only one long, resulting in overhead that can be ignored for cases where nr equals 1. A prime candidate for leveraging swap_free_nr() lies within kernel/power/swap.c. Implementing this change facilitates the adoption of batch processing for hibernation. Suggested-by: "Huang, Ying" Signed-off-by: Barry Song Reviewed-by: "Huang, Ying" Acked-by: Chris Li Reviewed-by: Ryan Roberts Cc: "Rafael J. Wysocki" Cc: Pavel Machek Cc: Len Brown Cc: Hugh Dickins Cc: Christoph Hellwig --- include/linux/swap.h | 10 +++++----- kernel/power/swap.c | 5 ++--- mm/swapfile.c | 17 ++++------------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 45f76dfe29b1..3df75d62a835 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -480,7 +480,6 @@ extern int add_swap_count_continuation(swp_entry_t, gfp_t); extern void swap_shmem_alloc(swp_entry_t); extern int swap_duplicate(swp_entry_t); extern int swapcache_prepare(swp_entry_t); -extern void swap_free(swp_entry_t); extern void swap_free_nr(swp_entry_t entry, int nr_pages); extern void swapcache_free_entries(swp_entry_t *entries, int n); extern void free_swap_and_cache_nr(swp_entry_t entry, int nr); @@ -559,10 +558,6 @@ static inline int swapcache_prepare(swp_entry_t swp) return 0; } -static inline void swap_free(swp_entry_t swp) -{ -} - static inline void swap_free_nr(swp_entry_t entry, int nr_pages) { } @@ -611,6 +606,11 @@ static inline void free_swap_and_cache(swp_entry_t entry) free_swap_and_cache_nr(entry, 1); } +static inline void swap_free(swp_entry_t entry) +{ + swap_free_nr(entry, 1); +} + #ifdef CONFIG_MEMCG static inline int mem_cgroup_swappiness(struct mem_cgroup *memcg) { diff --git a/kernel/power/swap.c b/kernel/power/swap.c index d9abb7ab031d..85a8b5f4a081 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c @@ -200,12 +200,11 @@ void free_all_swap_pages(int swap) while ((node = swsusp_extents.rb_node)) { struct swsusp_extent *ext; - unsigned long offset; ext = rb_entry(node, struct swsusp_extent, node); rb_erase(node, &swsusp_extents); - for (offset = ext->start; offset <= ext->end; offset++) - swap_free(swp_entry(swap, offset)); + swap_free_nr(swp_entry(swap, ext->start), + ext->end - ext->start + 1); kfree(ext); } diff --git a/mm/swapfile.c b/mm/swapfile.c index 92a045d34a97..9c6d8e557c0f 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1343,19 +1343,6 @@ static void swap_entry_free(struct swap_info_struct *p, swp_entry_t entry) swap_range_free(p, offset, 1); } -/* - * Caller has made sure that the swap device corresponding to entry - * is still around or has not been recycled. - */ -void swap_free(swp_entry_t entry) -{ - struct swap_info_struct *p; - - p = _swap_info_get(entry); - if (p) - __swap_entry_free(p, entry); -} - static void cluster_swap_free_nr(struct swap_info_struct *sis, unsigned long offset, int nr_pages) { @@ -1385,6 +1372,10 @@ static void cluster_swap_free_nr(struct swap_info_struct *sis, unlock_cluster_or_swap_info(sis, ci); } +/* + * Caller has made sure that the swap device corresponding to entry + * is still around or has not been recycled. + */ void swap_free_nr(swp_entry_t entry, int nr_pages) { int nr;