Linux-mm Archive on lore.kernel.org
 help / color / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: akpm@linux-foundation.org, mhocko@suse.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, gorcunov@virtuozzo.com
Subject: Re: [PATCH v2] ksm: React on changing "sleep_millisecs" parameter faster
Date: Tue, 11 Dec 2018 14:13:00 +0300
Message-ID: <20181211111300.GF2342@uranus.lan> (raw)
In-Reply-To: <154452399396.4921.3418365102240528000.stgit@localhost.localdomain>

On Tue, Dec 11, 2018 at 01:26:59PM +0300, Kirill Tkhai wrote:
> ksm thread unconditionally sleeps in ksm_scan_thread()
> after each iteration:
> 
> 	schedule_timeout_interruptible(
> 		msecs_to_jiffies(ksm_thread_sleep_millisecs))
> 
> The timeout is configured in /sys/kernel/mm/ksm/sleep_millisecs.
> 
> In case of user writes a big value by a mistake, and the thread
> enters into schedule_timeout_interruptible(), it's not possible
> to cancel the sleep by writing a new smaler value; the thread
> is just sleeping till timeout expires.
> 
> The patch fixes the problem by waking the thread each time
> after the value is updated.
> 
> This also may be useful for debug purposes; and also for userspace
> daemons, which change sleep_millisecs value in dependence of
> system load.
> 
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> 
> v2: Use wait_event_interruptible_timeout() instead of unconditional
>     schedule_timeout().
...
> @@ -2844,7 +2849,10 @@ static ssize_t sleep_millisecs_store(struct kobject *kobj,
>  	if (err || msecs > UINT_MAX)
>  		return -EINVAL;
>  
> +	mutex_lock(&ksm_thread_mutex);
>  	ksm_thread_sleep_millisecs = msecs;
> +	mutex_unlock(&ksm_thread_mutex);
> +	wake_up_interruptible(&ksm_iter_wait);

Btw, just thought -- if we start using this mutex here don't we
open a window for force attack on the thread self execution,
iow if there gonna be a million of writers do we have a guarantee
thread ksm_scan_thread will grab the mutex earlier than writers
(or somewhere inbetween)?

  reply index

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-11 10:03 [PATCH] " Cyrill Gorcunov
2018-12-11 10:26 ` [PATCH v2] " Kirill Tkhai
2018-12-11 11:13   ` Cyrill Gorcunov [this message]
2018-12-11 12:22     ` Kirill Tkhai
2018-12-11 12:34       ` Cyrill Gorcunov
2018-12-11 14:15         ` Kirill Tkhai
2018-12-11 15:11           ` [PATCH v3] " Kirill Tkhai
2018-12-11 15:19             ` Cyrill Gorcunov
  -- strict thread matches above, loose matches on Subject: below --
2018-12-10 16:06 [PATCH] " Kirill Tkhai
2018-12-10 20:10 ` Cyrill Gorcunov
2018-12-11  9:23   ` Kirill Tkhai

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=20181211111300.GF2342@uranus.lan \
    --to=gorcunov@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=gorcunov@virtuozzo.com \
    --cc=ktkhai@virtuozzo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.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

Linux-mm Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mm/0 linux-mm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mm linux-mm/ https://lore.kernel.org/linux-mm \
		linux-mm@kvack.org
	public-inbox-index linux-mm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kvack.linux-mm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git