www.usr.com/support/gpl/USR9113_release1.0.tar.gz
[bcm963xx.git] / kernel / linux / mm / page_alloc.c
index 6708f4f..7ccf618 100755 (executable)
@@ -608,6 +608,11 @@ __alloc_pages(unsigned int gfp_mask, unsigned int order,
        int alloc_type;
        int do_retry;
 
+#if defined(CONFIG_MIPS_BRCM)
+    int nretry;
+    int tpages = 0;
+#endif
+
        might_sleep_if(wait);
 
        zones = zonelist->zones;  /* the list of zones suitable for gfp_mask */
@@ -662,10 +667,18 @@ __alloc_pages(unsigned int gfp_mask, unsigned int order,
                                goto got_pg;
                        }
                }
+#if defined(CONFIG_MIPS_BRCM)
+        tpages += z->nr_active + z->nr_inactive;
+#endif
        }
 
        /* here we're in the low on memory slow path */
 
+#if defined(CONFIG_MIPS_BRCM)
+    nretry = tpages/SWAP_CLUSTER_MAX;
+    //printk("============to rebalance, tpages %d    nretry %d    ", tpages, nretry);
+#endif
+
 rebalance:
        if ((p->flags & (PF_MEMALLOC | PF_MEMDIE)) && !in_interrupt()) {
                /* go through the zonelist yet again, ignoring mins */
@@ -709,7 +722,24 @@ rebalance:
                        }
                }
        }
-
+#if defined(CONFIG_MIPS_BRCM)
+       /*
+        * For embedded system, we have small memory and we assume well-behaved software
+        * Let it scan all pages if necessary
+        * This is similar to including __GFP_NOFAIL/__GFP_REPEAT by default, except we use nretry as a safety mechanism
+        */
+       do_retry = 0;
+       if (!(gfp_mask & __GFP_NORETRY)) {
+               if ((gfp_mask & __GFP_NOFAIL) || (gfp_mask & __GFP_REPEAT)) {
+                       do_retry = 1;
+        }
+               else if (nretry > 0) {
+                       do_retry = 1;
+            nretry--;
+        }
+       }
+    //printk(".");
+#else
        /*
         * Don't let big-order allocations loop unless the caller explicitly
         * requests that.  Wait for some write requests to complete then retry.
@@ -724,6 +754,8 @@ rebalance:
                if (gfp_mask & __GFP_NOFAIL)
                        do_retry = 1;
        }
+#endif 
+
        if (do_retry) {
                blk_congestion_wait(WRITE, HZ/50);
                goto rebalance;
@@ -1880,6 +1912,7 @@ static void setup_per_zone_pages_min(void)
 
        for_each_zone(zone) {
                spin_lock_irqsave(&zone->lru_lock, flags);
+#if !defined(CONFIG_MIPS_BRCM)
                if (is_highmem(zone)) {
                        /*
                         * Often, highmem doesn't need to reserve any pages.
@@ -1902,9 +1935,17 @@ static void setup_per_zone_pages_min(void)
                        zone->pages_min = (pages_min * zone->present_pages) / 
                                           lowmem_pages;
                }
-
                zone->pages_low = zone->pages_min * 2;
                zone->pages_high = zone->pages_min * 3;
+#else
+               /* Tuned watermarks for better out of memory performance on our swapless system */
+               /* As we don't have a disc to swap out dirty pages, there is not much we can do if memory is really low */ 
+               /* We want to lower watermarks to prevent excessive scanning, which could slow down or lock up the system */
+               zone->pages_min = 0;   /* this is actually not used elsewhere except for calculating the other two */
+               zone->pages_low = 48;  
+               zone->pages_high = 50;
+#endif
+
                spin_unlock_irqrestore(&zone->lru_lock, flags);
        }
 }