Why can't the data be read directly into shared memory?
It is not the same lock. Each PgStatShared_IOPathOps has a lock so that they can be accessed individually (per BackendType in PgStatShared_BackendIOPathOps). It is optimized for the more common operation of flushing at the expense of the snapshot operation (which should be less common) and reset operation.
Why acquire the same lock repeatedly for each type, rather than once for the whole?
This is also because of having a LWLock in each PgStatShared_IOPathOps. Because I don't want a lock in the backend local stats, I have two data structures PgStatShared_IOPathOps and PgStat_IOPathOps. I thought it was odd to write out the lock to the file, so when persisting the stats, I write out the relevant data only and when reading it back in to shared memory, I read in the data member of PgStatShared_IOPathOps.