Refactor upgrade step to reduce memory consumption and avoid restarts on instances running with supervisor's memmon