Rack your brains
To rack one's brains is to strain mentally to recall or to understand something.
The rack was a medieval torture device. The crude but, one presumes, effective racks often tore the victim's limbs from their bodies. It isn't surprising that 'rack' was adopted as a verb meaning to cause pain and anguish. Shakespeare was one of many authors who used this; for example, from Twelfth Night, 1602:
"How haue the houres rack'd, and tortur'd me, Since I haue lost thee?"
The term was called on whenever something or someone was under particular stress and all manner of things were said to be 'racked'; for example, in the Prymmer or boke of priuate prayer nedeful to be vsed of al faythfull Christians, 1553 there's a reference to the racking, that is, increasing, of land rent:
"They may not racke and stretche oute the rentes of their houses"
The first recorded use of this being specifically applied to brains is in William Beveridge's Sermons, circa 1680:
"They rack their brains... they hazard their lives for it."
The same idea was used by the composer William Byrd in 1583 when he wrote:
"Racke not thy wit to winne by wicked waies."