Step 1: Temporarily stop swap on Raspberry Pi:
sudo dphys-swapfile swapoff
Step 2: Modify swap size on Raspberry Pi
sudo nano /etc/dphys-swapfile
Change CONF_SWAPSIZE to e.g. 1024 for 1024MB / 1GB.
Step 3: Re-initialize the Raspberry Pi’s swap
sudo dphys-swapfile setup
Step 4: Start swap on Raspberry Pi
sudo dphys-swapfile swapon
Note: I/O activity
Using swap can increase I/O activity on the MicroSD card increasing chances of shortening the lifespan of the card.