From: Phil Carmody <ext-phil.2.carmody@nokia.com>
To: balbir@linux.vnet.ibm.com, nishimura@mxp.nes.nec.co.jp,
kamezawa.hiroyu@jp.fujitsu.com
Cc: akpm@linux-foundation.org, kirill@shutemov.name,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] mm: remove unnecessary use of atomic
Date: Wed, 5 May 2010 14:21:48 +0300 [thread overview]
Message-ID: <1273058509-16625-1-git-send-email-ext-phil.2.carmody@nokia.com> (raw)
From: Phil Carmody <ext-phil.2.carmody@nokia.com>
The bottom 4 hunks are atomically changing memory to which there
are no aliases as it's freshly allocated, so there's no need to
use atomic operations.
The other hunks are just atomic_read and atomic_set, and do not
involve any read-modify-write. The use of atomic_{read,set}
doesn't prevent a read/write or write/write race, so if a race
were possible (I'm not saying one is), then it would still be
there even with atomic_set.
See:
http://digitalvampire.org/blog/index.php/2007/05/13/atomic-cargo-cults/
Signed-off-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
Acked-by: Kirill A. Shutemov <kirill@shutemov.name>
---
mm/memcontrol.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 6c755de..90e32b2 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -151,7 +151,7 @@ struct mem_cgroup_threshold {
struct mem_cgroup_threshold_ary {
/* An array index points to threshold just below usage. */
- atomic_t current_threshold;
+ int current_threshold;
/* Size of entries[] */
unsigned int size;
/* Array of thresholds */
@@ -3327,7 +3327,7 @@ static void __mem_cgroup_threshold(struct mem_cgroup *memcg, bool swap)
* If it's not true, a threshold was crossed after last
* call of __mem_cgroup_threshold().
*/
- i = atomic_read(&t->current_threshold);
+ i = t->current_threshold;
/*
* Iterate backward over array of thresholds starting from
@@ -3351,7 +3351,7 @@ static void __mem_cgroup_threshold(struct mem_cgroup *memcg, bool swap)
eventfd_signal(t->entries[i].eventfd, 1);
/* Update current_threshold */
- atomic_set(&t->current_threshold, i - 1);
+ t->current_threshold = i - 1;
unlock:
rcu_read_unlock();
}
@@ -3429,7 +3429,7 @@ static int mem_cgroup_register_event(struct cgroup *cgrp, struct cftype *cft,
compare_thresholds, NULL);
/* Find current threshold */
- atomic_set(&thresholds_new->current_threshold, -1);
+ thresholds_new->current_threshold = -1;
for (i = 0; i < size; i++) {
if (thresholds_new->entries[i].threshold < usage) {
/*
@@ -3437,7 +3437,7 @@ static int mem_cgroup_register_event(struct cgroup *cgrp, struct cftype *cft,
* until rcu_assign_pointer(), so it's safe to increment
* it here.
*/
- atomic_inc(&thresholds_new->current_threshold);
+ ++thresholds_new->current_threshold;
}
}
@@ -3508,7 +3508,7 @@ static int mem_cgroup_unregister_event(struct cgroup *cgrp, struct cftype *cft,
thresholds_new->size = size;
/* Copy thresholds and find current threshold */
- atomic_set(&thresholds_new->current_threshold, -1);
+ thresholds_new->current_threshold = -1;
for (i = 0, j = 0; i < thresholds->size; i++) {
if (thresholds->entries[i].eventfd == eventfd)
continue;
@@ -3520,7 +3520,7 @@ static int mem_cgroup_unregister_event(struct cgroup *cgrp, struct cftype *cft,
* until rcu_assign_pointer(), so it's safe to increment
* it here.
*/
- atomic_inc(&thresholds_new->current_threshold);
+ ++thresholds_new->current_threshold;
}
j++;
}
--
1.6.0.4
--
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>
next reply other threads:[~2010-05-05 11:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-05 11:21 Phil Carmody [this message]
2010-05-05 11:21 ` [PATCH 2/2] mm: memcontrol - uninitialised return value Phil Carmody
2010-05-06 6:18 ` KAMEZAWA Hiroyuki
2010-05-06 21:24 ` Andrew Morton
2010-05-07 1:07 ` KAMEZAWA Hiroyuki
2010-05-07 5:15 ` Kirill A. Shutemov
2010-05-06 6:18 ` [PATCH 1/2] mm: remove unnecessary use of atomic KAMEZAWA Hiroyuki
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=1273058509-16625-1-git-send-email-ext-phil.2.carmody@nokia.com \
--to=ext-phil.2.carmody@nokia.com \
--cc=akpm@linux-foundation.org \
--cc=balbir@linux.vnet.ibm.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nishimura@mxp.nes.nec.co.jp \
/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