I think the limiting factor in the amount of cellular mass that a volume can contain is probably either carbon content or nitrogen content.
Both maximize in the oceans near to shorelines, with smaller local maxima near some vents.
On land, I'd expect a gradient in both, decreasing with depth, but there's probably more CO2 100-m down in water than in rock.
The inhabited volume is huge, but the density of biomass is many times lower than in the oceans.
In oceans, most of the living beings, including most of the anaerobic bacteria that live at great depths or in the bottom of the ocean, are sustained by the solar energy captured by the algae living in the superficial layer of the sea. The living beings that live at greater depths, beyond those reached by light, are fed mostly by the dead matter falling down from the surface (with some exceptions around hydrothermal vents and underwater volcanos, but even there most of the bacteria are aerobic bacteria that oxidize substances ejected by vents using free oxygen that diffuses from the surface and which had been generated by algae with solar energy).
So in oceans there is a great density of bacteria and archaea, because most of the energy consumed by them comes from abundant solar energy.
At small depths in soil and rocks, dead matter carried by water from the surface can still provide food for abundant bacteria.
At greater depths that are not reached by dead matter from the surface, the only energy source is formed by free hydrogen or carbon monoxide gases, which come from volcanic sources or from oxidation reactions between water and iron containing rocks, like olivine. The energy that can be extracted by anaerobic bacteria from such gases is extremely low and such bacteria can grow and multiply only extremely slowly. The density of bacteria and archaea in the fissures of rock is limited by the flow of gases that can provide energy and it is extremely low in comparison with the places that benefit from using solar energy or aerobic metabolism based on substances originally synthesized by algae or plants.
At a depth great enough in the rocks, the temperature becomes so high that not even archaea can live, so the layer of the rocks that hosts archaea and bacteria is also limited in depth to a volume not much greater than the oceans, but with a much lower density of biomass.