The mechanism of sawtooth precursors and sawtooth relaxations