From: Matthew Wilcox <willy@infradead.org>
To: cgel.zte@gmail.com
Cc: akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org, corbet@lwn.net,
xu xin <xu.xin16@zte.com.cn>, Yang Yang <yang.yang29@zte.com.cn>,
Ran Xiaokai <ran.xiaokai@zte.com.cn>,
wangyong <wang.yong12@zte.com.cn>,
Yunkai Zhang <zhang.yunkai@zte.com.cn>
Subject: Re: [PATCH v6] mm/ksm: introduce ksm_force for each process
Date: Thu, 12 May 2022 22:07:09 +0100 [thread overview]
Message-ID: <Yn12/ZMyQEnSh0Ge@casper.infradead.org> (raw)
In-Reply-To: <20220510122242.1380536-1-xu.xin16@zte.com.cn>
On Tue, May 10, 2022 at 12:22:42PM +0000, cgel.zte@gmail.com wrote:
> +++ b/Documentation/admin-guide/mm/ksm.rst
> @@ -32,7 +32,7 @@ are swapped back in: ksmd must rediscover their identity and merge again).
> Controlling KSM with madvise
> ============================
>
> -KSM only operates on those areas of address space which an application
> +KSM can operates on those areas of address space which an application
"can operate on"
> +static ssize_t ksm_force_write(struct file *file, const char __user *buf,
> + size_t count, loff_t *ppos)
> +{
> + struct task_struct *task;
> + struct mm_struct *mm;
> + char buffer[PROC_NUMBUF];
> + int force;
> + int err = 0;
> +
> + memset(buffer, 0, sizeof(buffer));
> + if (count > sizeof(buffer) - 1)
> + count = sizeof(buffer) - 1;
> + if (copy_from_user(buffer, buf, count))
> + return -EFAULT;
> +
> + err = kstrtoint(strstrip(buffer), 0, &force);
> + if (err)
> + return err;
> +
> + if (force != 0 && force != 1)
> + return -EINVAL;
> +
> + task = get_proc_task(file_inode(file));
> + if (!task)
> + return -ESRCH;
> +
> + mm = get_task_mm(task);
> + if (!mm)
> + goto out_put_task;
> +
> + if (mm->ksm_force != force) {
> + if (mmap_write_lock_killable(mm)) {
> + err = -EINTR;
> + goto out_mmput;
> + }
> +
> + if (force == 0)
> + mm->ksm_force = force;
> + else {
> + /*
> + * Force anonymous pages of this mm to be involved in KSM merging
> + * without explicitly calling madvise.
> + */
> + if (!test_bit(MMF_VM_MERGEABLE, &mm->flags))
> + err = __ksm_enter(mm);
> + if (!err)
> + mm->ksm_force = force;
> + }
> +
> + mmap_write_unlock(mm);
> + }
There's a much simpler patch hiding inside this complicated one.
if (force) {
set_bit(MMF_VM_MERGEABLE, &mm->flags));
for each VMA
set VM_MERGEABLE;
err = __ksm_enter(mm);
} else {
clear_bit(MMF_VM_MERGEABLE, &mm->flags));
for each VMA
clear VM_MERGEABLE;
}
... and all the extra complications you added go away.
next prev parent reply other threads:[~2022-05-12 21:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-10 12:22 [PATCH v6] mm/ksm: introduce ksm_force for each process cgel.zte
2022-05-10 13:30 ` Oleksandr Natalenko
2022-05-11 3:12 ` CGEL
2022-05-12 22:37 ` Andrew Morton
2022-05-13 9:51 ` Oleksandr Natalenko
2022-05-13 20:32 ` Andrew Morton
2022-05-13 20:53 ` Oleksandr Natalenko
2022-05-12 21:07 ` Matthew Wilcox [this message]
2022-05-13 6:50 ` CGEL
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=Yn12/ZMyQEnSh0Ge@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=cgel.zte@gmail.com \
--cc=corbet@lwn.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ran.xiaokai@zte.com.cn \
--cc=wang.yong12@zte.com.cn \
--cc=xu.xin16@zte.com.cn \
--cc=yang.yang29@zte.com.cn \
--cc=zhang.yunkai@zte.com.cn \
/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;
as well as URLs for NNTP newsgroup(s).