There number of published researches that cover this point are available. You can access them easily to get complete details on this mechanism. The URL of these papers are :
In general, the formation of the onion rings is due to the process of friction heating due to the rotation of the tool and the forward movement extrudes the metal around to the retreating side of the tool.
Onion rings are the most prominent features of most friction stir welds. The formation of onion ring is found to be a geometric effect due to the fact that cylindrical sheets of material are extruded during each rotation of the tool and the cutting through the section of the material produces an apparent 'Onion Rings'.
Yes. the onion rings are not desirable. They should be as smooth as possible. More rough the onion rings, more inappropriate the welding is. Here inappropriate is regarding the parameters selections.
This phenomenon is caused due to the fact that when the welding is going on the material is being transferred from RS to AS.
In a nutshell, the joining region of the joints should be as smooth as the Base Metals are.
While rough onion ring formations are not desirable, it is my understanding that totally eliminating onion rings is both impossible and not desirable. They can be smoothed down post weld through post processing (sand/grind) to avoid stress concentrations, though.
Guerra et al (DOI: 10.1016/S1044-5803(02)00362-5) explained them as high strain rate shear bands on the advancing side of the weld and extruded material on the retreating side of the weld.
Tongne et al (DOI: 10.1016/j.jmatprotec.2015.02.020) explained them as alternating layers of high strain rate extrusion bands and average strain rate extrusion bands deposited into the void behind the pin. This paper also suggested that onion ring structures initiate on the retreating side of the weld and compete with tunnel defects originating at the advancing side of the weld. Therefore, more pronounced onion ring structures mean less tunnel defects.
Tongne et al (DOI: 10.1016/j.jmatprotec.2016.08.030) also noticed that there is an optimal translation rate where material flow becomes regular and the onion ring structure extends across the width of the weld. If the onion ring structure does not extend across the length of the weld, the quality of the weld tends to decrease.
The above observations may be material dependent. I have done most of my research on AL 6061-T6. They seem to be remnants of the extrusion process, as when one side of the weld deposits material behind the pin, the pressure on the material in front of the weld is dropped. This is suggested because of the oscillation in axial force applied during welding is equal to the rotation rate of the tool times the number of faces of the pin (1 for circle, 3 for triangle, etc.)