Who was the priest?

“And he said to them, “Have you never read what David did, when he was in need and was hungry, he and those who were with him: how he entered the house of God, in the time of Abiathar the high priest, and ate the bread of the Presence, which it is not lawful for any but the priests to eat, and also gave it to those who were with him?”” (Mark 2:25–26)

The apparent confusion is already evident in Tanakh.
1 Samuel 22:20
"But one son of Ahimelech the son of Ahitub, named Abiathar, escaped and fled after David."
Ahitub → Ahimelech → Abiathar.
2 Samuel 8:17
"Zadok the son of Ahitub and Ahimelech the son of Abiathar were priests."
Abiathar → Ahimelech
Ahitub → Zadok
1 Chronicles 18:16
"and Zadok the son of Ahitub and Abimelech the son of Abiathar were priests..."
Abiathar → Abimelech
Ahitub → Zadok
1 Chronicles 24:3
"...Zadok of the sons of Eleazar and Ahimelech of the sons of Ithamar..."
Ithamar → Ahimelech
Eleazar → Zadok
1 Chronicles 24:6
"...Zadok the priest, Ahimelech the son of Abiathar..."
Abiathar → Ahimelech
So pulling this all together what do we have?
Ahitub → Ahimelech → Abiathar → Ahimelech.
But Abiathar was the dominant character and associated strongly with David. It's interesting that in Tanakh Ahimelech is not called 'high priest', just the priest and other priests are mentioned. Also, if both Abiathar's father and son are called Ahimelech, without the text telling us, how do we know who was high priest? Furthermore, it is quite common when referring in the past to a later titled person. For instance when looking back to WW2 one could say '...the Queen did...' She's queen now but George was the monarch then. So Mark could be referring back to the days of Abiathar, even before he became high priest. After all, Abiathar is the only one who came out of that incident unscathed.