Olivine occurs in both mafic and ultramafic igneous rocks and as a primary mineral in certain metamorphic rocks. Mg-rich olivine crystallizes from magma that is rich in magnesium and low in silica. That magma crystallizes to mafic rocks such as gabbro and basalt. Ultramafic rocks usually contain substantial olivine, and those with an olivine content of over 40% are described as peridotites. Dunite has an olivine content of over 90% and is likely a cumulate formed by olivine crystallizing and settling out of magma or a vein mineral lining magma conduits. Olivine and high pressure structural variants constitute over 50% of the Earth's upper mantle, and olivine is one of the Earth's most common minerals by volume. The metamorphism of impure dolomite or other sedimentary rocks with high magnesium and low silica content also produces Mg-rich olivine, or forsterite.