When compiling the Dlib library on my Raspberry Pi pi3, I found that the compilation failed because of insufficient memory. The Raspberry Pi is 1G memory, swap only 50M, so the swap is increased to 500M, compiled through. Here's how to set it up:
Using the free command with the M parameter to see the swap file size, the official recommendation is that when RAM is 2 to 4.5G, swap is twice times ram, and swap equals RAM if RAM is greater than or equal to 4G
You can also use cat to view the swaps files in the ETC directory, such as
Add 1G of memory using the DD command
Make a swap file using the Mkswap command
Starting swap files with Swapon
Use the free view again to find that swap does increase by 1G
However, this is only valid for the current system, and if the system restarts, the swap becomes the same size.
If you want to continue to work after the next reboot, you need to switch to the root user and edit the/etc/fstab file to write the configuration to the/etc/fstab file.
The following is the contents of the/etc/fstab file, only need to add the last sentence to the/etc/fstab file can be
# # # #the content of Fstab
#
#/etc/fstab
# Created by Anaconda on Wed Dec 16 22:03:21 2015
#
# Accessible filesystems, by reference, is maintained under '/dev/disk '
# See mans Pages Fstab (5), Findfs (8), mount (8) and/or Blkid (8) for more info
#
/DEV/MAPPER/VG_GOLONGLEE-LV_ROOT/EXT4 Defaults 1 1
Uuid=20048355-eb7d-4624-a2e1-7de220341c6a/boot EXT4 Defaults 1 2
/dev/mapper/vg_golonglee-lv_swap swap swap defaults 0 0
TMPFS/DEV/SHM TMPFS Defaults 0 0
Devpts/dev/pts devpts gid=5,mode=620 0 0
Sysfs/sys Sysfs Defaults 0 0
PROC/PROC proc Defaults 0 0
/tmp/swap Swap Defaults 0 0
The above method is originally from here
Increase swap space size in Linux systems