From: Max Kellermann <mk@cm4all.com>
To: Aleksa Sarai <cyphar@cyphar.com>
Cc: Tejun Heo <tj@kernel.org>,
cgroups@vger.kernel.org, lizefan@huawei.com,
Johannes Weiner <hannes@cmpxchg.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cgroup_pids: add fork limit
Date: Tue, 10 Nov 2015 17:01:34 +0100 [thread overview]
Message-ID: <20151110160134.GB20758@rabbit.intern.cm-ag> (raw)
In-Reply-To: <CAOviyaiXSCztjv0d99G-t-yo1wtGzXZr0qpuqcKDBdV=wnMinw@mail.gmail.com>
On 2015/11/10 16:25, Aleksa Sarai <cyphar@cyphar.com> wrote:
> > The goal of this limit is to have another safeguard against fork
> > bombs. It gives processes a chance to set up their child processes /
> > threads, but will be stopped once they attempt to waste resources by
> > continuously exiting and cloning new processes. This can be useful
> > for short-lived processes such as CGI programs.
>
> Processes don't "use up resources" after they've died and been freed
> (which is dealt with inside PIDs).
That is true, but misses the point.
At some point, while the fork was in progress, those processes did
consume a considerable amount of resources. At that very range of
time, the server was occupied with executing these forks, and was
unable to give CPU time to other processes.
Now if the kernel had stopped that fork bomb earlier, he would have
had more capacity to execute other jobs which are waiting in the
queue. That fork bomb did do its damage, even though the number of
processes was limited - and the goal of the fork limit feature is to
detect it early and stop it from spreading larger.
Some jobs are predictable in how many forks will happen. Just like
some jobs are predictable in how many processes there will be at a
time, how many open files it has at a time, how much memory it will
consume at a time. All those limits are useful.
That's the big difference: existing cgroups limit a given resource at
one point in time, while "fork limit" is a counter that expires after
a certain amount of resources is consumed (integrated over time). It
is about "consumption", not about "usage".
This is similar to RLIMIT_CPU, which does not rate-limit the CPU
usage, but the total amount of time spent executing.
> Fork bombs aren't bad because they cause a lot of fork()s, they're bad
> because the *create a bunch of processes that use up memory*, which
> happens because they call fork() a bunch of times and **don't
> exit()**.
That is partly true, but is just one side of the story.
The fork() calls itself are expensive, and a process forking and
exiting over and over can put heavy load on your server. All within
"pids" and "memcg" limits.
The goal of my patch is to stop the fork bomb as early as possible,
with an additional limit that is reasonable, which no "good" job
implementation will need to cross.
I developed this feature long before cgroups have been invented
(actually I developed something similar to cgroups/namespaces back
then). It has been proven very successful in a large CGI hosting
cluster. It's perfectly ok for me to maintain this in my private
branch forever ...
Max
prev parent reply other threads:[~2015-11-10 16:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-10 14:06 Max Kellermann
2015-11-10 15:12 ` Tejun Heo
2015-11-10 15:37 ` Max Kellermann
2015-11-10 15:44 ` Tejun Heo
2015-11-10 17:06 ` Max Kellermann
2015-11-10 17:29 ` Tejun Heo
2015-11-10 17:52 ` Max Kellermann
2015-11-10 15:25 ` Aleksa Sarai
2015-11-10 15:58 ` Austin S Hemmelgarn
2015-11-10 16:19 ` Parav Pandit
2015-11-10 19:54 ` Austin S Hemmelgarn
2015-11-15 13:36 ` Aleksa Sarai
2015-11-16 17:02 ` Austin S Hemmelgarn
2015-11-10 16:01 ` Max Kellermann [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=20151110160134.GB20758@rabbit.intern.cm-ag \
--to=mk@cm4all.com \
--cc=cgroups@vger.kernel.org \
--cc=cyphar@cyphar.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=tj@kernel.org \
/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®