Some corrections to the above answer. Port-id and port-priority are different. One is configurable. The other is internally set. I'll make an attempt to answer your question below.
There has to be just 1 root port per switch. By definition , this is the port with the lowest path-cost to root.
- A path-cost is the sum of all port-costs along a given path. And
port-cost is set by the speed of the link connected to a given
Now lets look at your diagram. SW3 has 2 paths to the root, and both go through SW2. Assuming that both the links out of SW3 are the same speed, the port-cost is identical. So the path cost is the same out of both its ports. Now we need a tie-breaker, cuz we can have only 1 root port.
By default, STP uses the bridge-id of neighboring switch to break the tie. But since the neighboring switch is the same switch here (SW2), STP next uses port-priority of the neighboring switch to break the tie. This is something that can be manually configured. But lets say that in your case, its at default, and therefore at the same setting on both switches. So STP falls to something that has to be unique. And this final fallback is the internal port-id. This is not the same as the interface number (0/1,0/2..) but is an integer that is mapped to the interface number internally. And usually lower interface numbers, are mapped to lower ordered port-ids.