linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Balbir Singh <bsingharora@gmail.com>
Cc: cgroups@vger.kernel.org, Oleg Nesterov <oleg@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: Re: [RFC][PATCH] cgroup_threadgroup_rwsem - affects scalability and OOM
Date: Tue, 9 Aug 2016 02:29:00 -0400	[thread overview]
Message-ID: <20160809062900.GD4906@mtj.duckdns.org> (raw)
In-Reply-To: <4717ef90-ca86-4a34-c63a-94b8b4bfaaec@gmail.com>

Hello, Balbir.

On Tue, Aug 09, 2016 at 02:19:01PM +1000, Balbir Singh wrote:
> 
> cgroup_threadgroup_rwsem is acquired in read mode during process exit and fork.
> It is also grabbed in write mode during __cgroups_proc_write
> 
> I've recently run into a scenario with lots of memory pressure and OOM
> and I am beginning to see
> 
> systemd
> 
>  __switch_to+0x1f8/0x350
>  __schedule+0x30c/0x990
>  schedule+0x48/0xc0
>  percpu_down_write+0x114/0x170
>  __cgroup_procs_write.isra.12+0xb8/0x3c0
>  cgroup_file_write+0x74/0x1a0
>  kernfs_fop_write+0x188/0x200
>  __vfs_write+0x6c/0xe0
>  vfs_write+0xc0/0x230
>  SyS_write+0x6c/0x110
>  system_call+0x38/0xb4
> 
> This thread is waiting on the reader of cgroup_threadgroup_rwsem to exit.
> The reader itself is under memory pressure and has gone into reclaim after
> fork. There are times the reader also ends up waiting on oom_lock as well.
> 
...
>  copy_page_range+0x4ec/0x950
>  copy_process.isra.5+0x15a0/0x1870
>  _do_fork+0xa8/0x4b0
>  ppc_clone+0x8/0xc

Yeah, we definitely don't wanna be holding the rwsem during the actual
fork.

...
> There are other theoretical issues with this semaphore
> 
> systemd can do
> 
> 1. cgroup_mutex (cgroup_kn_lock_live)
> 2. cgroup_threadgroup_rwsem (W) (__cgroup_procs_write)
> 
> and other threads can go
> 
> 1. cgroup_threadgroup_rwsem (R) (copy_process)
> 2. mem_cgroup_iter (as a part of reclaim) (cgroup_mutex -- rcu lock or cgroup_mutex)

Hmm? Where does mem_cgroup_iter grab cgroup_mutex?  cgroup_mutex nests
outside cgroup_threadgroup_rwsem or most other mutexes for that matter
and isn't exposed from cgroup core.

> However, I've not examined them in too much detail or looked at lockdep
> wait chains for those paths.
> 
> I am sure there is a good reason for placing cgroup_threadgroup_rwsem
> where it is today and I might be missing something. I am also surprised

I could be missing something too but the positioning is largely
historic.

> no-one else has run into it so far.

Maybe it might matter that much on a system which is already heavily
thrasing, but yeah, we definitely want to tighten down the reader
sections so that it doesn't get in the way of making forward progress.

> Comments?

The change looks good to me on the first glance but I'll think more
about it tomorrow.

Thanks!

-- 
tejun

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2016-08-09  6:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-09  4:19 [RFC][PATCH] cgroup_threadgroup_rwsem - affects scalability and OOM Balbir Singh
2016-08-09  6:29 ` Tejun Heo [this message]
2016-08-09  7:02   ` Balbir Singh
2016-08-09 14:26     ` Tejun Heo
2016-08-10  1:21       ` Balbir Singh
2016-08-09  9:00 ` Zefan Li
2016-08-09 13:57   ` Balbir Singh
2016-08-10  1:31     ` Zefan Li
2016-08-09 18:09 ` Oleg Nesterov
2016-08-10 19:43 ` Tejun Heo
2016-08-11 23:47   ` Balbir Singh

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=20160809062900.GD4906@mtj.duckdns.org \
    --to=tj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=bsingharora@gmail.com \
    --cc=cgroups@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=oleg@redhat.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;
as well as URLs for NNTP newsgroup(s).