From: Johannes Weiner <hannes@cmpxchg.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Hocko <mhocko@suse.com>, Roman Gushchin <guro@fb.com>,
Tejun Heo <tj@kernel.org>,
linux-mm@kvack.org, cgroups@vger.kernel.org,
linux-kernel@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH 3/3] mm: memcontrol: recursive memory.low protection
Date: Fri, 13 Dec 2019 15:05:19 -0500 [thread overview]
Message-ID: <20191213200519.GA168988@cmpxchg.org> (raw)
In-Reply-To: <20191213192158.188939-4-hannes@cmpxchg.org>
On Fri, Dec 13, 2019 at 02:21:58PM -0500, Johannes Weiner wrote:
> + if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_RECURSIVE_PROT) {
> + unsigned long unclaimed;
> + /*
> + * If the children aren't claiming (all of) the
> + * protection afforded to them by the parent,
> + * distribute the remainder in proportion to the
> + * (unprotected) size of each cgroup. That way,
> + * cgroups that aren't explicitly prioritized wrt each
> + * other compete freely over the allowance, but they
> + * are collectively protected from neighboring trees.
> + *
> + * We're using unprotected size for the weight so that
> + * if some cgroups DO claim explicit protection, we
> + * don't protect the same bytes twice.
> + */
> + unclaimed = parent_effective - siblings_protected;
> + unclaimed *= usage - protected;
> + unclaimed /= parent_usage - siblings_protected;
Brainfart I noticed just after sending it out - naturally. If there is
unclaimed protection in the parent, but the children use exactly how
much they claim, this will div0. We have to check for usage that isn't
explicitly protected in the child to which to apply the float. Fixlet
below. Doesn't change the overall logic, though.
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 2e352cd6c38d..8d7e9490740b 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6328,21 +6328,24 @@ static unsigned long effective_protection(unsigned long usage,
*/
ep = protected;
- if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_RECURSIVE_PROT) {
+ /*
+ * If the children aren't claiming (all of) the protection
+ * afforded to them by the parent, distribute the remainder in
+ * proportion to the (unprotected) size of each cgroup. That
+ * way, cgroups that aren't explicitly prioritized wrt each
+ * other compete freely over the allowance, but they are
+ * collectively protected from neighboring trees.
+ *
+ * We're using unprotected size for the weight so that if some
+ * cgroups DO claim explicit protection, we don't protect the
+ * same bytes twice.
+ */
+ if (!(cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_RECURSIVE_PROT))
+ return ep;
+
+ if (usage > protected && parent_effective > siblings_protected) {
unsigned long unclaimed;
- /*
- * If the children aren't claiming (all of) the
- * protection afforded to them by the parent,
- * distribute the remainder in proportion to the
- * (unprotected) size of each cgroup. That way,
- * cgroups that aren't explicitly prioritized wrt each
- * other compete freely over the allowance, but they
- * are collectively protected from neighboring trees.
- *
- * We're using unprotected size for the weight so that
- * if some cgroups DO claim explicit protection, we
- * don't protect the same bytes twice.
- */
+
unclaimed = parent_effective - siblings_protected;
unclaimed *= usage - protected;
unclaimed /= parent_usage - siblings_protected;
next prev parent reply other threads:[~2019-12-13 21:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-13 19:21 [PATCH 0/3] mm: memcontrol: recursive memory protection Johannes Weiner
2019-12-13 19:21 ` [PATCH 1/3] mm: memcontrol: fix memory.low proportional distribution Johannes Weiner
2019-12-13 20:40 ` Roman Gushchin
2019-12-16 18:25 ` Johannes Weiner
2019-12-16 19:11 ` Roman Gushchin
2019-12-13 19:21 ` [PATCH 2/3] mm: memcontrol: clean up and document effective low/min calculations Johannes Weiner
2019-12-13 19:21 ` [PATCH 3/3] mm: memcontrol: recursive memory.low protection Johannes Weiner
2019-12-13 20:05 ` Johannes Weiner [this message]
2020-02-27 19:56 [PATCH 0/3] " Johannes Weiner
2020-02-27 19:56 ` [PATCH 3/3] " Johannes Weiner
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=20191213200519.GA168988@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=guro@fb.com \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.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