Move PMAP_TS_REFERENCED_MAX out of the various pmap implementations and into vm/pmap.h, and describe what its purpose is. Eliminate the archaic "XXX" comment about its value. I don't believe that its exact value, e.g., 5 versus 6, matters.
Update the arm64 and riscv pmap implementations of pmap_ts_referenced() to opportunistically update the page's dirty field.
On amd64, use the PDE value already cached in a local variable rather than dereferencing a pointer again and again.
I'm primarily looking for feedback on the first point, especially the new comment describing PMAP_TS_REFERENCED_MAX.