mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Yafang Shao <laoar.shao@gmail.com>
Cc: akpm@linux-foundation.org, jack@suse.cz, hannes@cmpxchg.org,
	mhocko@suse.com, vdavydov.dev@gmail.com, jlayton@redhat.com,
	nborisov@suse.com, tytso@mit.edu, mawilcox@microsoft.com,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: introduce sanity check on dirty ratio sysctl value
Date: Mon, 18 Sep 2017 12:22:44 +0200	[thread overview]
Message-ID: <20170918102244.GJ32516@quack2.suse.cz> (raw)
In-Reply-To: <1505669968-12593-1-git-send-email-laoar.shao@gmail.com>

On Mon 18-09-17 01:39:28, Yafang Shao wrote:
> we can find the logic in domain_dirty_limits() that
> when dirty bg_thresh is bigger than dirty thresh,
> bg_thresh will be set as thresh * 1 / 2.
> 	if (bg_thresh >= thresh)
> 		bg_thresh = thresh / 2;
> 
> But actually we can set dirty_background_raio bigger than
> dirty_ratio successfully. This behavior may mislead us.
> So we should do this sanity check at the beginning.
> 
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>

...

>  {
> +	int old_ratio = dirty_background_ratio;
> +	unsigned long bytes;
>  	int ret;
>  
>  	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
> -	if (ret == 0 && write)
> -		dirty_background_bytes = 0;
> +
> +	if (ret == 0 && write) {
> +		if (vm_dirty_ratio > 0) {
> +			if (dirty_background_ratio >= vm_dirty_ratio)
> +				ret = -EINVAL;
> +		} else if (vm_dirty_bytes > 0) {
> +			bytes = global_dirtyable_memory() * PAGE_SIZE *
> +					dirty_background_ratio / 100;
> +			if (bytes >= vm_dirty_bytes)
> +				ret = -EINVAL;
> +		}
> +
> +		if (ret == 0)
> +			dirty_background_bytes = 0;
> +		else
> +			dirty_background_ratio = old_ratio;
> +	}
> +

How about implementing something like

bool vm_dirty_settings_valid(void)

helper which would validate whether current dirtiness settings are
consistent. That way we would not have to repeat very similar checks four
times. Also the arithmetics in:

global_dirtyable_memory() * PAGE_SIZE * dirty_background_ratio / 100 

could overflow so I'd prefer to first divide by 100 and then multiply by
dirty_background_ratio...

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2017-09-18 10:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-17 17:39 Yafang Shao
2017-09-18 10:22 ` Jan Kara [this message]
2017-09-18 11:36   ` Yafang Shao

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=20170918102244.GJ32516@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=jlayton@redhat.com \
    --cc=laoar.shao@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mawilcox@microsoft.com \
    --cc=mhocko@suse.com \
    --cc=nborisov@suse.com \
    --cc=tytso@mit.edu \
    --cc=vdavydov.dev@gmail.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

all inboxes | Powered by JetHome®