Cannot allocate size for swapfile

My swap size shows 0bytes so I tried to increase the swap size.
I used following commands
Sudo swapoff -a
Sudo dd if=/dev/zero of=/swapfile bs=1G count=4

After this system freezes. Even cursor doesnt work and after sometime killed prompt is shown

Use archwiki to do any system administartion instead of random web search results