I have a Raspberry Pi 3 and I created a swap space with reference to this tutorial, How to set up swap space?.
However, even when my memory is almost fully used, none of my swap memory is used.
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It only takes a minute to sign up.Sign up to join this community
Your memory isn't "almost fully used" in the sense you think.
Cached: The amount of memory in use as a page cache by the system. Basically, this is stuff that was read off disk (or whatever storage) into memory for some useful purpose, but that purpose is over. However, since the memory is currently not needed for any other reason, it has been left there in case it is needed again in the near future. This is very normal since systems tend to be composed of small pieces that are simply reused different ways. Ideally, after a system has been running for a while, all of the memory will appear used this way, except for what is actually needed, which is:
Used +/- buffers/cache: The reason that line is +/- is because it is "-" with regard to "used" but + with regard to "free". We now see that the system is actually using only 238 MB, and has 687 free. Most of that "free" memory, however, contains cached data. Note that cached data can be instantaneously evicted if the system needs the space, exactly the same as if it were "empty".
Part of the reason RAM is used this way is that it uses the same amount of energy whether it is considered "empty" or "full", and that replacing previously used space is exactly as expensive as filling unused memory, so caching has no penalty and many benefits.
Swap will tend to only get used during those times when the system has had to drop most of the cache and the "free +/- buffers" number becomes very low. After that it will also be left there, so you may end up with a situation where it looks like most of your memory is is free and yet the system is still "using" swap. Whatever's in swap at that point isn't being used, it was just left there like cache and the system keeps track of it in case the same circumstances re-occur.