  The highly non-linear switching behavior of hafnia memristor actually hinders
its wide application in neuromorphic computing. Theoretical understanding into
its switching mechanism has been focused on the processes of conductive
filament generation and rupture, but possible phase transition and
crystallization around the region of conductive filaments (CFs) due to the
variation of O content have been paid less attention to. In this paper,
HfO$\mathrm{_x}$ structural models covering the full stoichiometries from Hf to
HfO$\mathrm{_2}$ were established, and the crystal structure evolution during
the reduction process of hafnia was obtained through first-principles
calculation. The electronic structures and O vacancy migration characteristics
of these structures were analyzed. A criterion was prescribed to predict the
mode of abrupt binary switching or gradual conductance modulation according to
the structure evolution of the CFs. In particular, factors that influence the
merging of tiny conductive channels into strong filaments are intensively
discussed, including the anisotropy of O vacancy migration and the size effect.
The feasibility of Mg doping to achieve robust gradual switching is discussed.
