Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1406129

Re: [PATCH RESEND 7/8] pipe: account to kmemcg

From Eric Dumazet <eric.dumazet@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH RESEND 7/8] pipe: account to kmemcg
Date 2016-05-24 15:00 +0200
Message-ID <rCk6j-3mY-15@gated-at.bofh.it> (permalink)
References <rCgvE-1kA-23@gated-at.bofh.it> <rCgvE-1kA-31@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, 2016-05-24 at 11:49 +0300, Vladimir Davydov wrote:
> Pipes can consume a significant amount of system memory, hence they
> should be accounted to kmemcg.
> 
> This patch marks pipe_inode_info and anonymous pipe buffer page
> allocations as __GFP_ACCOUNT so that they would be charged to kmemcg.
> Note, since a pipe buffer page can be "stolen" and get reused for other
> purposes, including mapping to userspace, we clear PageKmemcg thus
> resetting page->_mapcount and uncharge it in anon_pipe_buf_steal, which
> is introduced by this patch.
> 
> Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> ---
>  fs/pipe.c | 32 ++++++++++++++++++++++++++------
>  1 file changed, 26 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/pipe.c b/fs/pipe.c
> index 0d3f5165cb0b..4b32928f5426 100644
> --- a/fs/pipe.c
> +++ b/fs/pipe.c
> @@ -21,6 +21,7 @@
>  #include <linux/audit.h>
>  #include <linux/syscalls.h>
>  #include <linux/fcntl.h>
> +#include <linux/memcontrol.h>
>  
>  #include <asm/uaccess.h>
>  #include <asm/ioctls.h>
> @@ -137,6 +138,22 @@ static void anon_pipe_buf_release(struct pipe_inode_info *pipe,
>  		put_page(page);
>  }
>  
> +static int anon_pipe_buf_steal(struct pipe_inode_info *pipe,
> +			       struct pipe_buffer *buf)
> +{
> +	struct page *page = buf->page;
> +
> +	if (page_count(page) == 1) {

This looks racy : some cpu could have temporarily elevated page count.

> +		if (memcg_kmem_enabled()) {
> +			memcg_kmem_uncharge(page, 0);
> +			__ClearPageKmemcg(page);
> +		}
> +		__SetPageLocked(page);
> +		return 0;
> +	}
> +	return 1;
> +}
> +

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH RESEND 7/8] pipe: account to kmemcg Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-05-24 11:10 +0200
  Re: [PATCH RESEND 7/8] pipe: account to kmemcg Eric Dumazet <eric.dumazet@gmail.com> - 2016-05-24 15:00 +0200
    Re: [PATCH RESEND 7/8] pipe: account to kmemcg Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-05-24 18:50 +0200
      Re: [PATCH RESEND 7/8] pipe: account to kmemcg Eric Dumazet <eric.dumazet@gmail.com> - 2016-05-24 22:10 +0200
        Re: [PATCH RESEND 7/8] pipe: account to kmemcg Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-05-25 12:40 +0200
          Re: [PATCH RESEND 7/8] pipe: account to kmemcg Minchan Kim <minchan@kernel.org> - 2016-05-26 09:10 +0200
            Re: [PATCH RESEND 7/8] pipe: account to kmemcg Vladimir Davydov <vdavydov@virtuozzo.com> - 2016-05-26 16:00 +0200
              Re: [PATCH RESEND 7/8] pipe: account to kmemcg Eric Dumazet <eric.dumazet@gmail.com> - 2016-05-26 16:20 +0200

csiph-web