In the old days of carburetors and fixed ignition timing (you adjusted the timing yourself and it remained fixed until you adjusted it again), avoiding preignition was the limit on advancing the timing and leaning mixture.
Preignition happens when gas-air mixture ignites due to HEAT and COMPRESSION before it is supposed to. Obviously, this is usually when your engine is running under heavy load (like towing up a grade).
Higher octane gas suppresses preignition through needing slightly more heat and pressure to self-ignite AND slower spread of the flame front.
Modern engines have knock sensors and computer regulated timing to prevent preignition. So if you have knocking with a modern engine - your issues can be knock sensor(s), computer programming, and insufficient octane when your engine is running hot and at high power.
Easiest cure is to increase octane to see if that alleviates the problem. You only need the increased octane when under heavy loads.
Because I learned this flying super-charged, carbureted, air-cooled piston aircraft where the pilot monitors and controls engine temp and mixture, when I'm towing I increase the octane of the gas I buy as a preventative measure. Around town, not towing at 6K altitude 85 octane is just fine. Towing, I go to the manufacturer's recommended 87 octane minimum so I don't have to worry about the knock sensors and computer retarding timing. When towing below 2K altitude, I'll go up to 89 octane as a precaution because of the increased internal pressure and because the gas engine has 235K miles on it. Although the engine temp gauge stays in the same place, I can feel the heat pouring out of the engine compartment when I stop on a warm day after towing at 75mph across Western Texas. The higher octane gas may not be critical but it gives me peace of mind under the circumstances.
just my experiences
2019 Flagstaff T21TBHW A-frame
2008 Hyundai Entourage minivan
camping Colorado and adjacent states one weekend at a time