This is an English expression which is very commonly used in both written and spoken language. The verb “rack” is used in some other English expressions such as “to be racked with guilt” and can be spelt both as “rack” and “wrack.”
The expression is used in order to denote that someone is trying really hard in order to either remember or to understand something. The verb “rack” is used in a figurative sense rather than the literal sense.
The use of the word “rack” dates back to the Medieval Times when a “rack” was used as a device for torture. This noun then became the verb “to rack” meaning “to cause pain or anguish” due to the fact that the device was used to decapitate humans. This verb was first used by Shakespeare in 1602 in his play Twelfth Night which reads “how haue the houres rack’d, and tortur’d me, Since I haue lost thee?”
It was not until the 1680’s that this verb was first used in relation to brains. This was in William Beveridge’s Sermons and reads “they rack their brains… they hazard their lives for it.”
An example of this expression in use can be found in J. K. Rowling’s Harry Potter and the Deathly Hallows. The quote reads “rack your brains, that should only take a couple of seconds.”