Index: share/man/man9/vm_page_alloc.9 =================================================================== --- share/man/man9/vm_page_alloc.9 +++ share/man/man9/vm_page_alloc.9 @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 16, 2016 +.Dd February 19, 2021 .Dt VM_PAGE_ALLOC 9 .Os .Sh NAME @@ -103,11 +103,7 @@ .It Dv VM_ALLOC_WIRED The returned page will be wired. .It Dv VM_ALLOC_ZERO -Indicate a preference for a pre-zeroed page. -There is no guarantee that the returned page will be zeroed, but it -will have the -.Dv PG_ZERO -flag set if it is zeroed. +Zero-fill the contents of the page. .El .El .Sh RETURN VALUES Index: sys/vm/vm_page.c =================================================================== --- sys/vm/vm_page.c +++ sys/vm/vm_page.c @@ -1949,6 +1949,19 @@ return (0); } +static void +vm_page_alloc_zero(vm_page_t m, int req) +{ + if ((req & VM_ALLOC_ZERO) != 0) { + if ((m->flags & PG_ZERO) != 0) { + VM_CNT_INC(v_ozfod); + } else { + pmap_zero_page(m); + VM_CNT_INC(v_zfod); + } + } +} + /* * vm_page_alloc: * @@ -1969,9 +1982,10 @@ * VM_ALLOC_NODUMP do not include the page in a kernel core dump * VM_ALLOC_NOOBJ page is not associated with an object and * should not be exclusive busy + * * VM_ALLOC_SBUSY shared busy the allocated page * VM_ALLOC_WIRED wire the allocated page - * VM_ALLOC_ZERO prefer a zeroed page + * VM_ALLOC_ZERO return a zeroed page */ vm_page_t vm_page_alloc(vm_object_t object, vm_pindex_t pindex, int req) @@ -2144,10 +2158,9 @@ vm_page_alloc_check(m); /* - * Initialize the page. Only the PG_ZERO flag is inherited. + * Initialize the page. Zero its contents if so requested. */ - if ((req & VM_ALLOC_ZERO) != 0) - flags |= (m->flags & PG_ZERO); + vm_page_alloc_zero(m, req); if ((req & VM_ALLOC_NODUMP) != 0) flags |= PG_NODUMP; m->flags = flags; @@ -2175,7 +2188,8 @@ KASSERT(m->object == NULL, ("page %p has object", m)); m->oflags = VPO_UNMANAGED; m->busy_lock = VPB_UNBUSIED; - /* Don't change PG_ZERO. */ + if ((req & VM_ALLOC_ZERO) != 0) + m->flags |= PG_ZERO; vm_page_free_toq(m); if (req & VM_ALLOC_WAITFAIL) { VM_OBJECT_WUNLOCK(object); @@ -2232,7 +2246,7 @@ * should not be exclusive busy * VM_ALLOC_SBUSY shared busy the allocated page * VM_ALLOC_WIRED wire the allocated page - * VM_ALLOC_ZERO prefer a zeroed page + * VM_ALLOC_ZERO return a zeroed page */ vm_page_t vm_page_alloc_contig(vm_object_t object, vm_pindex_t pindex, int req, @@ -2334,11 +2348,9 @@ } /* - * Initialize the pages. Only the PG_ZERO flag is inherited. + * Initialize the pages. Zero their contents if so requested. */ flags = 0; - if ((req & VM_ALLOC_ZERO) != 0) - flags = PG_ZERO; if ((req & VM_ALLOC_NODUMP) != 0) flags |= PG_NODUMP; oflags = object == NULL || (object->flags & OBJ_UNMANAGED) != 0 ? @@ -2357,8 +2369,9 @@ memattr = object->memattr; } for (m = m_ret; m < &m_ret[npages]; m++) { + vm_page_alloc_zero(m, req); + m->flags = flags; m->a.flags = 0; - m->flags = (m->flags | PG_NODUMP) & flags; m->busy_lock = busy_lock; if ((req & VM_ALLOC_WIRED) != 0) m->ref_count = 1; @@ -2377,7 +2390,8 @@ m->ref_count = 0; m->oflags = VPO_UNMANAGED; m->busy_lock = VPB_UNBUSIED; - /* Don't change PG_ZERO. */ + if ((req & VM_ALLOC_ZERO) != 0) + m->flags |= PG_ZERO; vm_page_free_toq(m); } if (req & VM_ALLOC_WAITFAIL) { @@ -2434,7 +2448,7 @@ * VM_ALLOC_COUNT(number) the number of additional pages that the caller * intends to allocate * VM_ALLOC_WIRED wire the allocated page - * VM_ALLOC_ZERO prefer a zeroed page + * VM_ALLOC_ZERO return a zeroed page */ vm_page_t vm_page_alloc_freelist(int freelist, int req) @@ -2458,7 +2472,6 @@ { struct vm_domain *vmd; vm_page_t m; - u_int flags; m = NULL; vmd = VM_DOMAIN(domain); @@ -2480,13 +2493,11 @@ vm_page_alloc_check(m); /* - * Initialize the page. Only the PG_ZERO flag is inherited. + * Initialize the pages. Zero their contents if so requested. */ + vm_page_alloc_zero(m, req); + m->flags = 0; m->a.flags = 0; - flags = 0; - if ((req & VM_ALLOC_ZERO) != 0) - flags = PG_ZERO; - m->flags &= flags; if ((req & VM_ALLOC_WIRED) != 0) { vm_wire_add(1); m->ref_count = 1;