Nobody really knows how the term “green room” originated, but whether you’re relaxing backstage before presenting an Academy Award, awaiting a guest spot on “The View” or chilling before headlining a sold-out show in Vegas, that’s what they call that faux-living room waiting area where you nosh on snacks and chat with friends and go over some pre-show notes.

It’s the green room.

Even if you’re a struggling punk band serving as the opening act at a deep backwoods ramshackle barn festooned with Confederate flags and white supremacist graffiti, there’s a green room.

Until it’s a bloody red room.

Writer-director Jeremy Saulnier’s “Green Room” is a wonderfully nasty, gruesome, jagged-edge gem of a horror film, with echoes of “The Cabin in the Woods,” “The Texas Chain Saw Massacre” and “The Evil Dead,” and so many other films about a group of smart and cynical young people who find themselves cut off from the civilized world and in a bloody mess from which there just might be no escape.

Unlike far too many horror filmmakers, Saulnier has the confidence and the skill set to spend a considerable amount of time introducing us to the main characters before anyone suffers so much as a paper cut.

Young millennials Pat (Anton Yelchin), Sam (Alia Shawkat), Reece (Joe Cole) and Tiger (Callum Turner) are the Ain’t Rights, a hardcore punk band with a cult following but almost no commercial success.

They’re so pure and so badass they refuse to have a social media presence, because they want their fans to be in the moment and not tweeting to them.

They’re so pure and so badass they’ll siphon gas to keep their tour van running rather than sell out to The Man.

They’re so pure and so badass they only reluctantly grant an interview to an underground podcaster.

They’re so full of s—.

One suspects even a couple of the band members know they’re posing as much as they’re performing.

After a relatively lucrative show (i.e., $300 or $400 total) falls through, the cash-poor band accepts a gig playing to a mob of head-banging skinheads in a grungy beer hall in the middle of the woods in Oregon.

The moment the Ain’t Rights’ van enters the compound, which is teeming with surly, jack-booted types who seem six days out of prison, their best move would have been to turn around and floor it.

But they’re so cool, they’ve got this. Ahem.

Once the band is onstage, Pat and Sam take a look at the frothing mob and decide they’ll toy with them by kicking off their set with the Dead Kennedys’ “Nazi Punks F— Off.”

Bad idea. Why not just taunt trained fighter dogs with raw meat, deny them the meat and then forget to lock their cages?

Even so, it appears as if the band will be able to take the money and run, no harm, no foul — but Sam has left her cell phone in the green room, and Pat volunteers to retrieve it, and when Pat enters the green room he sees something he wasn’t supposed to see …

And that’s when the bone-cracking, temple-stabbing, killer-dog-biting bloodshed begins.

Patrick Stewart makes a great entrance as Darcy, the owner of the club and the leader of the “movement,” as he calls it, to restore white pride. As one act of violence begets more violence and the possibility of Darcy’s entire empire (which includes weapons and a LOT of drugs) blowing up, Darcy commands his underlings to get rid of the witnesses, aka the Ain’t Rights, by any means necessary.

Of course Darcy and his henchmen are the worst people on the planet — but a couple of the henchmen have possibly redeeming qualities, and it’s not often we see a movie with conflicted henchmen.

It’s also kinda great to see the Ain’t Rights — these smug, pretentious, wannabe punk rockers — thrust into a REAL hardcore situation, which turns one of them into a sniveling crybaby, and makes us more sympathetic to other band members.

I loved Imogen Poots’ work as a tough, seemingly heartless rebel who is a regular at Darcy’s club and thinks she can handle anything — but shifts into another gear when the bloodshed begins. Alia Shawkat (“Arrested Development”) also shines as the sole female member of the Ain’t Rights.

Stewart is a magnificently malevolent presence as Darcy. Macon Blair, who starred in Saulnier’s “Blue Ruin,” serves further notice he’s a breakout-level talent with his performance as Darcy’s trusted No. 2, Gabe. From the moment Gabe appears onscreen, Blair’s subtle and precise acting is a joy to experience. This guy is the real thing.

The cinematography, the set design, the all-important soundtrack, the editing: all first-rate.

This is one smart chiller.

★★★1⁄2

A24 presents a film written and directed by Jeremy Saulnier. Running time: 95 minutes. Rated R (for strong brutal graphic violence, gory images, language and some drug content). Opens Friday at AMC River East and the Music Box Theatre.