linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] Cleanups for swap
@ 2021-05-20 13:40 Miaohe Lin
  2021-05-20 13:40 ` [PATCH v2 1/4] mm/swapfile: move get_swap_page_of_type() under CONFIG_HIBERNATION Miaohe Lin
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Miaohe Lin @ 2021-05-20 13:40 UTC (permalink / raw)
  To: akpm; +Cc: willy, linux-kernel, linux-mm, linmiaohe

Hi all,
This series contains just cleanups to remove some unused variables, delete
meaningless forward declarations and so on. More details can be found in
the respective changelogs. Thanks!

v1->v2:
  collect Reviewed-by tag
  get rid of patch "mm/swap: simplify the code of find_get_incore_page()"

Miaohe Lin (4):
  mm/swapfile: move get_swap_page_of_type() under CONFIG_HIBERNATION
  mm/swap: remove unused local variable nr_shadows
  mm/swap_slots.c: delete meaningless forward declarations
  mm/swap: remove unused global variable nr_swapper_spaces

 mm/swap_slots.c |  2 --
 mm/swap_state.c |  8 --------
 mm/swapfile.c   | 48 ++++++++++++++++++++++++------------------------
 3 files changed, 24 insertions(+), 34 deletions(-)

-- 
2.23.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/4] mm/swapfile: move get_swap_page_of_type() under CONFIG_HIBERNATION
  2021-05-20 13:40 [PATCH v2 0/4] Cleanups for swap Miaohe Lin
@ 2021-05-20 13:40 ` Miaohe Lin
  2021-05-20 13:40 ` [PATCH v2 2/4] mm/swap: remove unused local variable nr_shadows Miaohe Lin
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Miaohe Lin @ 2021-05-20 13:40 UTC (permalink / raw)
  To: akpm; +Cc: willy, linux-kernel, linux-mm, linmiaohe

We should move get_swap_page_of_type() under CONFIG_HIBERNATION since the
only caller of this function is now suspend routine.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/swapfile.c | 48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 2aad85751991..4e7628b82e63 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1137,30 +1137,6 @@ int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size)
 	return n_ret;
 }
 
-/* The only caller of this function is now suspend routine */
-swp_entry_t get_swap_page_of_type(int type)
-{
-	struct swap_info_struct *si = swap_type_to_swap_info(type);
-	pgoff_t offset;
-
-	if (!si)
-		goto fail;
-
-	spin_lock(&si->lock);
-	if (si->flags & SWP_WRITEOK) {
-		/* This is called for allocating swap entry, not cache */
-		offset = scan_swap_map(si, 1);
-		if (offset) {
-			atomic_long_dec(&nr_swap_pages);
-			spin_unlock(&si->lock);
-			return swp_entry(type, offset);
-		}
-	}
-	spin_unlock(&si->lock);
-fail:
-	return (swp_entry_t) {0};
-}
-
 static struct swap_info_struct *__swap_info_get(swp_entry_t entry)
 {
 	struct swap_info_struct *p;
@@ -1812,6 +1788,30 @@ int free_swap_and_cache(swp_entry_t entry)
 }
 
 #ifdef CONFIG_HIBERNATION
+
+swp_entry_t get_swap_page_of_type(int type)
+{
+	struct swap_info_struct *si = swap_type_to_swap_info(type);
+	pgoff_t offset;
+
+	if (!si)
+		goto fail;
+
+	spin_lock(&si->lock);
+	if (si->flags & SWP_WRITEOK) {
+		/* This is called for allocating swap entry, not cache */
+		offset = scan_swap_map(si, 1);
+		if (offset) {
+			atomic_long_dec(&nr_swap_pages);
+			spin_unlock(&si->lock);
+			return swp_entry(type, offset);
+		}
+	}
+	spin_unlock(&si->lock);
+fail:
+	return (swp_entry_t) {0};
+}
+
 /*
  * Find the swap type that corresponds to given device (if any).
  *
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/4] mm/swap: remove unused local variable nr_shadows
  2021-05-20 13:40 [PATCH v2 0/4] Cleanups for swap Miaohe Lin
  2021-05-20 13:40 ` [PATCH v2 1/4] mm/swapfile: move get_swap_page_of_type() under CONFIG_HIBERNATION Miaohe Lin
@ 2021-05-20 13:40 ` Miaohe Lin
  2021-05-20 13:40 ` [PATCH v2 3/4] mm/swap_slots.c: delete meaningless forward declarations Miaohe Lin
  2021-05-20 13:40 ` [PATCH v2 4/4] mm/swap: remove unused global variable nr_swapper_spaces Miaohe Lin
  3 siblings, 0 replies; 5+ messages in thread
From: Miaohe Lin @ 2021-05-20 13:40 UTC (permalink / raw)
  To: akpm; +Cc: willy, linux-kernel, linux-mm, linmiaohe

Since commit 55c653b71e8c ("mm: stop accounting shadow entries"),
nr_shadows is not used anymore.

Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/swap_state.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/mm/swap_state.c b/mm/swap_state.c
index df5405384520..1a2ba4056f37 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -114,8 +114,6 @@ int add_to_swap_cache(struct page *page, swp_entry_t entry,
 	SetPageSwapCache(page);
 
 	do {
-		unsigned long nr_shadows = 0;
-
 		xas_lock_irq(&xas);
 		xas_create_range(&xas);
 		if (xas_error(&xas))
@@ -124,7 +122,6 @@ int add_to_swap_cache(struct page *page, swp_entry_t entry,
 			VM_BUG_ON_PAGE(xas.xa_index != idx + i, page);
 			old = xas_load(&xas);
 			if (xa_is_value(old)) {
-				nr_shadows++;
 				if (shadowp)
 					*shadowp = old;
 			}
@@ -260,7 +257,6 @@ void clear_shadow_from_swap_cache(int type, unsigned long begin,
 	void *old;
 
 	for (;;) {
-		unsigned long nr_shadows = 0;
 		swp_entry_t entry = swp_entry(type, curr);
 		struct address_space *address_space = swap_address_space(entry);
 		XA_STATE(xas, &address_space->i_pages, curr);
@@ -270,7 +266,6 @@ void clear_shadow_from_swap_cache(int type, unsigned long begin,
 			if (!xa_is_value(old))
 				continue;
 			xas_store(&xas, NULL);
-			nr_shadows++;
 		}
 		xa_unlock_irq(&address_space->i_pages);
 
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 3/4] mm/swap_slots.c: delete meaningless forward declarations
  2021-05-20 13:40 [PATCH v2 0/4] Cleanups for swap Miaohe Lin
  2021-05-20 13:40 ` [PATCH v2 1/4] mm/swapfile: move get_swap_page_of_type() under CONFIG_HIBERNATION Miaohe Lin
  2021-05-20 13:40 ` [PATCH v2 2/4] mm/swap: remove unused local variable nr_shadows Miaohe Lin
@ 2021-05-20 13:40 ` Miaohe Lin
  2021-05-20 13:40 ` [PATCH v2 4/4] mm/swap: remove unused global variable nr_swapper_spaces Miaohe Lin
  3 siblings, 0 replies; 5+ messages in thread
From: Miaohe Lin @ 2021-05-20 13:40 UTC (permalink / raw)
  To: akpm; +Cc: willy, linux-kernel, linux-mm, linmiaohe

deactivate_swap_slots_cache() and reactivate_swap_slots_cache() are only
called below their implementations. So these forward declarations are
meaningless and should be removed.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/swap_slots.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/mm/swap_slots.c b/mm/swap_slots.c
index 6248d1030a9b..a66f3e0ec973 100644
--- a/mm/swap_slots.c
+++ b/mm/swap_slots.c
@@ -43,8 +43,6 @@ static DEFINE_MUTEX(swap_slots_cache_mutex);
 static DEFINE_MUTEX(swap_slots_cache_enable_mutex);
 
 static void __drain_swap_slots_cache(unsigned int type);
-static void deactivate_swap_slots_cache(void);
-static void reactivate_swap_slots_cache(void);
 
 #define use_swap_slot_cache (swap_slot_cache_active && swap_slot_cache_enabled)
 #define SLOTS_CACHE 0x1
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 4/4] mm/swap: remove unused global variable nr_swapper_spaces
  2021-05-20 13:40 [PATCH v2 0/4] Cleanups for swap Miaohe Lin
                   ` (2 preceding siblings ...)
  2021-05-20 13:40 ` [PATCH v2 3/4] mm/swap_slots.c: delete meaningless forward declarations Miaohe Lin
@ 2021-05-20 13:40 ` Miaohe Lin
  3 siblings, 0 replies; 5+ messages in thread
From: Miaohe Lin @ 2021-05-20 13:40 UTC (permalink / raw)
  To: akpm; +Cc: willy, linux-kernel, linux-mm, linmiaohe

Since commit b6038942480e ("mm: memcg: add swapcache stat for memcg v2"),
the last user of nr_swapper_spaces is gone. So we remove this unused one.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/swap_state.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/mm/swap_state.c b/mm/swap_state.c
index 1a2ba4056f37..b5a3dc8f47a1 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -37,7 +37,6 @@ static const struct address_space_operations swap_aops = {
 };
 
 struct address_space *swapper_spaces[MAX_SWAPFILES] __read_mostly;
-static unsigned int nr_swapper_spaces[MAX_SWAPFILES] __read_mostly;
 static bool enable_vma_readahead __read_mostly = true;
 
 #define SWAP_RA_WIN_SHIFT	(PAGE_SHIFT / 2)
@@ -685,7 +684,6 @@ int init_swap_address_space(unsigned int type, unsigned long nr_pages)
 		/* swap cache doesn't use writeback related tags */
 		mapping_set_no_writeback_tags(space);
 	}
-	nr_swapper_spaces[type] = nr;
 	swapper_spaces[type] = spaces;
 
 	return 0;
@@ -694,7 +692,6 @@ int init_swap_address_space(unsigned int type, unsigned long nr_pages)
 void exit_swap_address_space(unsigned int type)
 {
 	kvfree(swapper_spaces[type]);
-	nr_swapper_spaces[type] = 0;
 	swapper_spaces[type] = NULL;
 }
 
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-20 13:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20 13:40 [PATCH v2 0/4] Cleanups for swap Miaohe Lin
2021-05-20 13:40 ` [PATCH v2 1/4] mm/swapfile: move get_swap_page_of_type() under CONFIG_HIBERNATION Miaohe Lin
2021-05-20 13:40 ` [PATCH v2 2/4] mm/swap: remove unused local variable nr_shadows Miaohe Lin
2021-05-20 13:40 ` [PATCH v2 3/4] mm/swap_slots.c: delete meaningless forward declarations Miaohe Lin
2021-05-20 13:40 ` [PATCH v2 4/4] mm/swap: remove unused global variable nr_swapper_spaces Miaohe Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).