From: Oleksandr Natalenko <oleksandr@natalenko.name>
To: timofey.titovets@synesis.ru
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, nefelim4ag@gmail.com, willy@infradead.org
Subject: Re: [PATCH V3] KSM: allow dedup all tasks memory
Date: Tue, 13 Nov 2018 17:33:49 +0100 [thread overview]
Message-ID: <d45addefdf05b84af96fb494d52b4ec4@natalenko.name> (raw)
In-Reply-To: <<20181112231344.7161-1-timofey.titovets@synesis.ru>>
So,
> a?|snipa?|
> +static int ksm_seeker_thread(void *nothing)
> +{
> + pid_t last_pid = 1;
> + pid_t curr_pid;
> + struct task_struct *task;
> +
> + set_freezable();
> + set_user_nice(current, 5);
> +
> + while (!kthread_should_stop()) {
> + wait_while_offlining();
> +
> + try_to_freeze();
> +
> + if (!ksm_mode_always()) {
> + wait_event_freezable(ksm_seeker_thread_wait,
> + ksm_mode_always() || kthread_should_stop());
> + continue;
> + }
> +
> + /*
> + * import one task's vma per run
> + */
> + read_lock(&tasklist_lock);
> +
> + /* Try always get next task */
> + for_each_process(task) {
> + curr_pid = task_pid_nr(task);
> + if (curr_pid == last_pid) {
> + task = next_task(task);
> + break;
> + }
> +
> + if (curr_pid > last_pid)
> + break;
> + }
> +
> + last_pid = task_pid_nr(task);
> + ksm_import_task_vma(task);
This seems to be a bad idea. ksm_import_task_vma() may sleep with
tasklist_lock being held. Thus, IIUC, you'll get this:
[ 1754.410322] BUG: scheduling while atomic: ksmd_seeker/50/0x00000002
a?|
[ 1754.410444] Call Trace:
[ 1754.410455] dump_stack+0x5c/0x80
[ 1754.410460] __schedule_bug.cold.19+0x38/0x51
[ 1754.410464] __schedule+0x11dc/0x2080
[ 1754.410483] schedule+0x32/0xb0
[ 1754.410487] rwsem_down_write_failed+0x15d/0x240
[ 1754.410496] call_rwsem_down_write_failed+0x13/0x20
[ 1754.410499] down_write+0x20/0x30
[ 1754.410502] ksm_import_task_vma+0x22/0x70
[ 1754.410505] ksm_seeker_thread+0x134/0x1c0
[ 1754.410512] kthread+0x113/0x130
[ 1754.410518] ret_from_fork+0x35/0x40
I think you may want to get a reference to task_struct before releasing
tasklist_lock, and then put it after ksm_import_task_vma() does its job.
> + read_unlock(&tasklist_lock);
> +
> + schedule_timeout_interruptible(
> + msecs_to_jiffies(ksm_thread_seeker_sleep_millisecs));
> + }
> + return 0;
> +}
> a?|snipa?|
--
Oleksandr Natalenko (post-factum)
next prev parent reply other threads:[~2018-11-13 16:33 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <<20181112231344.7161-1-timofey.titovets@synesis.ru>
2018-11-13 11:06 ` Oleksandr Natalenko
2018-11-13 11:56 ` Timofey Titovets
2018-11-13 16:33 ` Oleksandr Natalenko [this message]
2018-11-13 17:10 ` Timofey Titovets
2018-11-13 17:27 ` Oleksandr Natalenko
2018-11-13 17:44 ` Timofey Titovets
2018-11-13 18:20 Timofey Titovets
[not found] <<CAG48ez0ZprqUYGZFxcrY6U3Dnwt77q1NJXzzpsn1XNkRuXVppw@mail.gmail.com>
2018-11-13 14:23 ` Oleksandr Natalenko
2018-11-13 17:59 ` Pavel Tatashin
2018-11-13 18:17 ` Timofey Titovets
2018-11-13 18:35 ` Pavel Tatashin
2018-11-13 18:54 ` Timofey Titovets
2018-11-13 19:16 ` Pavel Tatashin
2018-11-13 22:40 ` Timofey Titovets
2018-11-13 22:53 ` Pavel Tatashin
2018-11-13 23:07 ` Timofey Titovets
2018-11-13 20:26 ` Jann Horn
2018-11-13 22:35 ` Pavel Tatashin
-- strict thread matches above, loose matches on Subject: below --
2018-11-12 23:13 Timofey Titovets
2018-11-13 1:49 ` Matthew Wilcox
2018-11-13 11:25 ` Timofey Titovets
2018-11-13 2:25 ` Pavel Tatashin
2018-11-13 11:40 ` Timofey Titovets
2018-11-13 18:42 ` Pavel Tatashin
2018-11-13 22:55 ` Timofey Titovets
2018-11-13 11:57 ` Jann Horn
2018-11-13 12:58 ` Timofey Titovets
2018-11-13 13:25 ` Jann Horn
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=d45addefdf05b84af96fb494d52b4ec4@natalenko.name \
--to=oleksandr@natalenko.name \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nefelim4ag@gmail.com \
--cc=timofey.titovets@synesis.ru \
--cc=willy@infradead.org \
/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