lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 5 Dec 2022 10:47:26 +0800
From:   Chen Wandun <chenwandun@...wei.com>
To:     <akpm@...ux-foundation.org>, <shli@...nel.org>, <hughd@...gle.com>,
        <arnd@...db.de>, <minchan@...nel.org>, <linux-mm@...ck.org>,
        <linux-kernel@...r.kernel.org>
CC:     <chenwandun@...wei.com>
Subject: [PATCH] swapfile: fix uncorrect statistical count about free swap

The counter of free swap turn to negtive during swapoff, this
phenomenon can be observed in oom log, such as:

1226 total pagecache pages
47 pages in swap cache
Swap cache stats: add 119633, delete 119814, find 26832/82125
Free swap  = -31796kB
Total swap = 0kB
1048576 pages RAM

Subtract the size of swap partition from free swap should put behind
try_to_unuse, otherwise, it will result in negtive counter if swap
partition is in use.

Fixes: ec8acf20afb8 ("swap: add per-partition lock for swapfile")
Signed-off-by: Chen Wandun <chenwandun@...wei.com>
---
 mm/swapfile.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 72e481aacd5d..5b9b695be84b 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2316,8 +2316,6 @@ static void setup_swap_info(struct swap_info_struct *p, int prio,
 static void _enable_swap_info(struct swap_info_struct *p)
 {
 	p->flags |= SWP_WRITEOK;
-	atomic_long_add(p->pages, &nr_swap_pages);
-	total_swap_pages += p->pages;
 
 	assert_spin_locked(&swap_lock);
 	/*
@@ -2353,6 +2351,8 @@ static void enable_swap_info(struct swap_info_struct *p, int prio,
 	spin_lock(&swap_lock);
 	spin_lock(&p->lock);
 	_enable_swap_info(p);
+	atomic_long_add(p->pages, &nr_swap_pages);
+	total_swap_pages += p->pages;
 	spin_unlock(&p->lock);
 	spin_unlock(&swap_lock);
 }
@@ -2444,8 +2444,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
 		least_priority++;
 	}
 	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);
@@ -2500,6 +2498,8 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
 		spin_lock(&p->lock);
 	}
 
+	atomic_long_sub(p->pages, &nr_swap_pages);
+	total_swap_pages -= p->pages;
 	swap_file = p->swap_file;
 	old_block_size = p->old_block_size;
 	p->swap_file = NULL;
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ