The whole desktop freezes after running minecraft for a few minutes

Hi,

I recently played modded minecraft on my gaming laptop with Nvidia card and AMD cpu, 16GBs of RAM. 16GB of SWAP

I allocated 8GB to minecraft (running on java 17). I use Endeavour OS

I ran minecraft and everything seem to be buttery smooth, nothing stuttered.
However, after about under 5 minutes, the whole system freeze, minecraft/desktop/whatever appear on my screen is like frozen in time. I can not interact with anything, even my mouse is not showing up, no hotkey combination is working. The only way is to force shutdown the laptop using the power button. after that, I did the same and the same.

I did wait but there was no result. The same thing happened to me on Ubuntu but I was not playing Minecraft on Ubuntu.