From: Bob Liu <lliubbo@gmail.com>
To: linux-mm@kvack.org
Cc: akpm@linux-foundation.org, kamezawa.hiroyu@jp.fujitsu.com,
mhocko@suse.cz, jweiner@redhat.com, bsingharora@gmail.com,
Bob Liu <lliubbo@gmail.com>
Subject: [PATCH v2] page_cgroup: add helper function to get swap_cgroup
Date: Fri, 2 Dec 2011 18:40:27 +0800 [thread overview]
Message-ID: <1322822427-7691-1-git-send-email-lliubbo@gmail.com> (raw)
There are multi places need to get swap_cgroup, so add a helper
function:
static struct swap_cgroup *swap_cgroup_getsc(swp_entry_t ent,
struct swap_cgroup_ctrl **ctrl);
to simple the code.
v1 -> v2:
- add parameter struct swap_cgroup_ctrl **ctrl suggested by Michal
Signed-off-by: Bob Liu <lliubbo@gmail.com>
---
mm/page_cgroup.c | 57 ++++++++++++++++++++++-------------------------------
1 files changed, 24 insertions(+), 33 deletions(-)
diff --git a/mm/page_cgroup.c b/mm/page_cgroup.c
index f0559e0..1970e8a 100644
--- a/mm/page_cgroup.c
+++ b/mm/page_cgroup.c
@@ -362,6 +362,27 @@ not_enough_page:
return -ENOMEM;
}
+static struct swap_cgroup *swap_cgroup_getsc(swp_entry_t ent,
+ struct swap_cgroup_ctrl **ctrl)
+{
+ int type = swp_type(ent);
+ unsigned long offset = swp_offset(ent);
+ unsigned long idx = offset / SC_PER_PAGE;
+ unsigned long pos = offset & SC_POS_MASK;
+ struct swap_cgroup_ctrl *temp_ctrl;
+ struct page *mappage;
+ struct swap_cgroup *sc;
+
+ temp_ctrl = &swap_cgroup_ctrl[type];
+ if (ctrl)
+ *ctrl = temp_ctrl;
+
+ mappage = temp_ctrl->map[idx];
+ sc = page_address(mappage);
+ sc += pos;
+ return sc;
+}
+
/**
* swap_cgroup_cmpxchg - cmpxchg mem_cgroup's id for this swp_entry.
* @end: swap entry to be cmpxchged
@@ -374,21 +395,13 @@ not_enough_page:
unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
unsigned short old, unsigned short new)
{
- int type = swp_type(ent);
- unsigned long offset = swp_offset(ent);
- unsigned long idx = offset / SC_PER_PAGE;
- unsigned long pos = offset & SC_POS_MASK;
struct swap_cgroup_ctrl *ctrl;
- struct page *mappage;
struct swap_cgroup *sc;
unsigned long flags;
unsigned short retval;
- ctrl = &swap_cgroup_ctrl[type];
+ sc = swap_cgroup_getsc(ent, &ctrl);
- mappage = ctrl->map[idx];
- sc = page_address(mappage);
- sc += pos;
spin_lock_irqsave(&ctrl->lock, flags);
retval = sc->id;
if (retval == old)
@@ -409,21 +422,13 @@ unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
*/
unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
{
- int type = swp_type(ent);
- unsigned long offset = swp_offset(ent);
- unsigned long idx = offset / SC_PER_PAGE;
- unsigned long pos = offset & SC_POS_MASK;
struct swap_cgroup_ctrl *ctrl;
- struct page *mappage;
struct swap_cgroup *sc;
unsigned short old;
unsigned long flags;
- ctrl = &swap_cgroup_ctrl[type];
+ sc = swap_cgroup_getsc(ent, &ctrl);
- mappage = ctrl->map[idx];
- sc = page_address(mappage);
- sc += pos;
spin_lock_irqsave(&ctrl->lock, flags);
old = sc->id;
sc->id = id;
@@ -440,21 +445,7 @@ unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
*/
unsigned short lookup_swap_cgroup(swp_entry_t ent)
{
- int type = swp_type(ent);
- unsigned long offset = swp_offset(ent);
- unsigned long idx = offset / SC_PER_PAGE;
- unsigned long pos = offset & SC_POS_MASK;
- struct swap_cgroup_ctrl *ctrl;
- struct page *mappage;
- struct swap_cgroup *sc;
- unsigned short ret;
-
- ctrl = &swap_cgroup_ctrl[type];
- mappage = ctrl->map[idx];
- sc = page_address(mappage);
- sc += pos;
- ret = sc->id;
- return ret;
+ return swap_cgroup_getsc(ent, NULL)->id;
}
int swap_cgroup_swapon(int type, unsigned long max_pages)
--
1.7.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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next reply other threads:[~2011-12-02 10:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-02 10:40 Bob Liu [this message]
2011-12-02 10:50 ` [PATCH v2] page_cgroup: add helper function to get swap_cgroup Michal Hocko
2011-12-05 0:51 ` KAMEZAWA Hiroyuki
2011-12-12 14:54 ` 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=1322822427-7691-1-git-send-email-lliubbo@gmail.com \
--to=lliubbo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=bsingharora@gmail.com \
--cc=jweiner@redhat.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.cz \
/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;
as well as URLs for NNTP newsgroup(s).