From: Greg Thelen <gthelen@google.com>
To: Tejun Heo <tj@kernel.org>,
Christoph Lameter <cl@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@suse.cz>,
Balbir Singh <bsingharora@gmail.com>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
handai.szj@taobao.com, Andrew Morton <akpm@linux-foundation.org>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
cgroups@vger.kernel.org, linux-mm@kvack.org,
Greg Thelen <gthelen@google.com>
Subject: [PATCH 0/3] fix unsigned pcp adjustments
Date: Sun, 27 Oct 2013 00:44:33 -0700 [thread overview]
Message-ID: <1382859876-28196-1-git-send-email-gthelen@google.com> (raw)
As of v3.11-9444-g3ea67d0 "memcg: add per cgroup writeback pages accounting"
memcg use of __this_cpu_add(counter, -nr_pages) leads to incorrect statistic
values because the negated nr_pages is not sign extended (counter is long,
nr_pages is unsigned int). The memcg fix is __this_cpu_sub(counter, nr_pages).
But that doesn't simply work because __this_cpu_sub(counter, nr_pages) was
implemented as __this_cpu_add(counter, -nr_pages) which suffers the same
problem. Example:
unsigned int delta = 1
preempt_disable()
this_cpu_write(long_counter, 0)
this_cpu_sub(long_counter, delta)
preempt_enable()
Before this change long_counter on a 64 bit machine ends with value 0xffffffff,
rather than 0xffffffffffffffff. This is because this_cpu_sub(pcp, delta) boils
down to:
long_counter = 0 + 0xffffffff
Patch 1 creates a test module for percpu counters operations which demonstrates
the __this_cpu_sub() problems. This patch is independent can be discarded if
there is no interest.
Patch 2 fixes __this_cpu_sub() to work with unsigned adjustments.
Patch 3 uses __this_cpu_sub() in memcg.
An alternative smaller solution is for memcg to use:
__this_cpu_add(counter, -(int)nr_pages)
admitting that __this_cpu_add/sub() doesn't work with unsigned adjustments. But
I felt like fixing the core services to prevent this in the future.
Greg Thelen (3):
percpu counter: test module
percpu counter: cast this_cpu_sub() adjustment
memcg: use __this_cpu_sub to decrement stats
arch/x86/include/asm/percpu.h | 3 +-
include/linux/percpu.h | 8 +--
lib/Kconfig.debug | 9 +++
lib/Makefile | 2 +
lib/percpu_test.c | 138 ++++++++++++++++++++++++++++++++++++++++++
mm/memcontrol.c | 2 +-
6 files changed, 156 insertions(+), 6 deletions(-)
create mode 100644 lib/percpu_test.c
--
1.8.4.1
--
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>
WARNING: multiple messages have this Message-ID (diff)
From: Greg Thelen <gthelen@google.com>
To: Tejun Heo <tj@kernel.org>,
Christoph Lameter <cl@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@suse.cz>,
Balbir Singh <bsingharora@gmail.com>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
handai.szj@taobao.com, Andrew Morton <akpm@linux-foundation.org>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
cgroups@vger.kernel.org, linux-mm@kvack.org,
Greg Thelen <gthelen@google.com>
Subject: [PATCH 0/3] fix unsigned pcp adjustments
Date: Sun, 27 Oct 2013 00:44:33 -0700 [thread overview]
Message-ID: <1382859876-28196-1-git-send-email-gthelen@google.com> (raw)
As of v3.11-9444-g3ea67d0 "memcg: add per cgroup writeback pages accounting"
memcg use of __this_cpu_add(counter, -nr_pages) leads to incorrect statistic
values because the negated nr_pages is not sign extended (counter is long,
nr_pages is unsigned int). The memcg fix is __this_cpu_sub(counter, nr_pages).
But that doesn't simply work because __this_cpu_sub(counter, nr_pages) was
implemented as __this_cpu_add(counter, -nr_pages) which suffers the same
problem. Example:
unsigned int delta = 1
preempt_disable()
this_cpu_write(long_counter, 0)
this_cpu_sub(long_counter, delta)
preempt_enable()
Before this change long_counter on a 64 bit machine ends with value 0xffffffff,
rather than 0xffffffffffffffff. This is because this_cpu_sub(pcp, delta) boils
down to:
long_counter = 0 + 0xffffffff
Patch 1 creates a test module for percpu counters operations which demonstrates
the __this_cpu_sub() problems. This patch is independent can be discarded if
there is no interest.
Patch 2 fixes __this_cpu_sub() to work with unsigned adjustments.
Patch 3 uses __this_cpu_sub() in memcg.
An alternative smaller solution is for memcg to use:
__this_cpu_add(counter, -(int)nr_pages)
admitting that __this_cpu_add/sub() doesn't work with unsigned adjustments. But
I felt like fixing the core services to prevent this in the future.
Greg Thelen (3):
percpu counter: test module
percpu counter: cast this_cpu_sub() adjustment
memcg: use __this_cpu_sub to decrement stats
arch/x86/include/asm/percpu.h | 3 +-
include/linux/percpu.h | 8 +--
lib/Kconfig.debug | 9 +++
lib/Makefile | 2 +
lib/percpu_test.c | 138 ++++++++++++++++++++++++++++++++++++++++++
mm/memcontrol.c | 2 +-
6 files changed, 156 insertions(+), 6 deletions(-)
create mode 100644 lib/percpu_test.c
--
1.8.4.1
next reply other threads:[~2013-10-27 7:44 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-27 7:44 Greg Thelen [this message]
2013-10-27 7:44 ` [PATCH 0/3] fix unsigned pcp adjustments Greg Thelen
2013-10-27 7:44 ` [PATCH 1/3] percpu counter: test module Greg Thelen
2013-10-27 7:44 ` Greg Thelen
[not found] ` <1382859876-28196-2-git-send-email-gthelen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2013-10-27 11:18 ` Tejun Heo
2013-10-27 11:18 ` Tejun Heo
2013-10-27 11:18 ` Tejun Heo
2013-10-27 7:44 ` [PATCH 2/3] percpu counter: cast this_cpu_sub() adjustment Greg Thelen
2013-10-27 7:44 ` Greg Thelen
[not found] ` <1382859876-28196-3-git-send-email-gthelen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2013-10-27 11:22 ` Tejun Heo
2013-10-27 11:22 ` Tejun Heo
2013-10-27 11:22 ` Tejun Heo
2013-10-27 12:04 ` Andrew Morton
2013-10-27 12:04 ` Andrew Morton
[not found] ` <20131027050429.7fcc2ed5.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2013-10-27 13:00 ` Tejun Heo
2013-10-27 13:00 ` Tejun Heo
2013-10-27 13:00 ` Tejun Heo
[not found] ` <20131027130036.GN14934-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2013-10-27 16:13 ` Greg Thelen
2013-10-27 16:13 ` Greg Thelen
2013-10-27 16:13 ` Greg Thelen
2013-10-27 17:12 ` Greg Thelen
2013-10-27 17:12 ` Greg Thelen
2013-10-27 17:12 ` Greg Thelen
2013-10-27 7:44 ` [PATCH 3/3] memcg: use __this_cpu_sub to decrement stats Greg Thelen
2013-10-27 7:44 ` Greg Thelen
[not found] ` <1382859876-28196-4-git-send-email-gthelen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2013-10-27 11:24 ` Tejun Heo
2013-10-27 11:24 ` Tejun Heo
2013-10-27 11:24 ` Tejun Heo
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=1382859876-28196-1-git-send-email-gthelen@google.com \
--to=gthelen@google.com \
--cc=akpm@linux-foundation.org \
--cc=bsingharora@gmail.com \
--cc=cgroups@vger.kernel.org \
--cc=cl@linux-foundation.org \
--cc=handai.szj@taobao.com \
--cc=hannes@cmpxchg.org \
--cc=hpa@zytor.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.cz \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=x86@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 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.