Rack likely comes from the Middle Dutch
“rec”, meaning 'framework', and the Old English 'recken', meaning
'to stretch out'. Usage became the word used for a frame that you
put things on to dry or to stretch something out on.
Later the word also came to mean a frame for putting people on for
torture. This expanded the meaning to include causing mental or
physical harm or suffering or to stretch or strain. So, when someone
says they are racking their brain, it means they are straining their
brain. I reckin this stuff is true.