The cavitation flow of the cartridge pilot-operated relief valve's main valve port was numerically simulated and studied using Computational Fluid Dynamics (CFD) in our research, and the relief valve structure was modified to decrease cavitation noise. The findings indicate that cavitation in the relief valve occurs mostly downstream of the main valve port and is linked to the wall. Cavitation generation is influenced by the jet at the valve port. The closer the high-speed jet at the valve port is to the valve's inner wall, the more readily cavitation occurs. Conversely, there is less cavitation. This paper reports the effect of the forms and parameters of the main port structure on the jet angle and the morphology of cavitation. The structure of the spool's annular groove has a considerable influence on the cavitation attached to the spool wall and the valve sleeve wall, whereas the outlet position of the relief valve mostly impacts the intensity of cavitation near the valve sleeve wall. Based on this, the relief valve's optimized structure is designed, with which the maximum vapor volume fraction and total vapor volume of the cavitation flow are considerably decreased for various inlet pressures and spool openings. The results of the experiment show that following optimization, the noise of the relief valve drops dramatically, confirming that optimizing the structure has a beneficial impact on decreasing cavitation noise.