* 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. */
| 1803 | * NULL if M_NOWAIT is set. |
| 1804 | */ |
| 1805 | static void * |
| 1806 | noobj_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. |
nothing calls this directly
no test coverage detected