All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Down <chris@chrisdown.name>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Michal Hocko <mhocko@suse.com>, Hugh Dickins <hughd@google.com>,
	Shakeel Butt <shakeelb@google.com>, Roman Gushchin <guro@fb.com>,
	linux-mm@kvack.org, cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH] mm: page_counter: mitigate consequences of a page_counter underflow
Date: Thu, 8 Apr 2021 17:18:41 +0100	[thread overview]
Message-ID: <YG8s4X9AB1GoxvYA@chrisdown.name> (raw)
In-Reply-To: <20210408143155.2679744-1-hannes@cmpxchg.org>

Johannes Weiner writes:
>When the unsigned page_counter underflows, even just by a few pages, a
>cgroup will not be able to run anything afterwards and trigger the OOM
>killer in a loop.
>
>Underflows shouldn't happen, but when they do in practice, we may just
>be off by a small amount that doesn't interfere with the normal
>operation - consequences don't need to be that dire.
>
>Reset the page_counter to 0 upon underflow. We'll issue a warning that
>the accounting will be off and then try to keep limping along.
>
>[ We used to do this with the original res_counter, where it was a
>  more straight-forward correction inside the spinlock section. I
>  didn't carry it forward into the lockless page counters for
>  simplicity, but it turns out this is quite useful in practice. ]
>
>Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>

Acked-by: Chris Down <chris@chrisdown.name>

>---
> mm/page_counter.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
>diff --git a/mm/page_counter.c b/mm/page_counter.c
>index c6860f51b6c6..7d83641eb86b 100644
>--- a/mm/page_counter.c
>+++ b/mm/page_counter.c
>@@ -52,9 +52,13 @@ void page_counter_cancel(struct page_counter *counter, unsigned long nr_pages)
> 	long new;
>
> 	new = atomic_long_sub_return(nr_pages, &counter->usage);
>-	propagate_protected_usage(counter, new);
> 	/* More uncharges than charges? */
>-	WARN_ON_ONCE(new < 0);
>+	if (WARN_ONCE(new < 0, "page_counter underflow: %ld nr_pages=%lu\n",
>+		      new, nr_pages)) {
>+		new = 0;
>+		atomic_long_set(&counter->usage, new);
>+	}
>+	propagate_protected_usage(counter, new);
> }
>
> /**
>-- 
>2.31.1
>
>

WARNING: multiple messages have this Message-ID (diff)
From: Chris Down <chris-6Bi1550iOqEnzZ6mRAm98g@public.gmane.org>
To: Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>
Cc: Andrew Morton
	<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
	Michal Hocko <mhocko-IBi9RG/b67k@public.gmane.org>,
	Hugh Dickins <hughd-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	Shakeel Butt <shakeelb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	Roman Gushchin <guro-b10kYP2dOMg@public.gmane.org>,
	linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org,
	cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	kernel-team-b10kYP2dOMg@public.gmane.org
Subject: Re: [PATCH] mm: page_counter: mitigate consequences of a page_counter underflow
Date: Thu, 8 Apr 2021 17:18:41 +0100	[thread overview]
Message-ID: <YG8s4X9AB1GoxvYA@chrisdown.name> (raw)
In-Reply-To: <20210408143155.2679744-1-hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>

Johannes Weiner writes:
>When the unsigned page_counter underflows, even just by a few pages, a
>cgroup will not be able to run anything afterwards and trigger the OOM
>killer in a loop.
>
>Underflows shouldn't happen, but when they do in practice, we may just
>be off by a small amount that doesn't interfere with the normal
>operation - consequences don't need to be that dire.
>
>Reset the page_counter to 0 upon underflow. We'll issue a warning that
>the accounting will be off and then try to keep limping along.
>
>[ We used to do this with the original res_counter, where it was a
>  more straight-forward correction inside the spinlock section. I
>  didn't carry it forward into the lockless page counters for
>  simplicity, but it turns out this is quite useful in practice. ]
>
>Signed-off-by: Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>

Acked-by: Chris Down <chris-6Bi1550iOqEnzZ6mRAm98g@public.gmane.org>

>---
> mm/page_counter.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
>diff --git a/mm/page_counter.c b/mm/page_counter.c
>index c6860f51b6c6..7d83641eb86b 100644
>--- a/mm/page_counter.c
>+++ b/mm/page_counter.c
>@@ -52,9 +52,13 @@ void page_counter_cancel(struct page_counter *counter, unsigned long nr_pages)
> 	long new;
>
> 	new = atomic_long_sub_return(nr_pages, &counter->usage);
>-	propagate_protected_usage(counter, new);
> 	/* More uncharges than charges? */
>-	WARN_ON_ONCE(new < 0);
>+	if (WARN_ONCE(new < 0, "page_counter underflow: %ld nr_pages=%lu\n",
>+		      new, nr_pages)) {
>+		new = 0;
>+		atomic_long_set(&counter->usage, new);
>+	}
>+	propagate_protected_usage(counter, new);
> }
>
> /**
>-- 
>2.31.1
>
>

  parent reply	other threads:[~2021-04-08 16:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-08 14:31 [PATCH] mm: page_counter: mitigate consequences of a page_counter underflow Johannes Weiner
2021-04-08 14:31 ` Johannes Weiner
2021-04-08 15:08 ` Michal Hocko
2021-04-08 15:08   ` Michal Hocko
2021-04-08 16:18 ` Chris Down [this message]
2021-04-08 16:18   ` Chris Down
2021-04-08 16:24 ` Shakeel Butt
2021-04-08 16:24   ` Shakeel Butt
2021-04-08 16:24   ` Shakeel Butt

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=YG8s4X9AB1GoxvYA@chrisdown.name \
    --to=chris@chrisdown.name \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=guro@fb.com \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=shakeelb@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.