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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231008095924.1165106-6-lincheng.yang@transsion.com>
Date:   Sun,  8 Oct 2023 17:59:24 +0800
From:   Lincheng Yang <lincheng.yang@...nssion.corp-partner.google.com>
To:     akpm@...ux-foundation.org, rostedt@...dmis.org,
        mhiramat@...nel.org, willy@...radead.org, hughd@...gle.com,
        peterx@...hat.com, mike.kravetz@...cle.com, jgg@...pe.ca,
        surenb@...gle.com, steven.price@....com, pasha.tatashin@...een.com,
        kirill.shutemov@...ux.intel.com, yuanchu@...gle.com,
        david@...hat.com, mathieu.desnoyers@...icios.com,
        dhowells@...hat.com, shakeelb@...gle.com, pcc@...gle.com,
        tytso@....edu, 42.hyeyoo@...il.com, vbabka@...e.cz,
        catalin.marinas@....com, lrh2000@....edu.cn, ying.huang@...el.com,
        mhocko@...e.com, vishal.moola@...il.com, yosryahmed@...gle.com,
        findns94@...il.com, neilb@...e.de
Cc:     linux-kernel@...r.kernel.org, linux-mm@...ck.org,
        wanbin.wang@...nssion.com, chunlei.zhuang@...nssion.com,
        jinsheng.zhao@...nssion.com, jiajun.ling@...nssion.com,
        dongyun.liu@...nssion.com,
        Lincheng Yang <lincheng.yang@...nssion.com>
Subject: [RFC PATCH 5/5] mm/swapfile: add swapfile_write_enable interface

When the user does not want to write back cold pages to swapfile, set
/proc/swapfile_write_enable to 0. At this time, all anon pages, regardless
of hot or cold status, will be written back to the zram device.

Signed-off-by: Lincheng Yang <lincheng.yang@...nssion.com>
---
 mm/swapfile.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 629e6a291e9b..557d1c29be77 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -106,6 +106,7 @@ static atomic_t proc_poll_event = ATOMIC_INIT(0);
 atomic_t nr_rotate_swap = ATOMIC_INIT(0);
 
 static unsigned int workingset_restore_limit;
+static unsigned int swapfile_write_enable;
 
 static struct swap_info_struct *swap_type_to_swap_info(int type)
 {
@@ -127,7 +128,7 @@ bool swap_folio_hot(struct folio *folio, bool hotness)
 	unsigned long restores;
 	int delta;
 
-	if (hotness)
+	if (!swapfile_write_enable || hotness)
 		return true;
 
 	if (folio_test_swapbacked(folio) && folio_test_hot(folio)) {
@@ -2775,10 +2776,46 @@ const struct proc_ops workingset_restore_limit_fops = {
 	.proc_write = workingset_restore_limit_write,
 };
 
+static ssize_t swapfile_write_enable_write(struct file *file,
+					   const char __user *ubuf,
+					   size_t count, loff_t *pos)
+{
+	unsigned int val;
+	int ret;
+
+	ret = kstrtouint_from_user(ubuf, count, 10, &val);
+	if (ret)
+		return ret;
+
+	swapfile_write_enable = val;
+
+	return count;
+}
+
+static int swapfile_write_enable_show(struct seq_file *m, void *v)
+{
+	seq_printf(m, "%d\n", swapfile_write_enable);
+	return 0;
+}
+
+static int swapfile_write_enable_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, swapfile_write_enable_show, inode->i_private);
+}
+
+const struct proc_ops swapfile_write_enable_fops = {
+	.proc_open	= swapfile_write_enable_open,
+	.proc_read	= seq_read,
+	.proc_lseek	= seq_lseek,
+	.proc_release	= seq_release,
+	.proc_write	= swapfile_write_enable_write,
+};
+
 static int __init procswaps_init(void)
 {
 	proc_create("swaps", 0, NULL, &swaps_proc_ops);
 	proc_create("workingset_restore_limit", S_IALLUGO, NULL, &workingset_restore_limit_fops);
+	proc_create("swapfile_write_enable", S_IALLUGO, NULL, &swapfile_write_enable_fops);
 
 	return 0;
 }
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ