We analyze numerically the mechanisms controlling the spacing of chimneys—channels devoid of solid—in two-dimensional mushy layers formed by solidifying a binary alloy. Chimneys are the principal conduits through which buoyancy effects material transport out of the mushy layer and into the liquid from which it formed. Experiments show a coarsening of chimney spacing; we pursue the hypothesis that the spacing adjusts to optimize material transport and hence maximize the rate of removal of potential energy stored in the mushy layer. The optimal solute flux increases approximately linearly with the mush Rayleigh number. However, for spacings below a critical value, the chimneys collapse and solute fluxes cease, revealing a hysteresis between chimney convection and no flow. The results are consistent with a variational principle controlling the dynamics of this dissipative system.