Periodicity in recurrent fast radio bursts and the origin of ultralong period magnetars