Change the usage of the pool field in vm_page structs.
Currently, every page belongs to a pool, and the pool field identifies
that pooll, whether the page is allocated or free.
With this change:
1. Free memory blocks are only have valid pool fields when they are
the first page in a block in a buddy queue. Otherwise, the value of
pool is VM_NFREEPOOL.
2. Memory allocated in power-of-two sized blocks, by
vm_phys_alloc_freelist_pages or vm_phys_alloc_pages, have only the
first page of the block with a valid pool field; the others have
VM_NFREEPOOL as their pool field. The function vm_phys_free_pages
frees such blocks and restores the first page field to VM_NFREEPOOL.
3. Memory allocated as a number of pages by vm_phys_alloc_npages has
no page marked with the pool value. The memory is freed by
vm_phys_free_npages, and that caller provides the pool value as a parameter.
Where the pool value is needed, in vm_page_free_toq, it has been supplied by
the function that called uma_zalloc to allocate it from the pgcache.
4. Memory allocated as a number of pages, by vm_phys_alloc_contig, has
only the first page marked with the pool value. Such memory can be freed all at once
with vm_phys_free_contig, or one page at a time with vm_phys_free_pages(m, 0).
4. A range of pages with all pool fields set to VM_NFREEPOOL can be
freed with vm_phys_enqueue_contig, which passes the pool value as a
parameter. The function vm_page_startup uses it to initialize the
buddy queues, and vm_reserv_break uses it to return to the buddy
queues unused pages from a broken reservation.
5. vm_phys_free_pages no longer immediately frees pages. Each domain maintains a range of pages waiting to be freed; when vm_phys_free_pages finds that the memory it is to free can extend that range, it does so. When it cannotchange, free_contigthe pool field of the first page of a frees block is used by the buddy all that memory at onceocator to identify its pool, and a new deferred free range is created. The deferred free range is flushed before anybut the buddy allocator makes no guarantees about the pool field value for allocation from its domained pages. This all allows a pool to be guessed; if the pages allocated with alloc_contig are freed from first page to last, then the pool from the first page will be used to free all of them to that poole buddy allocator requires that a pool parameter be passed as part of freeing memory. If pages from that allocation are freed in a random order, thoughA function that allocates memory may use the pool field of a page to record what pool to pass as that parameter when the memory is freed, some will end up in the default pool regardless of the pool from which they originally camebut might not need to do so for every allocated page.