pagefile.sys is a swap file that is a component of virtual memory and is used to free up RAM. When you run, for example, a lot of programs, the RAM may run out of space to open new programs or files, which would prevent the system from continuing. In this situation, the system will free RAM memory by rewriting its contents to the swap file (pagefile.sys). The system will write to the swap file what you are not currently using. When it is needed again, it will rewrite it to RAM.
The size of the swap file usually matches the size of the RAM. It can be set so that its size is always the same, or that it changes dynamically depending on how much memory will be freed from RAM.
By default, the swap file is on the system partition, but it is best to put it on the fastest disk. If you have one disk with two partitions, the one on which the swap file is located does not matter much. However, if you have two disks, it is best to place the swap file on the second disk, i.e. the one on which there is no system - it will run faster. You can also have several swap files, but only if you have several partitions, because you can assign one such file to each partition.
It is a good idea to place a swap file on a FAT32 partition instead of NTFS because it will simply run faster. However, a swap file larger than 4 GB cannot be created on a FAT32 partition.
The size of the swap file should be 1.5 x RAM, i.e. if you have 2 GB RAM, the swap file should be at least 3 GB (1.5 x 2 GB = 3 GB).
The swap file, like other files, is fragmented naturally, but it cannot be defragmented because it is always in use during system operation. The system defragmenter will not cope with this. However, the PageDefrag program available on the Microsoft website will handle this:
https://docs.microsoft.com/pl-pl/sysinternals/downloads/pagedefrag The swap file is an element of system memory that guarantees that you will never run out of memory. There are situations, however, when some memory-eating program needs a lot of memory, but only in RAM. If the RAM memory resources are less than the program needs it, the swap file will not help here.