Skip to content

Commit fdd64ed

Browse files
joergroedelrafaeljw
authored andcommitted
PM / hibernate: Iterate over set bits instead of PFNs in swsusp_free()
The existing implementation of swsusp_free iterates over all pfns in the system and checks every bit in the two memory bitmaps. This doesn't scale very well with large numbers of pfns, especially when the bitmaps are not populated very densly. Change the algorithm to iterate over the set bits in the bitmaps instead to make it scale better in large memory configurations. Also add a memory_bm_clear_current() helper function that clears the bit for the last position returned from the memory bitmap. This new version adds a !NULL check for the memory bitmaps before they are walked. Not doing so causes a kernel crash when the bitmaps are NULL. Signed-off-by: Joerg Roedel <jroedel@suse.de> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 905563f commit fdd64ed

1 file changed

Lines changed: 39 additions & 15 deletions

File tree

‎kernel/power/snapshot.c‎

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,14 @@ static void memory_bm_clear_bit(struct memory_bitmap *bm, unsigned long pfn)
725725
clear_bit(bit, addr);
726726
}
727727

728+
static void memory_bm_clear_current(struct memory_bitmap *bm)
729+
{
730+
int bit;
731+
732+
bit = max(bm->cur.node_bit - 1, 0);
733+
clear_bit(bit, bm->cur.node->data);
734+
}
735+
728736
static int memory_bm_test_bit(struct memory_bitmap *bm, unsigned long pfn)
729737
{
730738
void *addr;
@@ -1333,23 +1341,39 @@ static struct memory_bitmap copy_bm;
13331341

13341342
void swsusp_free(void)
13351343
{
1336-
struct zone *zone;
1337-
unsigned long pfn, max_zone_pfn;
1344+
unsigned long fb_pfn, fr_pfn;
13381345

1339-
for_each_populated_zone(zone) {
1340-
max_zone_pfn = zone_end_pfn(zone);
1341-
for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++)
1342-
if (pfn_valid(pfn)) {
1343-
struct page *page = pfn_to_page(pfn);
1344-
1345-
if (swsusp_page_is_forbidden(page) &&
1346-
swsusp_page_is_free(page)) {
1347-
swsusp_unset_page_forbidden(page);
1348-
swsusp_unset_page_free(page);
1349-
__free_page(page);
1350-
}
1351-
}
1346+
if (!forbidden_pages_map || !free_pages_map)
1347+
goto out;
1348+
1349+
memory_bm_position_reset(forbidden_pages_map);
1350+
memory_bm_position_reset(free_pages_map);
1351+
1352+
loop:
1353+
fr_pfn = memory_bm_next_pfn(free_pages_map);
1354+
fb_pfn = memory_bm_next_pfn(forbidden_pages_map);
1355+
1356+
/*
1357+
* Find the next bit set in both bitmaps. This is guaranteed to
1358+
* terminate when fb_pfn == fr_pfn == BM_END_OF_MAP.
1359+
*/
1360+
do {
1361+
if (fb_pfn < fr_pfn)
1362+
fb_pfn = memory_bm_next_pfn(forbidden_pages_map);
1363+
if (fr_pfn < fb_pfn)
1364+
fr_pfn = memory_bm_next_pfn(free_pages_map);
1365+
} while (fb_pfn != fr_pfn);
1366+
1367+
if (fr_pfn != BM_END_OF_MAP && pfn_valid(fr_pfn)) {
1368+
struct page *page = pfn_to_page(fr_pfn);
1369+
1370+
memory_bm_clear_current(forbidden_pages_map);
1371+
memory_bm_clear_current(free_pages_map);
1372+
__free_page(page);
1373+
goto loop;
13521374
}
1375+
1376+
out:
13531377
nr_copy_pages = 0;
13541378
nr_meta_pages = 0;
13551379
restore_pblist = NULL;

0 commit comments

Comments
 (0)