When we can't allocate from the preferred allocation type we need fallback to other allocation types. This patch determines which allocation types we try to fallback to in which order. It also adds a special fallback type that is designed to minimize the fragmentation caused by fallback between the other types. There is an implicit tradeoff being made here between avoiding fragmentation and satisfying allocations. This patch aims to keep existing behavior of satisfying allocations if there is any free memory of any type to satisfy them. It does a reasonable job of trying to minimize the fragmentation, and certainly does better than a stock kernel in all situations. However, it would not be hard to imagine scenarios where a different fallback algorithm that fails more allocations was able to keep fragmentation down much better, and on some systems this decreased fragmentation might even be worth the cost of failing allocations. Systems doing memory hotplug remove for example. This patch is designed so that the static function fallback_alloc() can be easily replaced with an alternate implementation (under a config option perhaps) in the future. Signed-off-by: Mel Gorman Signed-off-by: Joel Schopp