We use recent observations of the HI mass function to constrain the amount of cold gas in dark matter halos. It is found that the cold gas mass in a halo decreases rapidly with decreasing halo mass for low-mass halos with $M<10^{12} h^{-1}{\rm M_\odot}$. This result is in conflict with the standard model, in which most of the gas in a low-mass halo is assumed to settle into a gaseous disk, and the cold gas is depleted by star formation and supernova-driven outflow until the disk becomes gravitationally stable. Heating by the UV background can reduce the amount of cold gas in halos with masses $<10^{10} h^{-1}{\rm M}_\odot$, but is insufficient to explain the observational result. A consistent model can be found if low-mass halos are embedded in a preheated medium, with a specific gas entropy $\sim 10\,{\rm keV\,cm^{2}}$. Such a model can also explain why the faint-end slope of the galaxy luminosity function is flat. We propose a preheating model in which the medium around low-mass halos is preheated by gravitational pancaking. Since large-scale tidal fields tend to suppress the formation of low-mass virialised halos while promoting the formation of pancakes, the formation of massive pancakes may precede that of low-mass dark halos at the present time. ‘Previrialisation’ of such pancakes can heat the intergalactic medium. The preheated gas has a cooling time longer than the age of the Universe at $z\lesssim 2$, and has a specific entropy comparable to that required to reduce the amount of cold gas and star formation activity in galaxy halos.