Index: kernel/generic/include/mm/frame.h
===================================================================
--- kernel/generic/include/mm/frame.h	(revision 2ec725f323a83fee85ad7c1f75b8164d24daca8a)
+++ kernel/generic/include/mm/frame.h	(revision 5f7a0efdf9317065441dea283bfb70a495d7634c)
@@ -58,13 +58,12 @@
 #define ZONES_MAX       	16
 
-/** If possible, merge with neighbouring zones. */
-#define ZONE_JOIN       	0x1
-
 /** Convert the frame address to kernel va. */
 #define FRAME_KA		0x1
 /** Do not panic and do not sleep on failure. */
-#define FRAME_ATOMIC 	        0x2
+#define FRAME_ATOMIC		0x2
 /** Do not start reclaiming when no free memory. */
-#define FRAME_NO_RECLAIM        0x4
+#define FRAME_NO_RECLAIM	0x4
+/** Do not allocate above 16GiB. */
+#define FRAME_LOW_16_GiB	0x8
 
 static inline uintptr_t PFN2ADDR(pfn_t frame)
@@ -91,28 +90,28 @@
 
 #define IS_BUDDY_ORDER_OK(index, order)		\
-	((~(((unative_t) -1) << (order)) & (index)) == 0)
+    ((~(((unative_t) -1) << (order)) & (index)) == 0)
 #define IS_BUDDY_LEFT_BLOCK(zone, frame)	\
-	(((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
+    (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
 #define IS_BUDDY_RIGHT_BLOCK(zone, frame)	\
-	(((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
+    (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
 #define IS_BUDDY_LEFT_BLOCK_ABS(zone, frame)	\
-	(((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
+    (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
 #define IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame)	\
-	(((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
+    (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
 
 #define frame_alloc(order, flags)		\
-	frame_alloc_generic(order, flags, NULL)
+    frame_alloc_generic(order, flags, NULL)
 
 extern void frame_init(void);
-extern void *frame_alloc_generic(uint8_t order, int flags, unsigned int *pzone);
-extern void frame_free(uintptr_t frame);
-extern void frame_reference_add(pfn_t pfn);
+extern void *frame_alloc_generic(uint8_t, int, unsigned int *);
+extern void frame_free(uintptr_t);
+extern void frame_reference_add(pfn_t);
 
-extern int zone_create(pfn_t start, count_t count, pfn_t confframe, int flags);
-extern void *frame_get_parent(pfn_t frame, unsigned int hint);
-extern void frame_set_parent(pfn_t frame, void *data, unsigned int hint);
-extern void frame_mark_unavailable(pfn_t start, count_t count);
-extern uintptr_t zone_conf_size(count_t count);
-extern void zone_merge(unsigned int z1, unsigned int z2);
+extern int zone_create(pfn_t, count_t, pfn_t, int);
+extern void *frame_get_parent(pfn_t, unsigned int);
+extern void frame_set_parent(pfn_t, void *, unsigned int);
+extern void frame_mark_unavailable(pfn_t, count_t);
+extern uintptr_t zone_conf_size(count_t);
+extern void zone_merge(unsigned int, unsigned int);
 extern void zone_merge_all(void);
 extern uint64_t zone_total_size(void);
@@ -122,5 +121,5 @@
  */
 extern void zone_print_list(void);
-extern void zone_print_one(unsigned int znum);
+extern void zone_print_one(unsigned int);
 
 #endif
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);
 		}
 	}
