linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: viro@zeniv.linux.org.uk, akpm@linux-foundation.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] seq_file: account everything
Date: Fri, 16 Mar 2018 13:43:42 +0100	[thread overview]
Message-ID: <20180316124342.GB11461@dhcp22.suse.cz> (raw)
In-Reply-To: <20180310085252.GB17121@avx2>

On Sat 10-03-18 11:52:52, Alexey Dobriyan wrote:
> All it takes to open a file and read 1 byte from it.
> 
> seq_file will be allocated along with any private allocations,
> and more importantly seq file buffer which is 1 page by default.
 
OOM badness heuristic will not know about this memory when choosing an
oom victim so we might kill a wrong victim which is not all that great
but at least the consumption will be contained within a memcg which
sounds like the sufficient protection for now. This is the case
basically for all kmem charges...

The seq file life time should be bound to a process life time so this is
OK.

> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
> 
>  fs/seq_file.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> --- a/fs/seq_file.c
> +++ b/fs/seq_file.c
> @@ -29,7 +29,7 @@ static void seq_set_overflow(struct seq_file *m)
>  
>  static void *seq_buf_alloc(unsigned long size)
>  {
> -	return kvmalloc(size, GFP_KERNEL);
> +	return kvmalloc(size, GFP_KERNEL_ACCOUNT);
>  }
>  
>  /**
> @@ -566,7 +566,7 @@ static void single_stop(struct seq_file *p, void *v)
>  int single_open(struct file *file, int (*show)(struct seq_file *, void *),
>  		void *data)
>  {
> -	struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
> +	struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL_ACCOUNT);
>  	int res = -ENOMEM;
>  
>  	if (op) {
> @@ -628,7 +628,7 @@ void *__seq_open_private(struct file *f, const struct seq_operations *ops,
>  	void *private;
>  	struct seq_file *seq;
>  
> -	private = kzalloc(psize, GFP_KERNEL);
> +	private = kzalloc(psize, GFP_KERNEL_ACCOUNT);
>  	if (private == NULL)
>  		goto out;
>  
> @@ -1112,5 +1112,5 @@ EXPORT_SYMBOL(seq_hlist_next_percpu);
>  
>  void __init seq_file_init(void)
>  {
> -	seq_file_cache = KMEM_CACHE(seq_file, SLAB_PANIC);
> +	seq_file_cache = KMEM_CACHE(seq_file, SLAB_ACCOUNT|SLAB_PANIC);
>  }

-- 
Michal Hocko
SUSE Labs

      reply	other threads:[~2018-03-16 12:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-10  8:52 [PATCH 2/2] seq_file: account everything Alexey Dobriyan
2018-03-16 12:43 ` Michal Hocko [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=20180316124342.GB11461@dhcp22.suse.cz \
    --to=mhocko@kernel.org \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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).