Skip to content

Commit 6a5b18d

Browse files
namhyungtorvalds
authored andcommitted
memcg: move page-freeing code out of lock
Move page-freeing code out of swap_cgroup_mutex in the hope that it could reduce few of theoretical contentions between swapons and/or swapoffs. This is just a cleanup, no functional changes. Signed-off-by: Namhyung Kim <namhyung@gmail.com> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Balbir Singh <balbir@linux.vnet.ibm.com> Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> Cc: Michal Hocko <mhocko@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 33278f7 commit 6a5b18d

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

‎mm/page_cgroup.c‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,8 @@ int swap_cgroup_swapon(int type, unsigned long max_pages)
492492
/* memory shortage */
493493
ctrl->map = NULL;
494494
ctrl->length = 0;
495-
vfree(array);
496495
mutex_unlock(&swap_cgroup_mutex);
496+
vfree(array);
497497
goto nomem;
498498
}
499499
mutex_unlock(&swap_cgroup_mutex);
@@ -508,25 +508,29 @@ int swap_cgroup_swapon(int type, unsigned long max_pages)
508508

509509
void swap_cgroup_swapoff(int type)
510510
{
511-
int i;
511+
struct page **map;
512+
unsigned long i, length;
512513
struct swap_cgroup_ctrl *ctrl;
513514

514515
if (!do_swap_account)
515516
return;
516517

517518
mutex_lock(&swap_cgroup_mutex);
518519
ctrl = &swap_cgroup_ctrl[type];
519-
if (ctrl->map) {
520-
for (i = 0; i < ctrl->length; i++) {
521-
struct page *page = ctrl->map[i];
520+
map = ctrl->map;
521+
length = ctrl->length;
522+
ctrl->map = NULL;
523+
ctrl->length = 0;
524+
mutex_unlock(&swap_cgroup_mutex);
525+
526+
if (map) {
527+
for (i = 0; i < length; i++) {
528+
struct page *page = map[i];
522529
if (page)
523530
__free_page(page);
524531
}
525-
vfree(ctrl->map);
526-
ctrl->map = NULL;
527-
ctrl->length = 0;
532+
vfree(map);
528533
}
529-
mutex_unlock(&swap_cgroup_mutex);
530534
}
531535

532536
#endif

0 commit comments

Comments
 (0)