*/
 #define SHOW_MEM_FILTER_NODES          (0x0001u)       /* disallowed nodes */
 
-extern void show_free_areas(unsigned int flags, nodemask_t *nodemask);
+extern void __show_free_areas(unsigned int flags, nodemask_t *nodemask, int max_zone_idx);
+static void __maybe_unused show_free_areas(unsigned int flags, nodemask_t *nodemask)
+{
+       __show_free_areas(flags, nodemask, MAX_NR_ZONES - 1);
+}
 
 #ifdef CONFIG_MMU
 extern bool can_do_mlock(void);
 extern int __meminit init_per_zone_wmark_min(void);
 extern void mem_init(void);
 extern void __init mmap_init(void);
-extern void show_mem(unsigned int flags, nodemask_t *nodemask);
+
+extern void __show_mem(unsigned int flags, nodemask_t *nodemask, int max_zone_idx);
+static inline void show_mem(unsigned int flags, nodemask_t *nodemask)
+{
+       __show_mem(flags, nodemask, MAX_NR_ZONES - 1);
+}
 extern long si_mem_available(void);
 extern void si_meminfo(struct sysinfo * val);
 extern void si_meminfo_node(struct sysinfo *val, int nid);
 
 #include <linux/mm.h>
 #include <linux/cma.h>
 
-void show_mem(unsigned int filter, nodemask_t *nodemask)
+void __show_mem(unsigned int filter, nodemask_t *nodemask, int max_zone_idx)
 {
        pg_data_t *pgdat;
        unsigned long total = 0, reserved = 0, highmem = 0;
 
        printk("Mem-Info:\n");
-       show_free_areas(filter, nodemask);
+       __show_free_areas(filter, nodemask, max_zone_idx);
 
        for_each_online_pgdat(pgdat) {
                int zoneid;
 
        if (!in_task() || !(gfp_mask & __GFP_DIRECT_RECLAIM))
                filter &= ~SHOW_MEM_FILTER_NODES;
 
-       show_mem(filter, nodemask);
+       __show_mem(filter, nodemask, gfp_zone(gfp_mask));
 }
 
 void warn_alloc(gfp_t gfp_mask, nodemask_t *nodemask, const char *fmt, ...)
        printk(KERN_CONT "(%s) ", tmp);
 }
 
+static bool node_has_managed_zones(pg_data_t *pgdat, int max_zone_idx)
+{
+       int zone_idx;
+       for (zone_idx = 0; zone_idx <= max_zone_idx; zone_idx++)
+               if (zone_managed_pages(pgdat->node_zones + zone_idx))
+                       return true;
+       return false;
+}
+
 /*
  * Show free area list (used inside shift_scroll-lock stuff)
  * We also calculate the percentage fragmentation. We do this by counting the
  * SHOW_MEM_FILTER_NODES: suppress nodes that are not allowed by current's
  *   cpuset.
  */
-void show_free_areas(unsigned int filter, nodemask_t *nodemask)
+void __show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_zone_idx)
 {
        unsigned long free_pcp = 0;
        int cpu, nid;
        pg_data_t *pgdat;
 
        for_each_populated_zone(zone) {
+               if (zone_idx(zone) > max_zone_idx)
+                       continue;
                if (show_mem_node_skip(filter, zone_to_nid(zone), nodemask))
                        continue;
 
        for_each_online_pgdat(pgdat) {
                if (show_mem_node_skip(filter, pgdat->node_id, nodemask))
                        continue;
+               if (!node_has_managed_zones(pgdat, max_zone_idx))
+                       continue;
 
                printk("Node %d"
                        " active_anon:%lukB"
        for_each_populated_zone(zone) {
                int i;
 
+               if (zone_idx(zone) > max_zone_idx)
+                       continue;
                if (show_mem_node_skip(filter, zone_to_nid(zone), nodemask))
                        continue;
 
                unsigned long nr[MAX_ORDER], flags, total = 0;
                unsigned char types[MAX_ORDER];
 
+               if (zone_idx(zone) > max_zone_idx)
+                       continue;
                if (show_mem_node_skip(filter, zone_to_nid(zone), nodemask))
                        continue;
                show_node(zone);