AFAIK "swap file" is a rather loose naming convention that applies to a few different things on linux platforms. Here from what you show us, it is a swap file, with exactly 2048MB or 2GB of swap space.
It is there because some process or program or user with root permission on your system, created it. It is actual swap space and may or may not be enabled. It is usually created as a supplement to the more conventional swap space mounted at boot.
You or a process can create a swap file anywhere. Here it was created on
/, your root partition. You can repeat that process like so:
(here I use the
dd "data dump" command.)
$ su # enter root password.
# dd if=/dev/zero of=/extraswapfile bs=1M count=1024
# mkswap /extraswapfile
# swapon /extraswapfile # to turn the swapfile on
# swapoff /extraswapfile # to turn it off
To visualize your total available swap space, you can use
swapon -s as you do in your question. You will see the previous swap partition's space (if any) + the 2GB of extra swap space you just enabled via the swap file.
A swap file is not persisted and disappear at reboot, so it is practical when administering swap space in an ad hoc way is needed. Rebooting then wipes your (swap) slate clean. If you want to make a swap file persistent across reboots, edit
/etc/fstab to include:
/extraswapfile none swap sw 0 0
But persisting a swap file is generally ill-advised. Swapping already tends to translate as a drop in performance due to increased I/O operations on disk. It is preferable to increase the size of a swap partition than to add to a supplementary, non-contiguous swap space in rhe form of a swap file. Your case seems different since you do not have an already existing swap partition.
For a discussion on swap area priority, also see
man 2 swapon.