All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] A few fixup patches for swap
@ 2022-05-27  9:26 Miaohe Lin
  2022-05-27  9:26 ` [PATCH 1/3] mm/swapfile: make security_vm_enough_memory_mm() work as expected Miaohe Lin
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Miaohe Lin @ 2022-05-27  9:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, linmiaohe

Hi everyone,
This series contains a few fixup patches to avoid confusing swap cache
statistics, fix possible data races of inuse_pages and so on. More
details can be found in the respective changelogs. Thanks!

Miaohe Lin (3):
  mm/swapfile: make security_vm_enough_memory_mm() work as expected
  mm/swapfile: avoid confusing swap cache statistics
  mm/swapfile: fix possible data races of inuse_pages

 mm/swapfile.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

-- 
2.23.0


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

* [PATCH 1/3] mm/swapfile: make security_vm_enough_memory_mm() work as expected
  2022-05-27  9:26 [PATCH 0/3] A few fixup patches for swap Miaohe Lin
@ 2022-05-27  9:26 ` Miaohe Lin
  2022-05-30 23:02   ` Andrew Morton
  2022-05-27  9:26 ` [PATCH 2/3] mm/swapfile: avoid confusing swap cache statistics Miaohe Lin
  2022-05-27  9:26 ` [PATCH 3/3] mm/swapfile: fix possible data races of inuse_pages Miaohe Lin
  2 siblings, 1 reply; 15+ messages in thread
From: Miaohe Lin @ 2022-05-27  9:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, linmiaohe

security_vm_enough_memory_mm() checks whether a process has enough memory
to allocate a new virtual mapping. And total_swap_pages is considered as
available memory while swapoff tries to make sure there's enough memory
that can hold the swapped out memory. But total_swap_pages contains the
swap space that is being swapoff. So security_vm_enough_memory_mm() will
success even if there's no memory to hold the swapped out memory because
total_swap_pages always greater than or equal to p->pages.

In order to fix it, p->pages should be retracted from total_swap_pages
first and then check whether there's enough memory for inuse swap pages.

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

diff --git a/mm/swapfile.c b/mm/swapfile.c
index a2e66d855b19..960d14a4b19e 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2396,6 +2396,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
 	struct filename *pathname;
 	int err, found = 0;
 	unsigned int old_block_size;
+	unsigned int inuse_pages;
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
@@ -2426,9 +2427,13 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
 		spin_unlock(&swap_lock);
 		goto out_dput;
 	}
-	if (!security_vm_enough_memory_mm(current->mm, p->pages))
-		vm_unacct_memory(p->pages);
+
+	total_swap_pages -= p->pages;
+	inuse_pages = READ_ONCE(p->inuse_pages);
+	if (!security_vm_enough_memory_mm(current->mm, inuse_pages))
+		vm_unacct_memory(inuse_pages);
 	else {
+		total_swap_pages += p->pages;
 		err = -ENOMEM;
 		spin_unlock(&swap_lock);
 		goto out_dput;
@@ -2451,7 +2456,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
 	}
 	plist_del(&p->list, &swap_active_head);
 	atomic_long_sub(p->pages, &nr_swap_pages);
-	total_swap_pages -= p->pages;
 	p->flags &= ~SWP_WRITEOK;
 	spin_unlock(&p->lock);
 	spin_unlock(&swap_lock);
-- 
2.23.0


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

* [PATCH 2/3] mm/swapfile: avoid confusing swap cache statistics
  2022-05-27  9:26 [PATCH 0/3] A few fixup patches for swap Miaohe Lin
  2022-05-27  9:26 ` [PATCH 1/3] mm/swapfile: make security_vm_enough_memory_mm() work as expected Miaohe Lin
@ 2022-05-27  9:26 ` Miaohe Lin
  2022-05-30 23:04   ` Andrew Morton
  2022-05-27  9:26 ` [PATCH 3/3] mm/swapfile: fix possible data races of inuse_pages Miaohe Lin
  2 siblings, 1 reply; 15+ messages in thread
From: Miaohe Lin @ 2022-05-27  9:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, linmiaohe

At swapoff time, we're going to swap in the pages continuously. So calling
lookup_swap_cache would confuse statistics. We should use find_get_page
directly here.

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

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 960d14a4b19e..e033a53a99df 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1865,7 +1865,12 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
 		offset = swp_offset(entry);
 		pte_unmap(pte);
 		swap_map = &si->swap_map[offset];
-		page = lookup_swap_cache(entry, vma, addr);
+		/*
+		 * Since we're going to swap in the pages continuously,
+		 * calling lookup_swap_cache() would confuse statistics.
+		 */
+		page = find_get_page(swap_address_space(entry),
+				     swp_offset(entry));
 		if (!page) {
 			struct vm_fault vmf = {
 				.vma = vma,
-- 
2.23.0


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

* [PATCH 3/3] mm/swapfile: fix possible data races of inuse_pages
  2022-05-27  9:26 [PATCH 0/3] A few fixup patches for swap Miaohe Lin
  2022-05-27  9:26 ` [PATCH 1/3] mm/swapfile: make security_vm_enough_memory_mm() work as expected Miaohe Lin
  2022-05-27  9:26 ` [PATCH 2/3] mm/swapfile: avoid confusing swap cache statistics Miaohe Lin
@ 2022-05-27  9:26 ` Miaohe Lin
  2022-05-31 13:02   ` David Hildenbrand
  2 siblings, 1 reply; 15+ messages in thread
From: Miaohe Lin @ 2022-05-27  9:26 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, linmiaohe

si->inuse_pages could still be accessed concurrently now. The plain reads
outside si->lock critical section, i.e. swap_show and si_swapinfo, which
results in data races. But these should be ok because they're just used
for showing swap info.

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

diff --git a/mm/swapfile.c b/mm/swapfile.c
index e033a53a99df..29d7ca9eaa3c 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2649,7 +2649,7 @@ static int swap_show(struct seq_file *swap, void *v)
 	}
 
 	bytes = si->pages << (PAGE_SHIFT - 10);
-	inuse = si->inuse_pages << (PAGE_SHIFT - 10);
+	inuse = READ_ONCE(si->inuse_pages) << (PAGE_SHIFT - 10);
 
 	file = si->swap_file;
 	len = seq_file_path(swap, file, " \t\n\\");
@@ -3268,7 +3268,7 @@ void si_swapinfo(struct sysinfo *val)
 		struct swap_info_struct *si = swap_info[type];
 
 		if ((si->flags & SWP_USED) && !(si->flags & SWP_WRITEOK))
-			nr_to_be_unused += si->inuse_pages;
+			nr_to_be_unused += READ_ONCE(si->inuse_pages);
 	}
 	val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
 	val->totalswap = total_swap_pages + nr_to_be_unused;
-- 
2.23.0


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

* Re: [PATCH 1/3] mm/swapfile: make security_vm_enough_memory_mm() work as expected
  2022-05-27  9:26 ` [PATCH 1/3] mm/swapfile: make security_vm_enough_memory_mm() work as expected Miaohe Lin
@ 2022-05-30 23:02   ` Andrew Morton
  2022-05-31  2:40     ` Miaohe Lin
  0 siblings, 1 reply; 15+ messages in thread
From: Andrew Morton @ 2022-05-30 23:02 UTC (permalink / raw)
  To: Miaohe Lin; +Cc: linux-mm, linux-kernel

On Fri, 27 May 2022 17:26:24 +0800 Miaohe Lin <linmiaohe@huawei.com> wrote:

> security_vm_enough_memory_mm() checks whether a process has enough memory
> to allocate a new virtual mapping. And total_swap_pages is considered as
> available memory while swapoff tries to make sure there's enough memory
> that can hold the swapped out memory. But total_swap_pages contains the
> swap space that is being swapoff. So security_vm_enough_memory_mm() will
> success even if there's no memory to hold the swapped out memory because
> total_swap_pages always greater than or equal to p->pages.
> 
> In order to fix it, p->pages should be retracted from total_swap_pages
> first and then check whether there's enough memory for inuse swap pages.

User-visible impact?

If I'm understanding correctly, there's a risk that this fix will cause
existing setups to newly fail when attempting swapoff()?




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

* Re: [PATCH 2/3] mm/swapfile: avoid confusing swap cache statistics
  2022-05-27  9:26 ` [PATCH 2/3] mm/swapfile: avoid confusing swap cache statistics Miaohe Lin
@ 2022-05-30 23:04   ` Andrew Morton
  2022-05-31  2:55     ` Miaohe Lin
  0 siblings, 1 reply; 15+ messages in thread
From: Andrew Morton @ 2022-05-30 23:04 UTC (permalink / raw)
  To: Miaohe Lin; +Cc: linux-mm, linux-kernel

On Fri, 27 May 2022 17:26:25 +0800 Miaohe Lin <linmiaohe@huawei.com> wrote:

> At swapoff time, we're going to swap in the pages continuously. So calling
> lookup_swap_cache would confuse statistics. We should use find_get_page
> directly here.

Why is the existing behaviour wrong?  swapoff() has to swap stuff in to
be able to release the swap device.  Why do you believe that this
swapin activity should not be accounted?



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

* Re: [PATCH 1/3] mm/swapfile: make security_vm_enough_memory_mm() work as expected
  2022-05-30 23:02   ` Andrew Morton
@ 2022-05-31  2:40     ` Miaohe Lin
  0 siblings, 0 replies; 15+ messages in thread
From: Miaohe Lin @ 2022-05-31  2:40 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel

On 2022/5/31 7:02, Andrew Morton wrote:
> On Fri, 27 May 2022 17:26:24 +0800 Miaohe Lin <linmiaohe@huawei.com> wrote:
> 
>> security_vm_enough_memory_mm() checks whether a process has enough memory
>> to allocate a new virtual mapping. And total_swap_pages is considered as
>> available memory while swapoff tries to make sure there's enough memory
>> that can hold the swapped out memory. But total_swap_pages contains the
>> swap space that is being swapoff. So security_vm_enough_memory_mm() will
>> success even if there's no memory to hold the swapped out memory because
>> total_swap_pages always greater than or equal to p->pages.
>>
>> In order to fix it, p->pages should be retracted from total_swap_pages
>> first and then check whether there's enough memory for inuse swap pages.
> 
> User-visible impact?

With this change, swapping in pages is not even tried if there's no enough memory.
But in user's view, swapoff() is failed just like before when there's no enough memory.

> 
> If I'm understanding correctly, there's a risk that this fix will cause
> existing setups to newly fail when attempting swapoff()?

IIUC, the previous behavior would be:
Failing swapoff() after swapping in many pages due to lacking of physical memory, though
security_vm_enough_memory_mm() always tell us there's enough memory.

The changed behavior will be:
Failing swapoff() *without* swapping in many pages according to the right conclusion
of security_vm_enough_memory_mm().

IMHO, The final result should be same, but security_vm_enough_memory_mm() can tell us
whether we could succeed to swapoff() with this patch. Or am I miss something?

Many thanks for comment and reply!

> 
> 
> 
> .
> 


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

* Re: [PATCH 2/3] mm/swapfile: avoid confusing swap cache statistics
  2022-05-30 23:04   ` Andrew Morton
@ 2022-05-31  2:55     ` Miaohe Lin
  2022-05-31 12:58       ` David Hildenbrand
  0 siblings, 1 reply; 15+ messages in thread
From: Miaohe Lin @ 2022-05-31  2:55 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel

On 2022/5/31 7:04, Andrew Morton wrote:
> On Fri, 27 May 2022 17:26:25 +0800 Miaohe Lin <linmiaohe@huawei.com> wrote:
> 
>> At swapoff time, we're going to swap in the pages continuously. So calling
>> lookup_swap_cache would confuse statistics. We should use find_get_page
>> directly here.
> 
> Why is the existing behaviour wrong?  swapoff() has to swap stuff in to
> be able to release the swap device.  Why do you believe that this
> swapin activity should not be accounted?

IMHO, statistics, e.g. swap_cache_info.find_success, are used to show the effectiveness
of the swap cache activity. So they should only reflect the memory accessing activity
of the user. I think swapoff can't reflect the effectiveness of the swap cache activity
because it just swaps in pages one by one. Or statistics should reflect all the activity
of the user including swapoff?

Thanks!

> 
> 
> .
> 


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

* Re: [PATCH 2/3] mm/swapfile: avoid confusing swap cache statistics
  2022-05-31  2:55     ` Miaohe Lin
@ 2022-05-31 12:58       ` David Hildenbrand
  2022-06-01  2:11         ` Miaohe Lin
  0 siblings, 1 reply; 15+ messages in thread
From: David Hildenbrand @ 2022-05-31 12:58 UTC (permalink / raw)
  To: Miaohe Lin, Andrew Morton; +Cc: linux-mm, linux-kernel

On 31.05.22 04:55, Miaohe Lin wrote:
> On 2022/5/31 7:04, Andrew Morton wrote:
>> On Fri, 27 May 2022 17:26:25 +0800 Miaohe Lin <linmiaohe@huawei.com> wrote:
>>
>>> At swapoff time, we're going to swap in the pages continuously. So calling
>>> lookup_swap_cache would confuse statistics. We should use find_get_page
>>> directly here.
>>
>> Why is the existing behaviour wrong?  swapoff() has to swap stuff in to
>> be able to release the swap device.  Why do you believe that this
>> swapin activity should not be accounted?
> 
> IMHO, statistics, e.g. swap_cache_info.find_success, are used to show the effectiveness
> of the swap cache activity. So they should only reflect the memory accessing activity
> of the user. I think swapoff can't reflect the effectiveness of the swap cache activity
> because it just swaps in pages one by one. Or statistics should reflect all the activity
> of the user including swapoff?

I'm wondering who cares and why?


-- 
Thanks,

David / dhildenb


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

* Re: [PATCH 3/3] mm/swapfile: fix possible data races of inuse_pages
  2022-05-27  9:26 ` [PATCH 3/3] mm/swapfile: fix possible data races of inuse_pages Miaohe Lin
@ 2022-05-31 13:02   ` David Hildenbrand
  0 siblings, 0 replies; 15+ messages in thread
From: David Hildenbrand @ 2022-05-31 13:02 UTC (permalink / raw)
  To: Miaohe Lin, akpm; +Cc: linux-mm, linux-kernel

On 27.05.22 11:26, Miaohe Lin wrote:
> si->inuse_pages could still be accessed concurrently now. The plain reads
> outside si->lock critical section, i.e. swap_show and si_swapinfo, which
> results in data races. But these should be ok because they're just used
> for showing swap info.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  mm/swapfile.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index e033a53a99df..29d7ca9eaa3c 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -2649,7 +2649,7 @@ static int swap_show(struct seq_file *swap, void *v)
>  	}
>  
>  	bytes = si->pages << (PAGE_SHIFT - 10);
> -	inuse = si->inuse_pages << (PAGE_SHIFT - 10);
> +	inuse = READ_ONCE(si->inuse_pages) << (PAGE_SHIFT - 10);
>  
>  	file = si->swap_file;
>  	len = seq_file_path(swap, file, " \t\n\\");
> @@ -3268,7 +3268,7 @@ void si_swapinfo(struct sysinfo *val)
>  		struct swap_info_struct *si = swap_info[type];
>  
>  		if ((si->flags & SWP_USED) && !(si->flags & SWP_WRITEOK))
> -			nr_to_be_unused += si->inuse_pages;
> +			nr_to_be_unused += READ_ONCE(si->inuse_pages);
>  	}
>  	val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
>  	val->totalswap = total_swap_pages + nr_to_be_unused;


AFAIKT, this makes sense

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb


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

* Re: [PATCH 2/3] mm/swapfile: avoid confusing swap cache statistics
  2022-05-31 12:58       ` David Hildenbrand
@ 2022-06-01  2:11         ` Miaohe Lin
  2022-06-01  7:53           ` David Hildenbrand
  0 siblings, 1 reply; 15+ messages in thread
From: Miaohe Lin @ 2022-06-01  2:11 UTC (permalink / raw)
  To: David Hildenbrand, Andrew Morton; +Cc: linux-mm, linux-kernel

On 2022/5/31 20:58, David Hildenbrand wrote:
> On 31.05.22 04:55, Miaohe Lin wrote:
>> On 2022/5/31 7:04, Andrew Morton wrote:
>>> On Fri, 27 May 2022 17:26:25 +0800 Miaohe Lin <linmiaohe@huawei.com> wrote:
>>>
>>>> At swapoff time, we're going to swap in the pages continuously. So calling
>>>> lookup_swap_cache would confuse statistics. We should use find_get_page
>>>> directly here.
>>>
>>> Why is the existing behaviour wrong?  swapoff() has to swap stuff in to
>>> be able to release the swap device.  Why do you believe that this
>>> swapin activity should not be accounted?
>>
>> IMHO, statistics, e.g. swap_cache_info.find_success, are used to show the effectiveness
>> of the swap cache activity. So they should only reflect the memory accessing activity
>> of the user. I think swapoff can't reflect the effectiveness of the swap cache activity
>> because it just swaps in pages one by one. Or statistics should reflect all the activity
>> of the user including swapoff?
> 
> I'm wondering who cares and why?

I thought it's used to show the effectiveness of the swapcache readahead algorithm. If nobody
ever cares about it now, I'm fine to drop this patch. And could these statistics be removed
since nobody cares about it?

Thanks!

> 
> 


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

* Re: [PATCH 2/3] mm/swapfile: avoid confusing swap cache statistics
  2022-06-01  2:11         ` Miaohe Lin
@ 2022-06-01  7:53           ` David Hildenbrand
  2022-06-02  7:29             ` Miaohe Lin
  0 siblings, 1 reply; 15+ messages in thread
From: David Hildenbrand @ 2022-06-01  7:53 UTC (permalink / raw)
  To: Miaohe Lin, Andrew Morton; +Cc: linux-mm, linux-kernel, Hugh Dickins

On 01.06.22 04:11, Miaohe Lin wrote:
> On 2022/5/31 20:58, David Hildenbrand wrote:
>> On 31.05.22 04:55, Miaohe Lin wrote:
>>> On 2022/5/31 7:04, Andrew Morton wrote:
>>>> On Fri, 27 May 2022 17:26:25 +0800 Miaohe Lin <linmiaohe@huawei.com> wrote:
>>>>
>>>>> At swapoff time, we're going to swap in the pages continuously. So calling
>>>>> lookup_swap_cache would confuse statistics. We should use find_get_page
>>>>> directly here.
>>>>
>>>> Why is the existing behaviour wrong?  swapoff() has to swap stuff in to
>>>> be able to release the swap device.  Why do you believe that this
>>>> swapin activity should not be accounted?
>>>
>>> IMHO, statistics, e.g. swap_cache_info.find_success, are used to show the effectiveness
>>> of the swap cache activity. So they should only reflect the memory accessing activity
>>> of the user. I think swapoff can't reflect the effectiveness of the swap cache activity
>>> because it just swaps in pages one by one. Or statistics should reflect all the activity
>>> of the user including swapoff?
>>
>> I'm wondering who cares and why?
> 
> I thought it's used to show the effectiveness of the swapcache readahead algorithm. If nobody
> ever cares about it now, I'm fine to drop this patch. And could these statistics be removed
> since nobody cares about it?

IIUC, they are printed (via show_swap_cache_info()), which is called via
show_free_areas() -- primarily used via show_mem(). show_mem() is
primarily used when OOM, when allocation fails and we warn, from the OOM
killer, on panic().

I am not sure how useful for (OOM ?) debugging the find_success vs.
find_total stats are at all. They are from ancient times. In
bb63be0a091c ("tmpfs: move swap_state stats update") we removed other
statistics that are "are relics of my 2.4.11 testing". Maybe
find_success and find_total can be similarly removed.

data_race() indicates to me that these stats are somewhat best-effort
already.

-- 
Thanks,

David / dhildenb


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

* Re: [PATCH 2/3] mm/swapfile: avoid confusing swap cache statistics
  2022-06-01  7:53           ` David Hildenbrand
@ 2022-06-02  7:29             ` Miaohe Lin
  2022-06-02  8:41               ` David Hildenbrand
  0 siblings, 1 reply; 15+ messages in thread
From: Miaohe Lin @ 2022-06-02  7:29 UTC (permalink / raw)
  To: David Hildenbrand; +Cc: linux-mm, linux-kernel, Hugh Dickins, Andrew Morton

On 2022/6/1 15:53, David Hildenbrand wrote:
> On 01.06.22 04:11, Miaohe Lin wrote:
>> On 2022/5/31 20:58, David Hildenbrand wrote:
>>> On 31.05.22 04:55, Miaohe Lin wrote:
>>>> On 2022/5/31 7:04, Andrew Morton wrote:
>>>>> On Fri, 27 May 2022 17:26:25 +0800 Miaohe Lin <linmiaohe@huawei.com> wrote:
>>>>>
>>>>>> At swapoff time, we're going to swap in the pages continuously. So calling
>>>>>> lookup_swap_cache would confuse statistics. We should use find_get_page
>>>>>> directly here.
>>>>>
>>>>> Why is the existing behaviour wrong?  swapoff() has to swap stuff in to
>>>>> be able to release the swap device.  Why do you believe that this
>>>>> swapin activity should not be accounted?
>>>>
>>>> IMHO, statistics, e.g. swap_cache_info.find_success, are used to show the effectiveness
>>>> of the swap cache activity. So they should only reflect the memory accessing activity
>>>> of the user. I think swapoff can't reflect the effectiveness of the swap cache activity
>>>> because it just swaps in pages one by one. Or statistics should reflect all the activity
>>>> of the user including swapoff?
>>>
>>> I'm wondering who cares and why?
>>
>> I thought it's used to show the effectiveness of the swapcache readahead algorithm. If nobody
>> ever cares about it now, I'm fine to drop this patch. And could these statistics be removed
>> since nobody cares about it?
> 
> IIUC, they are printed (via show_swap_cache_info()), which is called via
> show_free_areas() -- primarily used via show_mem(). show_mem() is
> primarily used when OOM, when allocation fails and we warn, from the OOM
> killer, on panic().
> 
> I am not sure how useful for (OOM ?) debugging the find_success vs.
> find_total stats are at all. They are from ancient times. In
> bb63be0a091c ("tmpfs: move swap_state stats update") we removed other
> statistics that are "are relics of my 2.4.11 testing". Maybe
> find_success and find_total can be similarly removed.

Maybe add_total, del_total, find_success and find_total should be similarly removed altogether?
It seems those can't provide useful info when OOM occurs? And we can thus avoid touching the
swap_cache_info cacheline.

> 
> data_race() indicates to me that these stats are somewhat best-effort
> already.

At least, this patch seems unneeded.

Thanks!

> 

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

* Re: [PATCH 2/3] mm/swapfile: avoid confusing swap cache statistics
  2022-06-02  7:29             ` Miaohe Lin
@ 2022-06-02  8:41               ` David Hildenbrand
  2022-06-06  3:14                 ` Miaohe Lin
  0 siblings, 1 reply; 15+ messages in thread
From: David Hildenbrand @ 2022-06-02  8:41 UTC (permalink / raw)
  To: Miaohe Lin; +Cc: linux-mm, linux-kernel, Hugh Dickins, Andrew Morton

On 02.06.22 09:29, Miaohe Lin wrote:
> On 2022/6/1 15:53, David Hildenbrand wrote:
>> On 01.06.22 04:11, Miaohe Lin wrote:
>>> On 2022/5/31 20:58, David Hildenbrand wrote:
>>>> On 31.05.22 04:55, Miaohe Lin wrote:
>>>>> On 2022/5/31 7:04, Andrew Morton wrote:
>>>>>> On Fri, 27 May 2022 17:26:25 +0800 Miaohe Lin <linmiaohe@huawei.com> wrote:
>>>>>>
>>>>>>> At swapoff time, we're going to swap in the pages continuously. So calling
>>>>>>> lookup_swap_cache would confuse statistics. We should use find_get_page
>>>>>>> directly here.
>>>>>>
>>>>>> Why is the existing behaviour wrong?  swapoff() has to swap stuff in to
>>>>>> be able to release the swap device.  Why do you believe that this
>>>>>> swapin activity should not be accounted?
>>>>>
>>>>> IMHO, statistics, e.g. swap_cache_info.find_success, are used to show the effectiveness
>>>>> of the swap cache activity. So they should only reflect the memory accessing activity
>>>>> of the user. I think swapoff can't reflect the effectiveness of the swap cache activity
>>>>> because it just swaps in pages one by one. Or statistics should reflect all the activity
>>>>> of the user including swapoff?
>>>>
>>>> I'm wondering who cares and why?
>>>
>>> I thought it's used to show the effectiveness of the swapcache readahead algorithm. If nobody
>>> ever cares about it now, I'm fine to drop this patch. And could these statistics be removed
>>> since nobody cares about it?
>>
>> IIUC, they are printed (via show_swap_cache_info()), which is called via
>> show_free_areas() -- primarily used via show_mem(). show_mem() is
>> primarily used when OOM, when allocation fails and we warn, from the OOM
>> killer, on panic().
>>
>> I am not sure how useful for (OOM ?) debugging the find_success vs.
>> find_total stats are at all. They are from ancient times. In
>> bb63be0a091c ("tmpfs: move swap_state stats update") we removed other
>> statistics that are "are relics of my 2.4.11 testing". Maybe
>> find_success and find_total can be similarly removed.
> 
> Maybe add_total, del_total, find_success and find_total should be similarly removed altogether?
> It seems those can't provide useful info when OOM occurs? And we can thus avoid touching the
> swap_cache_info cacheline.

At least makes sense to me, AFAIKU, these are not statistics one could
easily use to tune system performance because they are not easily
accessile. Maybe simply propose removal?


-- 
Thanks,

David / dhildenb


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

* Re: [PATCH 2/3] mm/swapfile: avoid confusing swap cache statistics
  2022-06-02  8:41               ` David Hildenbrand
@ 2022-06-06  3:14                 ` Miaohe Lin
  0 siblings, 0 replies; 15+ messages in thread
From: Miaohe Lin @ 2022-06-06  3:14 UTC (permalink / raw)
  To: David Hildenbrand; +Cc: linux-mm, linux-kernel, Hugh Dickins, Andrew Morton

On 2022/6/2 16:41, David Hildenbrand wrote:
> On 02.06.22 09:29, Miaohe Lin wrote:
>> On 2022/6/1 15:53, David Hildenbrand wrote:
>>> On 01.06.22 04:11, Miaohe Lin wrote:
>>>> On 2022/5/31 20:58, David Hildenbrand wrote:
>>>>> On 31.05.22 04:55, Miaohe Lin wrote:
>>>>>> On 2022/5/31 7:04, Andrew Morton wrote:
>>>>>>> On Fri, 27 May 2022 17:26:25 +0800 Miaohe Lin <linmiaohe@huawei.com> wrote:
>>>>>>>
>>>>>>>> At swapoff time, we're going to swap in the pages continuously. So calling
>>>>>>>> lookup_swap_cache would confuse statistics. We should use find_get_page
>>>>>>>> directly here.
>>>>>>>
>>>>>>> Why is the existing behaviour wrong?  swapoff() has to swap stuff in to
>>>>>>> be able to release the swap device.  Why do you believe that this
>>>>>>> swapin activity should not be accounted?
>>>>>>
>>>>>> IMHO, statistics, e.g. swap_cache_info.find_success, are used to show the effectiveness
>>>>>> of the swap cache activity. So they should only reflect the memory accessing activity
>>>>>> of the user. I think swapoff can't reflect the effectiveness of the swap cache activity
>>>>>> because it just swaps in pages one by one. Or statistics should reflect all the activity
>>>>>> of the user including swapoff?
>>>>>
>>>>> I'm wondering who cares and why?
>>>>
>>>> I thought it's used to show the effectiveness of the swapcache readahead algorithm. If nobody
>>>> ever cares about it now, I'm fine to drop this patch. And could these statistics be removed
>>>> since nobody cares about it?
>>>
>>> IIUC, they are printed (via show_swap_cache_info()), which is called via
>>> show_free_areas() -- primarily used via show_mem(). show_mem() is
>>> primarily used when OOM, when allocation fails and we warn, from the OOM
>>> killer, on panic().
>>>
>>> I am not sure how useful for (OOM ?) debugging the find_success vs.
>>> find_total stats are at all. They are from ancient times. In
>>> bb63be0a091c ("tmpfs: move swap_state stats update") we removed other
>>> statistics that are "are relics of my 2.4.11 testing". Maybe
>>> find_success and find_total can be similarly removed.
>>
>> Maybe add_total, del_total, find_success and find_total should be similarly removed altogether?
>> It seems those can't provide useful info when OOM occurs? And we can thus avoid touching the
>> swap_cache_info cacheline.
> 
> At least makes sense to me, AFAIKU, these are not statistics one could
> easily use to tune system performance because they are not easily
> accessile. Maybe simply propose removal?

I tend to agree with you. Will try to do it soon. Thanks!

> 
> 


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

end of thread, other threads:[~2022-06-06  3:15 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-27  9:26 [PATCH 0/3] A few fixup patches for swap Miaohe Lin
2022-05-27  9:26 ` [PATCH 1/3] mm/swapfile: make security_vm_enough_memory_mm() work as expected Miaohe Lin
2022-05-30 23:02   ` Andrew Morton
2022-05-31  2:40     ` Miaohe Lin
2022-05-27  9:26 ` [PATCH 2/3] mm/swapfile: avoid confusing swap cache statistics Miaohe Lin
2022-05-30 23:04   ` Andrew Morton
2022-05-31  2:55     ` Miaohe Lin
2022-05-31 12:58       ` David Hildenbrand
2022-06-01  2:11         ` Miaohe Lin
2022-06-01  7:53           ` David Hildenbrand
2022-06-02  7:29             ` Miaohe Lin
2022-06-02  8:41               ` David Hildenbrand
2022-06-06  3:14                 ` Miaohe Lin
2022-05-27  9:26 ` [PATCH 3/3] mm/swapfile: fix possible data races of inuse_pages Miaohe Lin
2022-05-31 13:02   ` David Hildenbrand

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.