Faster SWSUSP free page counting
Subsystems (3)
PATCH 1/1 Faster SWSUSP free page counting
Hi.
This patch improves the speed of SWSUSP's count_and_copy_data_pages function by generating a map of the free pages before iterating through the list of pages. The net result is to go from O(n^2) to O(n), if I remember my computer science correctly.
Regards,
Nigel
include/linux/page-flags.h +5 -0
@@ -74,6 +74,7 @@#define PG_mappedtodisk 17/* Has blocks allocated on-disk */ #define PG_reclaim 18/* To be reclaimed asap */ #define PG_compound 19/* Part of a compound page */ +#define PG_free 20/* swsusp - page is unused - dont rely on outside swsusp! */ /* * Global page accounting. One instance per CPU. Only unsigned longs are
@@ -237,6 +238,10 @@#define ClearPageNosave (page) clear_bit(PG_nosave, &(page)->flags)#define TestClearPageNosave (page) test_and_clear_bit(PG_nosave, &(page)->flags) +#define PageFree (page) test_bit(PG_free, &(page)->flags) +#define SetPageFree (page) set_bit(PG_free, &(page)->flags) +#define ClearPageFree (page) clear_bit(PG_free, &(page)->flags) +#define PageDirect (page) test_bit(PG_direct, &(page)->flags)#define SetPageDirect (page) set_bit(PG_direct, &(page)->flags)#define TestSetPageDirect (page) test_and_set_bit(PG_direct, &(page)->flags)
kernel/suspend.c +2 -0
@@ -479,6 +479,8 @@#else BUG_ON (max_pfn != num_physpages);#endif +generate_free_page_map (); +for (pfn =0 ; pfn < max_pfn; pfn++) { page =pfn_to_page (pfn);if (PageHighMem (page))
mm/page_alloc.c +31 -16
57 lines not on this page · raw message
Hi!
Quoted 4 lines
This patch improves the speed of SWSUSP's
count_and_copy_data_pagesfunction by generating a map of the free pages before iterating through the list of pages. The net result is to go from O(n^2) to O(n), if I remember my computer science correctly.
Is the speed difference noticable?
If yes than okay, but generate_free_page_map() should still be moved into kernel/suspend.c.
Pavel
Signature · 2 lines
Horseback riding is like software... ...vgf orggre jura vgf serr.
Hi.
The speed difference depends of course upon the number of pages free and the degree of fragmentation. I guess the easy answer is that it was written and kept because it helped. Having talked to Andrew about the use of page flags, I'll do some more changes before we put it to Linus - I'll use a dynamically allocated bitmap instead of pageflags.
Regards,
Nigel
Quoted 12 lines · Pavel Machek
Hi!
Quoted 4 lines
This patch improves the speed of SWSUSP's
count_and_copy_data_pagesfunction by generating a map of the free pages before iterating through the list of pages. The net result is to go from O(n^2) to O(n), if I remember my computer science correctly.Is the speed difference noticable?
If yes than okay, but
generate_free_page_map()should still be moved intokernel/suspend.c.
Pavel
Signature · 6 lines
Nigel Cunningham 495 St Georges Road South, Hastings 4201, New Zealand Be diligent to present yourself approved to God as a workman who does not need to be ashamed, handling accurately the word of truth. -- 2 Timothy 2:14, NASB.