* [PATCH 1/5] mm/swapfile: move get_swap_page_of_type() under CONFIG_HIBERNATION
2021-05-18 13:53 [PATCH 0/5] Cleanups for swap Miaohe Lin
@ 2021-05-18 13:53 ` Miaohe Lin
2021-05-18 13:53 ` [PATCH 2/5] mm/swap: remove unused local variable nr_shadows Miaohe Lin
` (3 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: Miaohe Lin @ 2021-05-18 13:53 UTC (permalink / raw)
To: akpm; +Cc: 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] 12+ messages in thread
* [PATCH 2/5] mm/swap: remove unused local variable nr_shadows
2021-05-18 13:53 [PATCH 0/5] Cleanups for swap Miaohe Lin
2021-05-18 13:53 ` [PATCH 1/5] mm/swapfile: move get_swap_page_of_type() under CONFIG_HIBERNATION Miaohe Lin
@ 2021-05-18 13:53 ` Miaohe Lin
2021-05-18 14:37 ` Matthew Wilcox
2021-05-18 13:53 ` [PATCH 3/5] mm/swap_slots.c: delete meaningless forward declarations Miaohe Lin
` (2 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Miaohe Lin @ 2021-05-18 13:53 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel, linux-mm, linmiaohe
Since commit 55c653b71e8c ("mm: stop accounting shadow entries"),
nr_shadows is not used anymore.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
mm/swap_state.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/mm/swap_state.c b/mm/swap_state.c
index df5405384520..bab386c7b655 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -114,7 +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);
@@ -124,7 +123,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 +258,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 +267,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] 12+ messages in thread
* Re: [PATCH 2/5] mm/swap: remove unused local variable nr_shadows
2021-05-18 13:53 ` [PATCH 2/5] mm/swap: remove unused local variable nr_shadows Miaohe Lin
@ 2021-05-18 14:37 ` Matthew Wilcox
2021-05-19 1:37 ` Miaohe Lin
0 siblings, 1 reply; 12+ messages in thread
From: Matthew Wilcox @ 2021-05-18 14:37 UTC (permalink / raw)
To: Miaohe Lin; +Cc: akpm, linux-kernel, linux-mm
On Tue, May 18, 2021 at 09:53:49PM +0800, Miaohe Lin wrote:
> Since commit 55c653b71e8c ("mm: stop accounting shadow entries"),
> nr_shadows is not used anymore.
>
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> +++ b/mm/swap_state.c
> @@ -114,7 +114,6 @@ int add_to_swap_cache(struct page *page, swp_entry_t entry,
> SetPageSwapCache(page);
>
> do {
> - unsigned long nr_shadows = 0;
>
Perhaps delete the blank line as well?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/5] mm/swap: remove unused local variable nr_shadows
2021-05-18 14:37 ` Matthew Wilcox
@ 2021-05-19 1:37 ` Miaohe Lin
0 siblings, 0 replies; 12+ messages in thread
From: Miaohe Lin @ 2021-05-19 1:37 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: akpm, linux-kernel, linux-mm
On 2021/5/18 22:37, Matthew Wilcox wrote:
> On Tue, May 18, 2021 at 09:53:49PM +0800, Miaohe Lin wrote:
>> Since commit 55c653b71e8c ("mm: stop accounting shadow entries"),
>> nr_shadows is not used anymore.
>>
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>
> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
>
>> +++ b/mm/swap_state.c
>> @@ -114,7 +114,6 @@ int add_to_swap_cache(struct page *page, swp_entry_t entry,
>> SetPageSwapCache(page);
>>
>> do {
>> - unsigned long nr_shadows = 0;
>>
>
> Perhaps delete the blank line as well?
Will do. Many thanks for the review.
>
> .
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 3/5] mm/swap_slots.c: delete meaningless forward declarations
2021-05-18 13:53 [PATCH 0/5] Cleanups for swap Miaohe Lin
2021-05-18 13:53 ` [PATCH 1/5] mm/swapfile: move get_swap_page_of_type() under CONFIG_HIBERNATION Miaohe Lin
2021-05-18 13:53 ` [PATCH 2/5] mm/swap: remove unused local variable nr_shadows Miaohe Lin
@ 2021-05-18 13:53 ` Miaohe Lin
2021-05-18 13:53 ` [PATCH 4/5] mm/swap: remove unused global variable nr_swapper_spaces Miaohe Lin
2021-05-18 13:53 ` [PATCH 5/5] mm/swap: simplify the code of find_get_incore_page() Miaohe Lin
4 siblings, 0 replies; 12+ messages in thread
From: Miaohe Lin @ 2021-05-18 13:53 UTC (permalink / raw)
To: akpm; +Cc: 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] 12+ messages in thread
* [PATCH 4/5] mm/swap: remove unused global variable nr_swapper_spaces
2021-05-18 13:53 [PATCH 0/5] Cleanups for swap Miaohe Lin
` (2 preceding siblings ...)
2021-05-18 13:53 ` [PATCH 3/5] mm/swap_slots.c: delete meaningless forward declarations Miaohe Lin
@ 2021-05-18 13:53 ` Miaohe Lin
2021-05-18 13:53 ` [PATCH 5/5] mm/swap: simplify the code of find_get_incore_page() Miaohe Lin
4 siblings, 0 replies; 12+ messages in thread
From: Miaohe Lin @ 2021-05-18 13:53 UTC (permalink / raw)
To: akpm; +Cc: 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 bab386c7b655..a55b7b74b0e6 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)
@@ -686,7 +685,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;
@@ -695,7 +693,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] 12+ messages in thread
* [PATCH 5/5] mm/swap: simplify the code of find_get_incore_page()
2021-05-18 13:53 [PATCH 0/5] Cleanups for swap Miaohe Lin
` (3 preceding siblings ...)
2021-05-18 13:53 ` [PATCH 4/5] mm/swap: remove unused global variable nr_swapper_spaces Miaohe Lin
@ 2021-05-18 13:53 ` Miaohe Lin
2021-05-18 14:33 ` Matthew Wilcox
4 siblings, 1 reply; 12+ messages in thread
From: Miaohe Lin @ 2021-05-18 13:53 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel, linux-mm, linmiaohe
pagecache_get_page() can do find_subpage() for us if we do not specify
FGP_HEAD. No functional change intended.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
mm/swap_state.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/mm/swap_state.c b/mm/swap_state.c
index a55b7b74b0e6..bc92e4893fec 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -394,13 +394,11 @@ struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index)
{
swp_entry_t swp;
struct swap_info_struct *si;
- struct page *page = pagecache_get_page(mapping, index,
- FGP_ENTRY | FGP_HEAD, 0);
+ struct page *page = pagecache_get_page(mapping, index, FGP_ENTRY, 0);
- if (!page)
+ if (!page || !xa_is_value(page))
return page;
- if (!xa_is_value(page))
- return find_subpage(page, index);
+
if (!shmem_mapping(mapping))
return NULL;
--
2.23.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 5/5] mm/swap: simplify the code of find_get_incore_page()
2021-05-18 13:53 ` [PATCH 5/5] mm/swap: simplify the code of find_get_incore_page() Miaohe Lin
@ 2021-05-18 14:33 ` Matthew Wilcox
2021-05-18 21:13 ` Andrew Morton
0 siblings, 1 reply; 12+ messages in thread
From: Matthew Wilcox @ 2021-05-18 14:33 UTC (permalink / raw)
To: Miaohe Lin; +Cc: akpm, linux-kernel, linux-mm
On Tue, May 18, 2021 at 09:53:52PM +0800, Miaohe Lin wrote:
> pagecache_get_page() can do find_subpage() for us if we do not specify
> FGP_HEAD. No functional change intended.
Please, no. This interferes with the folio work.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 5/5] mm/swap: simplify the code of find_get_incore_page()
2021-05-18 14:33 ` Matthew Wilcox
@ 2021-05-18 21:13 ` Andrew Morton
2021-05-18 21:34 ` Matthew Wilcox
0 siblings, 1 reply; 12+ messages in thread
From: Andrew Morton @ 2021-05-18 21:13 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: Miaohe Lin, linux-kernel, linux-mm
On Tue, 18 May 2021 15:33:54 +0100 Matthew Wilcox <willy@infradead.org> wrote:
> On Tue, May 18, 2021 at 09:53:52PM +0800, Miaohe Lin wrote:
> > pagecache_get_page() can do find_subpage() for us if we do not specify
> > FGP_HEAD. No functional change intended.
>
> Please, no. This interferes with the folio work.
In what way? Can't the folio patches simply revert this or suitably
alter it?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 5/5] mm/swap: simplify the code of find_get_incore_page()
2021-05-18 21:13 ` Andrew Morton
@ 2021-05-18 21:34 ` Matthew Wilcox
2021-05-19 1:39 ` Miaohe Lin
0 siblings, 1 reply; 12+ messages in thread
From: Matthew Wilcox @ 2021-05-18 21:34 UTC (permalink / raw)
To: Andrew Morton; +Cc: Miaohe Lin, linux-kernel, linux-mm
On Tue, May 18, 2021 at 02:13:04PM -0700, Andrew Morton wrote:
> On Tue, 18 May 2021 15:33:54 +0100 Matthew Wilcox <willy@infradead.org> wrote:
>
> > On Tue, May 18, 2021 at 09:53:52PM +0800, Miaohe Lin wrote:
> > > pagecache_get_page() can do find_subpage() for us if we do not specify
> > > FGP_HEAD. No functional change intended.
> >
> > Please, no. This interferes with the folio work.
>
> In what way? Can't the folio patches simply revert this or suitably
> alter it?
Of course, it's just software. Anything can just be modified. I don't
see the point of putting in a cleanup patch that creates a conflict with
important work.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 5/5] mm/swap: simplify the code of find_get_incore_page()
2021-05-18 21:34 ` Matthew Wilcox
@ 2021-05-19 1:39 ` Miaohe Lin
0 siblings, 0 replies; 12+ messages in thread
From: Miaohe Lin @ 2021-05-19 1:39 UTC (permalink / raw)
To: Matthew Wilcox, Andrew Morton; +Cc: linux-kernel, linux-mm
On 2021/5/19 5:34, Matthew Wilcox wrote:
> On Tue, May 18, 2021 at 02:13:04PM -0700, Andrew Morton wrote:
>> On Tue, 18 May 2021 15:33:54 +0100 Matthew Wilcox <willy@infradead.org> wrote:
>>
>>> On Tue, May 18, 2021 at 09:53:52PM +0800, Miaohe Lin wrote:
>>>> pagecache_get_page() can do find_subpage() for us if we do not specify
>>>> FGP_HEAD. No functional change intended.
>>>
>>> Please, no. This interferes with the folio work.
>>
>> In what way? Can't the folio patches simply revert this or suitably
>> alter it?
>
> Of course, it's just software. Anything can just be modified. I don't
> see the point of putting in a cleanup patch that creates a conflict with
> important work.
I could hold this patch out until folio work is done if you ask for it.
Thanks.
> .
>
^ permalink raw reply [flat|nested] 12+ messages in thread