Start small and work your way up.
Start with a hammer-on, for example, on the A string between frets 7 and 9, between index and ring fingers. This is probably the easiest place to trill, at least it is for me.
Get that hammer-on good and solid. Try your best to make it faster.
Once you master that hammer-on, immediately do a pull-off, and let the lower note ring out. 797..... get it as fast as possible.
Then start adding the 9 at the end. 7,9,7,9.... This is what I'd really consider a trill. Here you may find your speed decreasing or your endurance becoming a challenge, and it's a great place to stop and practice.
As Luke said, it's totally about repetition and practice and training your wrist and fingers to make that rapid movement for a long time.
By the way, a trill between two fretted notes is often far easier than trilling between a fretted and open string (such as 0-2-0-2 type patterns, common in SRV/Eric Johnson type licks). It's actually a different movement because the pull-off is more forceful, so I'd start with the two fretted notes first.