The Film(s) Within the Film
If you've ever studied Hamlet, then you're already pretty familiar with the idea of a story within a story. In the Prince of Denmark's case it's The Mousetrap, a play within a play, but in Singin' in the Rain, we're looking at a movie within a movie. Actually, we're looking at two: The Dancing (previously, Dueling) Cavalier and Singin' in the Rain.
So what's the function of a movie within a movie? Mainly, the "little" movie is used to enhance the "big" movie. For example, The Dueling/Dancing Cavalier is the basis for most of Singin' in the Rain's conflict. When R.F. decides it will be a talkie, everything goes haywire and sets the movie's biggest plot points in motion.
The Dueling/Dancing Cavalier is also used to deepen our understanding of the movie's major characters. In Lina's case, it's used to bolster her role as a villain. All of her involvement in the production is tainted: from being unable to remember where the microphone is to demanding Kathy get no credit. It also shows how tempestuous her relationship is with Don; think about when they enact a passionate love scene while simultaneously threatening to ruin each other. For Lina, the movie within a movie brings out the worst in her.
Conversely, it brings out the best in Don. Each time the filming of The Dueling/Dancing Cavalier presents a challenge, Don hikes up his knickers to meet it. It's going to be a talkie? Cool, Don can talk. Don talk real good. The screening stinks? Fine, we'll make it a musical. Don sings and dances better than he talks. Lina sings like a dying goat? No worries, Don's girl Kathy has his back. The movie within the movie highlights Don's willingness and ability to change, and it helps him evolve.
But wait, there's more: We have a second movie within a movie. The final shot of Don and Kathy standing in front of the billboard for their first feature together, also titled Singin' in the Rain, is used to cement their happy ending. They're in love, they're movie stars, and they're not too proud to stand in a field and admire their own giant faces.