[Suspend2][ 09/20] [Suspend2] Get size of a free region.

Nigel Cunningham
2006-06-26T22:36:02Z

Get the size of a range of free pages beginning at the given page, and
finishing at the end of the zone in which the page is found if not before.
The page given may not itself be free, in which case the return value will
be zero.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

kernel/power/prepare_image.c | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/kernel/power/prepare_image.c b/kernel/power/prepare_image.c
index bf38334..0030661 100644
--- a/kernel/power/prepare_image.c
+++ b/kernel/power/prepare_image.c
@@ -222,3 +222,21 @@ static void generate_free_page_map(void)
}
}

+/* size_of_free_region
+ *
+ * Description: Return the number of pages that are free, beginning with and
+ * including this one.
+ */
+static int size_of_free_region(struct page *page)
+{
+ struct zone *zone = page_zone(page);
+ struct page *posn = page, *last_in_zone =
+ pfn_to_page(zone->zone_start_pfn) + zone->spanned_pages - 1;
+
+ while (posn < last_in_zone && !PageInUse(posn)) {
+ BUG_ON(PagePageset2(posn));
+ posn++;
+ }
+ return (posn - page);