Note: this is also a backport of https://github.com/ceph/ceph/pull/30853, which was a performance improvement but also made visible the underlying bug addressed.
This update was made using the script "backport-resolve-issue". backport PR https://github.com/ceph/ceph/pull/33675 merge commit cca668e688cde6dfca14f90cb51f0c0afa0b6f97 (v14.2.9-481-gcca668e688c)