linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lincheng Yang <lincheng.yang@transsion.corp-partner.google.com>
To: akpm@linux-foundation.org, rostedt@goodmis.org,
	mhiramat@kernel.org, willy@infradead.org, hughd@google.com,
	peterx@redhat.com, mike.kravetz@oracle.com, jgg@ziepe.ca,
	surenb@google.com, steven.price@arm.com,
	pasha.tatashin@soleen.com, kirill.shutemov@linux.intel.com,
	yuanchu@google.com, david@redhat.com,
	mathieu.desnoyers@efficios.com, dhowells@redhat.com,
	shakeelb@google.com, pcc@google.com, tytso@mit.edu,
	42.hyeyoo@gmail.com, vbabka@suse.cz, catalin.marinas@arm.com,
	lrh2000@pku.edu.cn, ying.huang@intel.com, mhocko@suse.com,
	vishal.moola@gmail.com, yosryahmed@google.com,
	findns94@gmail.com, neilb@suse.de
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	wanbin.wang@transsion.com, chunlei.zhuang@transsion.com,
	jinsheng.zhao@transsion.com, jiajun.ling@transsion.com,
	dongyun.liu@transsion.com,
	Lincheng Yang <lincheng.yang@transsion.com>
Subject: [RFC PATCH 5/5] mm/swapfile: add swapfile_write_enable interface
Date: Sun,  8 Oct 2023 17:59:24 +0800	[thread overview]
Message-ID: <20231008095924.1165106-6-lincheng.yang@transsion.com> (raw)
In-Reply-To: <20231008095924.1165106-1-lincheng.yang@transsion.com>

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@transsion.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



      parent reply	other threads:[~2023-10-08 10:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-08  9:59 [RFC PATCH 0/5] hot page swap to zram, cold page swap to swapfile directly Lincheng Yang
2023-10-08  9:59 ` [RFC PATCH 1/5] mm/swap_slots: cleanup swap slot cache Lincheng Yang
2023-10-08  9:59 ` [RFC PATCH 2/5] mm: introduce hot and cold anon page flags Lincheng Yang
2023-10-08  9:59 ` [RFC PATCH 3/5] mm: add VMA hot flag Lincheng Yang
2023-10-08  9:59 ` [RFC PATCH 4/5] mm: add page implyreclaim flag Lincheng Yang
2023-10-08 11:07   ` Matthew Wilcox
2023-10-10  3:27     ` Lincheng Yang
2023-10-08  9:59 ` Lincheng Yang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231008095924.1165106-6-lincheng.yang@transsion.com \
    --to=lincheng.yang@transsion.corp-partner.google.com \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=chunlei.zhuang@transsion.com \
    --cc=david@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=dongyun.liu@transsion.com \
    --cc=findns94@gmail.com \
    --cc=hughd@google.com \
    --cc=jgg@ziepe.ca \
    --cc=jiajun.ling@transsion.com \
    --cc=jinsheng.zhao@transsion.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=lincheng.yang@transsion.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lrh2000@pku.edu.cn \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=mhocko@suse.com \
    --cc=mike.kravetz@oracle.com \
    --cc=neilb@suse.de \
    --cc=pasha.tatashin@soleen.com \
    --cc=pcc@google.com \
    --cc=peterx@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=shakeelb@google.com \
    --cc=steven.price@arm.com \
    --cc=surenb@google.com \
    --cc=tytso@mit.edu \
    --cc=vbabka@suse.cz \
    --cc=vishal.moola@gmail.com \
    --cc=wanbin.wang@transsion.com \
    --cc=willy@infradead.org \
    --cc=ying.huang@intel.com \
    --cc=yosryahmed@google.com \
    --cc=yuanchu@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox