[PATCH 1/2] hugetlb reservations: move region tracking earlier

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Andy Whitcroft
Date: Friday, June 20, 2008 - 12:17 pm

Move the region tracking code much earlier so we can use it for page
presence tracking later on.  No code is changed, just its location.

Signed-off-by: Andy Whitcroft <apw@shadowen.org>
---
 mm/hugetlb.c |  246 +++++++++++++++++++++++++++++----------------------------
 1 files changed, 125 insertions(+), 121 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 0f76ed1..d701e39 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -47,6 +47,131 @@ static unsigned long __initdata default_hstate_size;
 static DEFINE_SPINLOCK(hugetlb_lock);
 
 /*
+ * Region tracking -- allows tracking of reservations and instantiated pages
+ *                    across the pages in a mapping.
+ */
+struct file_region {
+	struct list_head link;
+	long from;
+	long to;
+};
+
+static long region_add(struct list_head *head, long f, long t)
+{
+	struct file_region *rg, *nrg, *trg;
+
+	/* Locate the region we are either in or before. */
+	list_for_each_entry(rg, head, link)
+		if (f <= rg->to)
+			break;
+
+	/* Round our left edge to the current segment if it encloses us. */
+	if (f > rg->from)
+		f = rg->from;
+
+	/* Check for and consume any regions we now overlap with. */
+	nrg = rg;
+	list_for_each_entry_safe(rg, trg, rg->link.prev, link) {
+		if (&rg->link == head)
+			break;
+		if (rg->from > t)
+			break;
+
+		/* If this area reaches higher then extend our area to
+		 * include it completely.  If this is not the first area
+		 * which we intend to reuse, free it. */
+		if (rg->to > t)
+			t = rg->to;
+		if (rg != nrg) {
+			list_del(&rg->link);
+			kfree(rg);
+		}
+	}
+	nrg->from = f;
+	nrg->to = t;
+	return 0;
+}
+
+static long region_chg(struct list_head *head, long f, long t)
+{
+	struct file_region *rg, *nrg;
+	long chg = 0;
+
+	/* Locate the region we are before or in. */
+	list_for_each_entry(rg, head, link)
+		if (f <= rg->to)
+			break;
+
+	/* If we are below the current region then a new region is required.
+	 * Subtle, allocate a new region at the position but make it zero
+	 * size such that we can guarantee to record the reservation. */
+	if (&rg->link == head || t < rg->from) {
+		nrg = kmalloc(sizeof(*nrg), GFP_KERNEL);
+		if (!nrg)
+			return -ENOMEM;
+		nrg->from = f;
+		nrg->to   = f;
+		INIT_LIST_HEAD(&nrg->link);
+		list_add(&nrg->link, rg->link.prev);
+
+		return t - f;
+	}
+
+	/* Round our left edge to the current segment if it encloses us. */
+	if (f > rg->from)
+		f = rg->from;
+	chg = t - f;
+
+	/* Check for and consume any regions we now overlap with. */
+	list_for_each_entry(rg, rg->link.prev, link) {
+		if (&rg->link == head)
+			break;
+		if (rg->from > t)
+			return chg;
+
+		/* We overlap with this area, if it extends futher than
+		 * us then we must extend ourselves.  Account for its
+		 * existing reservation. */
+		if (rg->to > t) {
+			chg += rg->to - t;
+			t = rg->to;
+		}
+		chg -= rg->to - rg->from;
+	}
+	return chg;
+}
+
+static long region_truncate(struct list_head *head, long end)
+{
+	struct file_region *rg, *trg;
+	long chg = 0;
+
+	/* Locate the region we are either in or before. */
+	list_for_each_entry(rg, head, link)
+		if (end <= rg->to)
+			break;
+	if (&rg->link == head)
+		return 0;
+
+	/* If we are in the middle of a region then adjust it. */
+	if (end > rg->from) {
+		chg = rg->to - end;
+		rg->to = end;
+		rg = list_entry(rg->link.next, typeof(*rg), link);
+	}
+
+	/* Drop any remaining regions. */
+	list_for_each_entry_safe(rg, trg, rg->link.prev, link) {
+		if (&rg->link == head)
+			break;
+		chg += rg->to - rg->from;
+		list_del(&rg->link);
+		kfree(rg);
+	}
+	return chg;
+}
+
+/*
  * Convert the address within this vma to the page offset within
  * the mapping, in base page units.
  */
@@ -649,127 +774,6 @@ static void return_unused_surplus_pages(struct hstate *h,
 	}
 }
 
-struct file_region {
-	struct list_head link;
-	long from;
-	long to;
-};
-
-static long region_add(struct list_head *head, long f, long t)
-{
-	struct file_region *rg, *nrg, *trg;
-
-	/* Locate the region we are either in or before. */
-	list_for_each_entry(rg, head, link)
-		if (f <= rg->to)
-			break;
-
-	/* Round our left edge to the current segment if it encloses us. */
-	if (f > rg->from)
-		f = rg->from;
-
-	/* Check for and consume any regions we now overlap with. */
-	nrg = rg;
-	list_for_each_entry_safe(rg, trg, rg->link.prev, link) {
-		if (&rg->link == head)
-			break;
-		if (rg->from > t)
-			break;
-
-		/* If this area reaches higher then extend our area to
-		 * include it completely.  If this is not the first area
-		 * which we intend to reuse, free it. */
-		if (rg->to > t)
-			t = rg->to;
-		if (rg != nrg) {
-			list_del(&rg->link);
-			kfree(rg);
-		}
-	}
-	nrg->from = f;
-	nrg->to = t;
-	return 0;
-}
-
-static long region_chg(struct list_head *head, long f, long t)
-{
-	struct file_region *rg, *nrg;
-	long chg = 0;
-
-	/* Locate the region we are before or in. */
-	list_for_each_entry(rg, head, link)
-		if (f <= rg->to)
-			break;
-
-	/* If we are below the current region then a new region is required.
-	 * Subtle, allocate a new region at the position but make it zero
-	 * size such that we can guarantee to record the reservation. */
-	if (&rg->link == head || t < rg->from) {
-		nrg = kmalloc(sizeof(*nrg), GFP_KERNEL);
-		if (!nrg)
-			return -ENOMEM;
-		nrg->from = f;
-		nrg->to   = f;
-		INIT_LIST_HEAD(&nrg->link);
-		list_add(&nrg->link, rg->link.prev);
-
-		return t - f;
-	}
-
-	/* Round our left edge to the current segment if it encloses us. */
-	if (f > rg->from)
-		f = rg->from;
-	chg = t - f;
-
-	/* Check for and consume any regions we now overlap with. */
-	list_for_each_entry(rg, rg->link.prev, link) {
-		if (&rg->link == head)
-			break;
-		if (rg->from > t)
-			return chg;
-
-		/* We overlap with this area, if it extends futher than
-		 * us then we must extend ourselves.  Account for its
-		 * existing reservation. */
-		if (rg->to > t) {
-			chg += rg->to - t;
-			t = rg->to;
-		}
-		chg -= rg->to - rg->from;
-	}
-	return chg;
-}
-
-static long region_truncate(struct list_head *head, long end)
-{
-	struct file_region *rg, *trg;
-	long chg = 0;
-
-	/* Locate the region we are either in or before. */
-	list_for_each_entry(rg, head, link)
-		if (end <= rg->to)
-			break;
-	if (&rg->link == head)
-		return 0;
-
-	/* If we are in the middle of a region then adjust it. */
-	if (end > rg->from) {
-		chg = rg->to - end;
-		rg->to = end;
-		rg = list_entry(rg->link.next, typeof(*rg), link);
-	}
-
-	/* Drop any remaining regions. */
-	list_for_each_entry_safe(rg, trg, rg->link.prev, link) {
-		if (&rg->link == head)
-			break;
-		chg += rg->to - rg->from;
-		list_del(&rg->link);
-		kfree(rg);
-	}
-	return chg;
-}
-
 /*
  * Determine if the huge page at addr within the vma has an associated
  * reservation.  Where it does not we will need to logically increase
-- 
1.5.6.205.g7ca3a

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
2.6.26-rc5-mm3, Andrew Morton, (Wed Jun 11, 10:59 pm)
2.6.26-rc5-mm3: kernel BUG at mm/vmscan.c:510, Alexey Dobriyan, (Thu Jun 12, 12:58 am)
Re: 2.6.26-rc5-mm3: kernel BUG at mm/vmscan.c:510, Andrew Morton, (Thu Jun 12, 1:22 am)
Re: 2.6.26-rc5-mm3: kernel BUG at mm/vmscan.c:510, Alexey Dobriyan, (Thu Jun 12, 1:23 am)
[BUG] 2.6.26-rc5-mm3 kernel BUG at mm/filemap.c:575!, Kamalesh Babulal, (Thu Jun 12, 1:44 am)
Re: [BUG] 2.6.26-rc5-mm3 kernel BUG at mm/filemap.c:575!, Andrew Morton, (Thu Jun 12, 1:57 am)
Re: [BUG] 2.6.26-rc5-mm3 kernel BUG at mm/filemap.c:575!, KAMEZAWA Hiroyuki, (Thu Jun 12, 4:20 am)
Re: 2.6.26-rc5-mm3, Byron Bradley, (Thu Jun 12, 4:32 pm)
Re: 2.6.26-rc5-mm3, Daniel Walker, (Thu Jun 12, 4:55 pm)
Re: 2.6.26-rc5-mm3, Byron Bradley, (Thu Jun 12, 5:04 pm)
Re: [BUG] 2.6.26-rc5-mm3 kernel BUG at mm/filemap.c:575!, KAMEZAWA Hiroyuki, (Thu Jun 12, 5:25 pm)
[PATCH] fix double unlock_page() in 2.6.26-rc5-mm3 kernel ..., KAMEZAWA Hiroyuki, (Thu Jun 12, 6:44 pm)
Re: [BUG] 2.6.26-rc5-mm3 kernel BUG at mm/filemap.c:575!, Valdis.Kletnieks, (Thu Jun 12, 9:18 pm)
Re: [BUG] 2.6.26-rc5-mm3 kernel BUG at mm/filemap.c:575!, Andrew Morton, (Fri Jun 13, 12:16 am)
Re: [PATCH] fix double unlock_page() in 2.6.26-rc5-mm3 ker ..., KAMEZAWA Hiroyuki, (Mon Jun 16, 7:32 pm)
[PATCH][RFC] fix kernel BUG at mm/migrate.c:719! in 2.6.26 ..., Daisuke Nishimura, (Tue Jun 17, 12:35 am)
[Bad page] trying to free locked page? (Re: [PATCH][RFC] f ..., Daisuke Nishimura, (Tue Jun 17, 12:47 am)
Re: [Bad page] trying to free locked page? (Re: [PATCH][RF ..., KAMEZAWA Hiroyuki, (Tue Jun 17, 2:03 am)
Re: [Bad page] trying to free locked page? (Re: [PATCH][RF ..., Daisuke Nishimura, (Tue Jun 17, 2:15 am)
Re: [PATCH][RFC] fix kernel BUG at mm/migrate.c:719! in 2. ..., Lee Schermerhorn, (Tue Jun 17, 10:46 am)
Re: [Bad page] trying to free locked page? (Re: [PATCH][RF ..., Lee Schermerhorn, (Tue Jun 17, 11:29 am)
Re: [PATCH][RFC] fix kernel BUG at mm/migrate.c:719! in 2. ..., Lee Schermerhorn, (Tue Jun 17, 12:28 pm)
[PATCH] unevictable mlocked pages: initialize mm member o ..., Lee Schermerhorn, (Tue Jun 17, 1:00 pm)
Re: [PATCH][RFC] fix kernel BUG at mm/migrate.c:719! in 2. ..., KAMEZAWA Hiroyuki, (Tue Jun 17, 6:13 pm)
Re: [PATCH][RFC] fix kernel BUG at mm/migrate.c:719! in 2. ..., Daisuke Nishimura, (Tue Jun 17, 6:26 pm)
Re: [PATCH][RFC] fix kernel BUG at mm/migrate.c:719! in 2. ..., Daisuke Nishimura, (Tue Jun 17, 6:54 pm)
[PATCH] migration_entry_wait fix., KAMEZAWA Hiroyuki, (Tue Jun 17, 6:54 pm)
Re: [Bad page] trying to free locked page? (Re: [PATCH][RF ..., Daisuke Nishimura, (Tue Jun 17, 7:32 pm)
Re: [Bad page] trying to free locked page? (Re: [PATCH][RF ..., Daisuke Nishimura, (Tue Jun 17, 7:40 pm)
Re: [PATCH][RFC] fix kernel BUG at mm/migrate.c:719! in 2. ..., Daisuke Nishimura, (Tue Jun 17, 7:59 pm)
Re: [PATCH][RFC] fix kernel BUG at mm/migrate.c:719! in 2. ..., Daisuke Nishimura, (Tue Jun 17, 9:41 pm)
Re: [PATCH][RFC] fix kernel BUG at mm/migrate.c:719! in 2. ..., KAMEZAWA Hiroyuki, (Tue Jun 17, 9:59 pm)
Re: [PATCH] migration_entry_wait fix., KOSAKI Motohiro, (Tue Jun 17, 10:26 pm)
Re: [PATCH] migration_entry_wait fix., Nick Piggin, (Tue Jun 17, 10:35 pm)
Re: [PATCH] migration_entry_wait fix., KAMEZAWA Hiroyuki, (Tue Jun 17, 11:04 pm)
Re: [PATCH] migration_entry_wait fix., Nick Piggin, (Tue Jun 17, 11:42 pm)
Re: [PATCH] migration_entry_wait fix., KAMEZAWA Hiroyuki, (Tue Jun 17, 11:52 pm)
Re: [PATCH -mm][BUGFIX] migration_entry_wait fix. v2, KOSAKI Motohiro, (Wed Jun 18, 12:26 am)
[PATCH -mm][BUGFIX] migration_entry_wait fix. v2, KAMEZAWA Hiroyuki, (Wed Jun 18, 12:29 am)
Re: [PATCH -mm][BUGFIX] migration_entry_wait fix. v2, Nick Piggin, (Wed Jun 18, 12:40 am)
[PATCH][-mm] remove redundant page-&gt;mapping check, KOSAKI Motohiro, (Wed Jun 18, 12:54 am)
[Experimental][PATCH] putback_lru_page rework, KAMEZAWA Hiroyuki, (Wed Jun 18, 2:40 am)
Re: [Experimental][PATCH] putback_lru_page rework, KOSAKI Motohiro, (Wed Jun 18, 4:36 am)
Re: [Experimental][PATCH] putback_lru_page rework, KAMEZAWA Hiroyuki, (Wed Jun 18, 4:55 am)
Re: [Experimental][PATCH] putback_lru_page rework, Daisuke Nishimura, (Wed Jun 18, 7:50 am)
Re: 2.6.26-rc5-mm3, Daniel Walker, (Wed Jun 18, 10:55 am)
Re: [Experimental][PATCH] putback_lru_page rework, Lee Schermerhorn, (Wed Jun 18, 11:21 am)
Re: [Experimental][PATCH] putback_lru_page rework, KAMEZAWA Hiroyuki, (Wed Jun 18, 5:22 pm)
[BUG][PATCH -mm] avoid BUG() in __stop_machine_run(), Hidehiro Kawai, (Wed Jun 18, 11:59 pm)
Re: [Experimental][PATCH] putback_lru_page rework, Daisuke Nishimura, (Thu Jun 19, 1:00 am)
Re: [Experimental][PATCH] putback_lru_page rework, KAMEZAWA Hiroyuki, (Thu Jun 19, 1:24 am)
Re: 2.6.26-rc5-mm3, Ingo Molnar, (Thu Jun 19, 2:13 am)
Re: [BUG][PATCH -mm] avoid BUG() in __stop_machine_run(), Rusty Russell, (Thu Jun 19, 3:12 am)
Re: 2.6.26-rc5-mm3, Daniel Walker, (Thu Jun 19, 7:39 am)
Re: [Experimental][PATCH] putback_lru_page rework, Lee Schermerhorn, (Thu Jun 19, 7:45 am)
Re: Re: [Experimental][PATCH] putback_lru_page rework, kamezawa.hiroyu, (Thu Jun 19, 8:32 am)
Re: [BUG][PATCH -mm] avoid BUG() in __stop_machine_run(), Jeremy Fitzhardinge, (Thu Jun 19, 8:51 am)
Re: 2.6.26-rc5-mm3: BUG large value for HugePages_Rsvd, Jon Tollefson, (Thu Jun 19, 9:27 am)
Re: 2.6.26-rc5-mm3: BUG large value for HugePages_Rsvd, Andy Whitcroft, (Thu Jun 19, 10:16 am)
Re: [Experimental][PATCH] putback_lru_page rework, KAMEZAWA Hiroyuki, (Thu Jun 19, 5:47 pm)
Re: [Experimental][PATCH] putback_lru_page rework, KAMEZAWA Hiroyuki, (Thu Jun 19, 6:13 pm)
Re: 2.6.26-rc5-mm3: BUG large value for HugePages_Rsvd, Jon Tollefson, (Thu Jun 19, 8:18 pm)
Re: Re: [Experimental][PATCH] putback_lru_page rework, Lee Schermerhorn, (Fri Jun 20, 9:24 am)
Re: [Experimental][PATCH] putback_lru_page rework, Lee Schermerhorn, (Fri Jun 20, 10:10 am)
[PATCH 1/2] hugetlb reservations: move region tracking earlier, Andy Whitcroft, (Fri Jun 20, 12:17 pm)
Re: [Experimental][PATCH] putback_lru_page rework, Lee Schermerhorn, (Fri Jun 20, 1:41 pm)
Re: [Experimental][PATCH] putback_lru_page rework, KOSAKI Motohiro, (Sat Jun 21, 1:39 am)
Re: [Experimental][PATCH] putback_lru_page rework, KOSAKI Motohiro, (Sat Jun 21, 1:41 am)
Re: [Experimental][PATCH] putback_lru_page rework, KOSAKI Motohiro, (Sat Jun 21, 1:56 am)
Re: [Experimental][PATCH] putback_lru_page rework, KAMEZAWA Hiroyuki, (Sun Jun 22, 5:30 pm)
Re: [BUG][PATCH -mm] avoid BUG() in __stop_machine_run(), Rusty Russell, (Sun Jun 22, 8:55 pm)