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

Function noobj_alloc

freebsd/vm/uma_core.c:1805–1853  ·  view source on GitHub ↗

* Allocates a number of pages from within an object * * Arguments: * bytes The number of bytes requested * wait Shall we wait? * * Returns: * A pointer to the alloced memory or possibly * NULL if M_NOWAIT is set. */

Source from the content-addressed store, hash-verified

1803 * NULL if M_NOWAIT is set.
1804 */
1805static void *
1806noobj_alloc(uma_zone_t zone, vm_size_t bytes, int domain, uint8_t *flags,
1807 int wait)
1808{
1809 TAILQ_HEAD(, vm_page) alloctail;
1810 u_long npages;
1811 vm_offset_t retkva, zkva;
1812 vm_page_t p, p_next;
1813 uma_keg_t keg;
1814
1815 TAILQ_INIT(&alloctail);
1816 keg = zone->uz_keg;
1817
1818 npages = howmany(bytes, PAGE_SIZE);
1819 while (npages > 0) {
1820 p = vm_page_alloc_domain(NULL, 0, domain, VM_ALLOC_INTERRUPT |
1821 VM_ALLOC_WIRED | VM_ALLOC_NOOBJ |
1822 ((wait & M_WAITOK) != 0 ? VM_ALLOC_WAITOK :
1823 VM_ALLOC_NOWAIT));
1824 if (p != NULL) {
1825 /*
1826 * Since the page does not belong to an object, its
1827 * listq is unused.
1828 */
1829 TAILQ_INSERT_TAIL(&alloctail, p, listq);
1830 npages--;
1831 continue;
1832 }
1833 /*
1834 * Page allocation failed, free intermediate pages and
1835 * exit.
1836 */
1837 TAILQ_FOREACH_SAFE(p, &alloctail, listq, p_next) {
1838 vm_page_unwire_noq(p);
1839 vm_page_free(p);
1840 }
1841 return (NULL);
1842 }
1843 *flags = UMA_SLAB_PRIV;
1844 zkva = keg->uk_kva +
1845 atomic_fetchadd_long(&keg->uk_offset, round_page(bytes));
1846 retkva = zkva;
1847 TAILQ_FOREACH(p, &alloctail, listq) {
1848 pmap_qenter(zkva, &p, 1);
1849 zkva += PAGE_SIZE;
1850 }
1851
1852 return ((void *)retkva);
1853}
1854
1855/*
1856 * Allocate physically contiguous pages.

Callers

nothing calls this directly

Calls 5

vm_page_alloc_domainFunction · 0.85
vm_page_unwire_noqFunction · 0.85
vm_page_freeFunction · 0.85
atomic_fetchadd_longFunction · 0.50
pmap_qenterFunction · 0.50

Tested by

no test coverage detected