The Berber peoples of the Maghreb in the early Middle Ages can be roughly classified into three major groups: the Zenata across the north, the Masmuda concentrated in central Morocco, and the Sanhaja, clustered in two areas: the western part of the Sahara and the hills of the eastern Maghreb.
The eastern Sanhaja include the Kutama Berbers, who had been the base of the Fatimid rise in the early tenth century, and the Zirid dynasty, who have ruled Ifriqiya as vassals of the Fatimids since the latter moved to Egypt in 972.
The western Sanhaja are divided into several tribes: the Gazzula and the Lamta in the Draa valley and the foothills of the Anti-Atlas range; further south, encamped in the western Sahara desert, are the Massufa, the Lamtuna and the Banu Warith; and most southerly of all, the Gudala (or Judala), in littoral Mauritania down to the borderlands of the Senegal River.
The western Sanhaja had been converted to Islam some time in the ninth century.
They had been subsequently united in the tenth century and, with the zeal of neophyte converts, had launched several campaigns against the "Sudanese" (pagan peoples of sub-Saharan Africa).
Under their king Tinbarutan ibn Usfayshar, the Sanhaja Lamtuna had erected (or captured) the citadel of Awdaghust, or Aoudaghost, a critical stop on the trans-Saharan trade route.
After the collapse of the Sanhaja union, Awdagust had passed over to the Ghana empire; and the trans-Saharan routes had been taken over by the Zenata Maghrawa of Sijilmassa.
The Maghrawa had also exploited this disunion to dislodge the Sanhaja Gazzula and Lamta out of their pasturelands in the Sous and Draa valleys.
Around 1035, the Lamtuna chieftain Abu Abdallah Muhammad ibn Tifat (alias Tarsina), had tried to reunite the Sanhaja desert tribes, but his reign had lasted less than three years.