Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 86825
b: refs/heads/master
c: 2680eed
h: refs/heads/master
i:
  86823: 9de700c
v: v3
  • Loading branch information
Hugh Dickins authored and Linus Torvalds committed Mar 5, 2008
1 parent 0392a57 commit 093c1e9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6d48ff8bcfd403ec8d3ef7a56538ea9e6f773b9c
refs/heads/master: 2680eed723b664d83e6181ae275fac0ec8fa05ff
49 changes: 43 additions & 6 deletions trunk/mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ static void lock_page_cgroup(struct page *page)
bit_spin_lock(PAGE_CGROUP_LOCK_BIT, &page->page_cgroup);
}

static int try_lock_page_cgroup(struct page *page)
{
return bit_spin_trylock(PAGE_CGROUP_LOCK_BIT, &page->page_cgroup);
}

static void unlock_page_cgroup(struct page *page)
{
bit_spin_unlock(PAGE_CGROUP_LOCK_BIT, &page->page_cgroup);
Expand Down Expand Up @@ -348,17 +353,49 @@ int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem)
void mem_cgroup_move_lists(struct page *page, bool active)
{
struct page_cgroup *pc;
struct mem_cgroup *mem;
struct mem_cgroup_per_zone *mz;
unsigned long flags;

pc = page_get_page_cgroup(page);
if (!pc)
/*
* We cannot lock_page_cgroup while holding zone's lru_lock,
* because other holders of lock_page_cgroup can be interrupted
* with an attempt to rotate_reclaimable_page. But we cannot
* safely get to page_cgroup without it, so just try_lock it:
* mem_cgroup_isolate_pages allows for page left on wrong list.
*/
if (!try_lock_page_cgroup(page))
return;

mz = page_cgroup_zoneinfo(pc);
spin_lock_irqsave(&mz->lru_lock, flags);
__mem_cgroup_move_lists(pc, active);
spin_unlock_irqrestore(&mz->lru_lock, flags);
/*
* Now page_cgroup is stable, but we cannot acquire mz->lru_lock
* while holding it, because mem_cgroup_force_empty_list does the
* reverse. Get a hold on the mem_cgroup before unlocking, so that
* the zoneinfo remains stable, then take mz->lru_lock; then check
* that page still points to pc and pc (even if freed and reassigned
* to that same page meanwhile) still points to the same mem_cgroup.
* Then we know mz still points to the right spinlock, so it's safe
* to move_lists (page->page_cgroup might be reset while we do so, but
* that doesn't matter: pc->page is stable till we drop mz->lru_lock).
* We're being a little naughty not to try_lock_page_cgroup again
* inside there, but we are safe, aren't we? Aren't we? Whistle...
*/
pc = page_get_page_cgroup(page);
if (pc) {
mem = pc->mem_cgroup;
mz = page_cgroup_zoneinfo(pc);
css_get(&mem->css);

unlock_page_cgroup(page);

spin_lock_irqsave(&mz->lru_lock, flags);
if (page_get_page_cgroup(page) == pc && pc->mem_cgroup == mem)
__mem_cgroup_move_lists(pc, active);
spin_unlock_irqrestore(&mz->lru_lock, flags);

css_put(&mem->css);
} else
unlock_page_cgroup(page);
}

/*
Expand Down

0 comments on commit 093c1e9

Please sign in to comment.