Clean up work_mem handling
Clean up work_mem handling

Add some comments and improve exception handling when twiddling work_mem for
the search update

matrix-org/synapse,matrix-org/synapse,matrix-org/synapse,matrix-org/synapse,matrix-org/synapse,matrix-org/synapse