memblock_free(start, end - start);
 }
-
-/*
- * Finds an active region in the address range from start_pfn to last_pfn and
- * returns its range in ei_startpfn and ei_endpfn for the memblock entry.
- */
-static int __init memblock_x86_find_active_region(const struct memblock_region *ei,
-                                 unsigned long start_pfn,
-                                 unsigned long last_pfn,
-                                 unsigned long *ei_startpfn,
-                                 unsigned long *ei_endpfn)
-{
-       u64 align = PAGE_SIZE;
-
-       *ei_startpfn = round_up(ei->base, align) >> PAGE_SHIFT;
-       *ei_endpfn = round_down(ei->base + ei->size, align) >> PAGE_SHIFT;
-
-       /* Skip map entries smaller than a page */
-       if (*ei_startpfn >= *ei_endpfn)
-               return 0;
-
-       /* Skip if map is outside the node */
-       if (*ei_endpfn <= start_pfn || *ei_startpfn >= last_pfn)
-               return 0;
-
-       /* Check for overlaps */
-       if (*ei_startpfn < start_pfn)
-               *ei_startpfn = start_pfn;
-       if (*ei_endpfn > last_pfn)
-               *ei_endpfn = last_pfn;
-
-       return 1;
-}
-
-/*
- * Find the hole size (in bytes) in the memory range.
- * @start: starting address of the memory range to scan
- * @end: ending address of the memory range to scan
- */
-u64 __init memblock_x86_hole_size(u64 start, u64 end)
-{
-       unsigned long start_pfn = start >> PAGE_SHIFT;
-       unsigned long last_pfn = end >> PAGE_SHIFT;
-       unsigned long ei_startpfn, ei_endpfn, ram = 0;
-       struct memblock_region *r;
-
-       for_each_memblock(memory, r)
-               if (memblock_x86_find_active_region(r, start_pfn, last_pfn,
-                                          &ei_startpfn, &ei_endpfn))
-                       ram += ei_endpfn - ei_startpfn;
-
-       return end - start - ((u64)ram << PAGE_SHIFT);
-}
 
        return -ENOENT;
 }
 
+static u64 mem_hole_size(u64 start, u64 end)
+{
+       unsigned long start_pfn = PFN_UP(start);
+       unsigned long end_pfn = PFN_DOWN(end);
+
+       if (start_pfn < end_pfn)
+               return PFN_PHYS(absent_pages_in_range(start_pfn, end_pfn));
+       return 0;
+}
+
 /*
  * Sets up nid to range from @start to @end.  The return value is -errno if
  * something went wrong, 0 otherwise.
         * Calculate target node size.  x86_32 freaks on __udivdi3() so do
         * the division in ulong number of pages and convert back.
         */
-       size = max_addr - addr - memblock_x86_hole_size(addr, max_addr);
+       size = max_addr - addr - mem_hole_size(addr, max_addr);
        size = PFN_PHYS((unsigned long)(size >> PAGE_SHIFT) / nr_nodes);
 
        /*
                         * Continue to add memory to this fake node if its
                         * non-reserved memory is less than the per-node size.
                         */
-                       while (end - start -
-                              memblock_x86_hole_size(start, end) < size) {
+                       while (end - start - mem_hole_size(start, end) < size) {
                                end += FAKE_NODE_MIN_SIZE;
                                if (end > limit) {
                                        end = limit;
                         * this one must extend to the boundary.
                         */
                        if (end < dma32_end && dma32_end - end -
-                           memblock_x86_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
+                           mem_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
                                end = dma32_end;
 
                        /*
                         * next node, this one must extend to the end of the
                         * physical node.
                         */
-                       if (limit - end -
-                           memblock_x86_hole_size(end, limit) < size)
+                       if (limit - end - mem_hole_size(end, limit) < size)
                                end = limit;
 
                        ret = emu_setup_memblk(ei, pi, nid++ % nr_nodes,
 {
        u64 end = start + size;
 
-       while (end - start - memblock_x86_hole_size(start, end) < size) {
+       while (end - start - mem_hole_size(start, end) < size) {
                end += FAKE_NODE_MIN_SIZE;
                if (end > max_addr) {
                        end = max_addr;
         * creates a uniform distribution of node sizes across the entire
         * machine (but not necessarily over physical nodes).
         */
-       min_size = (max_addr - addr - memblock_x86_hole_size(addr, max_addr)) /
-                                               MAX_NUMNODES;
+       min_size = (max_addr - addr - mem_hole_size(addr, max_addr)) / MAX_NUMNODES;
        min_size = max(min_size, FAKE_NODE_MIN_SIZE);
        if ((min_size & FAKE_NODE_MIN_HASH_MASK) < min_size)
                min_size = (min_size + FAKE_NODE_MIN_SIZE) &
                         * this one must extend to the boundary.
                         */
                        if (end < dma32_end && dma32_end - end -
-                           memblock_x86_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
+                           mem_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
                                end = dma32_end;
 
                        /*
                         * next node, this one must extend to the end of the
                         * physical node.
                         */
-                       if (limit - end -
-                           memblock_x86_hole_size(end, limit) < size)
+                       if (limit - end - mem_hole_size(end, limit) < size)
                                end = limit;
 
                        ret = emu_setup_memblk(ei, pi, nid++ % MAX_NUMNODES,