diff options
author | Bob Liu <lliubbo@gmail.com> | 2012-01-12 20:18:48 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-01-12 23:13:07 -0500 |
commit | 9fb4b7cc0724f178d4b24a2a566ea1e7cb120b82 (patch) | |
tree | 0f2db9102d46f5e5c8492864fb1bd21f2e7cd768 /mm/page_cgroup.c | |
parent | 40f23a21a8501c1b2c65c50c19b516488ac31313 (diff) |
page_cgroup: add helper function to get swap_cgroup
There are multiple places which need to get the swap_cgroup address, so
add a helper function:
static struct swap_cgroup *swap_cgroup_getsc(swp_entry_t ent,
struct swap_cgroup_ctrl **ctrl);
to simplify the code.
Signed-off-by: Bob Liu <lliubbo@gmail.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Johannes Weiner <jweiner@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/page_cgroup.c')
-rw-r--r-- | mm/page_cgroup.c | 56 |
1 files changed, 20 insertions, 36 deletions
diff --git a/mm/page_cgroup.c b/mm/page_cgroup.c index e910524e5a08..b99d19edf89b 100644 --- a/mm/page_cgroup.c +++ b/mm/page_cgroup.c | |||
@@ -334,7 +334,6 @@ struct swap_cgroup { | |||
334 | unsigned short id; | 334 | unsigned short id; |
335 | }; | 335 | }; |
336 | #define SC_PER_PAGE (PAGE_SIZE/sizeof(struct swap_cgroup)) | 336 | #define SC_PER_PAGE (PAGE_SIZE/sizeof(struct swap_cgroup)) |
337 | #define SC_POS_MASK (SC_PER_PAGE - 1) | ||
338 | 337 | ||
339 | /* | 338 | /* |
340 | * SwapCgroup implements "lookup" and "exchange" operations. | 339 | * SwapCgroup implements "lookup" and "exchange" operations. |
@@ -376,6 +375,21 @@ not_enough_page: | |||
376 | return -ENOMEM; | 375 | return -ENOMEM; |
377 | } | 376 | } |
378 | 377 | ||
378 | static struct swap_cgroup *lookup_swap_cgroup(swp_entry_t ent, | ||
379 | struct swap_cgroup_ctrl **ctrlp) | ||
380 | { | ||
381 | pgoff_t offset = swp_offset(ent); | ||
382 | struct swap_cgroup_ctrl *ctrl; | ||
383 | struct page *mappage; | ||
384 | |||
385 | ctrl = &swap_cgroup_ctrl[swp_type(ent)]; | ||
386 | if (ctrlp) | ||
387 | *ctrlp = ctrl; | ||
388 | |||
389 | mappage = ctrl->map[offset / SC_PER_PAGE]; | ||
390 | return page_address(mappage) + offset % SC_PER_PAGE; | ||
391 | } | ||
392 | |||
379 | /** | 393 | /** |
380 | * swap_cgroup_cmpxchg - cmpxchg mem_cgroup's id for this swp_entry. | 394 | * swap_cgroup_cmpxchg - cmpxchg mem_cgroup's id for this swp_entry. |
381 | * @end: swap entry to be cmpxchged | 395 | * @end: swap entry to be cmpxchged |
@@ -388,21 +402,13 @@ not_enough_page: | |||
388 | unsigned short swap_cgroup_cmpxchg(swp_entry_t ent, | 402 | unsigned short swap_cgroup_cmpxchg(swp_entry_t ent, |
389 | unsigned short old, unsigned short new) | 403 | unsigned short old, unsigned short new) |
390 | { | 404 | { |
391 | int type = swp_type(ent); | ||
392 | unsigned long offset = swp_offset(ent); | ||
393 | unsigned long idx = offset / SC_PER_PAGE; | ||
394 | unsigned long pos = offset & SC_POS_MASK; | ||
395 | struct swap_cgroup_ctrl *ctrl; | 405 | struct swap_cgroup_ctrl *ctrl; |
396 | struct page *mappage; | ||
397 | struct swap_cgroup *sc; | 406 | struct swap_cgroup *sc; |
398 | unsigned long flags; | 407 | unsigned long flags; |
399 | unsigned short retval; | 408 | unsigned short retval; |
400 | 409 | ||
401 | ctrl = &swap_cgroup_ctrl[type]; | 410 | sc = lookup_swap_cgroup(ent, &ctrl); |
402 | 411 | ||
403 | mappage = ctrl->map[idx]; | ||
404 | sc = page_address(mappage); | ||
405 | sc += pos; | ||
406 | spin_lock_irqsave(&ctrl->lock, flags); | 412 | spin_lock_irqsave(&ctrl->lock, flags); |
407 | retval = sc->id; | 413 | retval = sc->id; |
408 | if (retval == old) | 414 | if (retval == old) |
@@ -423,21 +429,13 @@ unsigned short swap_cgroup_cmpxchg(swp_entry_t ent, | |||
423 | */ | 429 | */ |
424 | unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id) | 430 | unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id) |
425 | { | 431 | { |
426 | int type = swp_type(ent); | ||
427 | unsigned long offset = swp_offset(ent); | ||
428 | unsigned long idx = offset / SC_PER_PAGE; | ||
429 | unsigned long pos = offset & SC_POS_MASK; | ||
430 | struct swap_cgroup_ctrl *ctrl; | 432 | struct swap_cgroup_ctrl *ctrl; |
431 | struct page *mappage; | ||
432 | struct swap_cgroup *sc; | 433 | struct swap_cgroup *sc; |
433 | unsigned short old; | 434 | unsigned short old; |
434 | unsigned long flags; | 435 | unsigned long flags; |
435 | 436 | ||
436 | ctrl = &swap_cgroup_ctrl[type]; | 437 | sc = lookup_swap_cgroup(ent, &ctrl); |
437 | 438 | ||
438 | mappage = ctrl->map[idx]; | ||
439 | sc = page_address(mappage); | ||
440 | sc += pos; | ||
441 | spin_lock_irqsave(&ctrl->lock, flags); | 439 | spin_lock_irqsave(&ctrl->lock, flags); |
442 | old = sc->id; | 440 | old = sc->id; |
443 | sc->id = id; | 441 | sc->id = id; |
@@ -447,28 +445,14 @@ unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id) | |||
447 | } | 445 | } |
448 | 446 | ||
449 | /** | 447 | /** |
450 | * lookup_swap_cgroup - lookup mem_cgroup tied to swap entry | 448 | * lookup_swap_cgroup_id - lookup mem_cgroup id tied to swap entry |
451 | * @ent: swap entry to be looked up. | 449 | * @ent: swap entry to be looked up. |
452 | * | 450 | * |
453 | * Returns CSS ID of mem_cgroup at success. 0 at failure. (0 is invalid ID) | 451 | * Returns CSS ID of mem_cgroup at success. 0 at failure. (0 is invalid ID) |
454 | */ | 452 | */ |
455 | unsigned short lookup_swap_cgroup(swp_entry_t ent) | 453 | unsigned short lookup_swap_cgroup_id(swp_entry_t ent) |
456 | { | 454 | { |
457 | int type = swp_type(ent); | 455 | return lookup_swap_cgroup(ent, NULL)->id; |
458 | unsigned long offset = swp_offset(ent); | ||
459 | unsigned long idx = offset / SC_PER_PAGE; | ||
460 | unsigned long pos = offset & SC_POS_MASK; | ||
461 | struct swap_cgroup_ctrl *ctrl; | ||
462 | struct page *mappage; | ||
463 | struct swap_cgroup *sc; | ||
464 | unsigned short ret; | ||
465 | |||
466 | ctrl = &swap_cgroup_ctrl[type]; | ||
467 | mappage = ctrl->map[idx]; | ||
468 | sc = page_address(mappage); | ||
469 | sc += pos; | ||
470 | ret = sc->id; | ||
471 | return ret; | ||
472 | } | 456 | } |
473 | 457 | ||
474 | int swap_cgroup_swapon(int type, unsigned long max_pages) | 458 | int swap_cgroup_swapon(int type, unsigned long max_pages) |