When your life is besieged, the music is therapy, vicarious mastery in a world where you control virtually nothing, least of all the fate of your body. I had a friend in middle school who would play Rakim every morning because he knew there was a good chance that he would be jumped en route to or from school by the various crews that roamed the area. But, in his mind, the mask of rap machismo made him too many for them.

“Good Kid” is narrative told from behind the mask. Fantasies of rage and lust are present, but fear pervades Lamar’s world. He pitches himself not as “Compton’s Most Wanted” but as “Compton’s Human Sacrifice.” He loves the city, even as he acknowledges that the city is trying to kill him. “If Pirus and Crips all got along,” he says, “They’d probably gun me down by the end of this song.”

On one of the most affecting songs, “The Art of Peer Pressure,” he engages in a series of criminal escapades. It’s reminiscent of N.W.A.’s “Gangsta, Gangsta,” except that Lamar is not a supercriminal but a boy out to impress his friends. The character’s drug use is not so much a choice of pleasure as it is a puerile bid for attention: “Look at me,” he raps. “I got the blunt in my mouth.”

I must confess my bias. I grew up in Baltimore during a time when the city was in the thrall of crack and Saturday night specials. I’ve spent most of my life in neighborhoods suffering their disproportionate share of gun violence. In each of these places it was not simply the deaths that have stood out to me, but the way that death corrupted the most ordinary of rituals. On an average day in middle school, fully a third of my brain was obsessed with personal safety. I feared the block 10 times more than any pop quiz. My favorite show in those days was “The Wonder Years.” When Kevin Arnold went to visit his lost-found love Winnie Cooper, he simply hopped on his bike. In Baltimore, calling upon our Winnie Coopers meant gathering an entire crew. There was safety in numbers. Alone, we were targets.