MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vm_phys_early_alloc

Function vm_phys_early_alloc

freebsd/vm/vm_phys.c:1615–1696  ·  view source on GitHub ↗

* This routine allocates NUMA node specific memory before the page * allocator is bootstrapped. */

Source from the content-addressed store, hash-verified

1613 * allocator is bootstrapped.
1614 */
1615vm_paddr_t
1616vm_phys_early_alloc(int domain, size_t alloc_size)
1617{
1618 int i, mem_index, biggestone;
1619 vm_paddr_t pa, mem_start, mem_end, size, biggestsize, align;
1620
1621 KASSERT(domain == -1 || (domain >= 0 && domain < vm_ndomains),
1622 ("%s: invalid domain index %d", __func__, domain));
1623
1624 /*
1625 * Search the mem_affinity array for the biggest address
1626 * range in the desired domain. This is used to constrain
1627 * the phys_avail selection below.
1628 */
1629 biggestsize = 0;
1630 mem_index = 0;
1631 mem_start = 0;
1632 mem_end = -1;
1633#ifdef NUMA
1634 if (mem_affinity != NULL) {
1635 for (i = 0;; i++) {
1636 size = mem_affinity[i].end - mem_affinity[i].start;
1637 if (size == 0)
1638 break;
1639 if (domain != -1 && mem_affinity[i].domain != domain)
1640 continue;
1641 if (size > biggestsize) {
1642 mem_index = i;
1643 biggestsize = size;
1644 }
1645 }
1646 mem_start = mem_affinity[mem_index].start;
1647 mem_end = mem_affinity[mem_index].end;
1648 }
1649#endif
1650
1651 /*
1652 * Now find biggest physical segment in within the desired
1653 * numa domain.
1654 */
1655 biggestsize = 0;
1656 biggestone = 0;
1657 for (i = 0; phys_avail[i + 1] != 0; i += 2) {
1658 /* skip regions that are out of range */
1659 if (phys_avail[i+1] - alloc_size < mem_start ||
1660 phys_avail[i+1] > mem_end)
1661 continue;
1662 size = vm_phys_avail_size(i);
1663 if (size > biggestsize) {
1664 biggestone = i;
1665 biggestsize = size;
1666 }
1667 }
1668 alloc_size = round_page(alloc_size);
1669
1670 /*
1671 * Grab single pages from the front to reduce fragmentation.
1672 */

Callers 1

pmap_page_array_startupFunction · 0.85

Calls 4

vm_phys_avail_sizeFunction · 0.85
vm_phys_avail_checkFunction · 0.85
vm_phys_avail_splitFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected