Index: kernel/generic/src/mm/frame.c
===================================================================
--- kernel/generic/src/mm/frame.c	(revision 2ec725f323a83fee85ad7c1f75b8164d24daca8a)
+++ kernel/generic/src/mm/frame.c	(revision 5f7a0efdf9317065441dea283bfb70a495d7634c)
@@ -201,6 +201,5 @@
 }
 
-/**
- * Try to find a zone where can we find the frame.
+/** Try to find a zone where can we find the frame.
  *
  * Assume interrupts are disabled.
@@ -238,5 +237,5 @@
 		if (i >= zones.count)
 			i = 0;
-	} while(i != hint);
+	} while (i != hint);
 
 	spinlock_unlock(&zones.lock);
@@ -255,8 +254,10 @@
  *
  * @param order		Size (2^order) of free space we are trying to find.
+ * @param flags		Required flags of the target zone.
  * @param pzone		Pointer to preferred zone or NULL, on return contains
  * 			zone number.
  */
-static zone_t *find_free_zone_and_lock(uint8_t order, unsigned int *pzone)
+static zone_t *
+find_free_zone_and_lock(uint8_t order, int flags, unsigned int *pzone)
 {
 	unsigned int i;
@@ -264,4 +265,7 @@
 	unsigned int hint = pzone ? *pzone : 0;
 	
+	/* Mask off flags that are not applicable. */
+	flags &= FRAME_LOW_16_GiB;
+
 	spinlock_lock(&zones.lock);
 	if (hint >= zones.count)
@@ -273,15 +277,22 @@
 		spinlock_lock(&z->lock);
 
-		/* Check if the zone has 2^order frames area available  */
-		if (zone_can_alloc(z, order)) {
-			spinlock_unlock(&zones.lock);
-			if (pzone)
-				*pzone = i;
-			return z;
+		/*
+		 * Check whether the zone meets the search criteria.
+		 */
+		if ((z->flags & flags) == flags) {
+			/*
+			 * Check if the zone has 2^order frames area available.
+			 */
+			if (zone_can_alloc(z, order)) {
+				spinlock_unlock(&zones.lock);
+				if (pzone)
+					*pzone = i;
+				return z;
+			}
 		}
 		spinlock_unlock(&z->lock);
 		if (++i >= zones.count)
 			i = 0;
-	} while(i != hint);
+	} while (i != hint);
 	spinlock_unlock(&zones.lock);
 	return NULL;
@@ -811,5 +822,13 @@
 	z->base = start;
 	z->count = count;
+
+	/* Mask off flags that are calculated automatically. */
+	flags &= ~FRAME_LOW_16_GiB;
+	/* Determine calculated flags. */
+	if (z->base + count < (1ULL << (34 - FRAME_WIDTH)))	/* 16 GiB */
+		flags |= FRAME_LOW_16_GiB;
+
 	z->flags = flags;
+
 	z->free_count = count;
 	z->busy_count = 0;
@@ -983,5 +1002,5 @@
 	 * First, find suitable frame zone.
 	 */
-	zone = find_free_zone_and_lock(order, pzone);
+	zone = find_free_zone_and_lock(order, flags, pzone);
 	
 	/* If no memory, reclaim some slab memory,
@@ -990,9 +1009,10 @@
 		freed = slab_reclaim(0);
 		if (freed)
-			zone = find_free_zone_and_lock(order, pzone);
+			zone = find_free_zone_and_lock(order, flags, pzone);
 		if (!zone) {
 			freed = slab_reclaim(SLAB_RECLAIM_ALL);
 			if (freed)
-				zone = find_free_zone_and_lock(order, pzone);
+				zone = find_free_zone_and_lock(order, flags,
+				    pzone);
 		}
 	}
