I rent a shared VPS that runs Debian 9. I am alloted 4GB RAM (4096MB), but sometimes my processes go over 4GB. This is largely due to the kernel caching a lot of my stuff, so I'd like to know if I can limit the kernel to 4GB so that when I need more RAM, it clears the buff/cache to ensure I don't go over 4GB.
You already are limited to 4 GiB of memory; that’s what the “4096” value in the output of
free -m means. Your graph is no doubt taking swap into account too, so when you see memory usage go over 4 GiB it’s because the sum of memory and swap used is greater than 4 GiB. (Either that, or it’s using powers of 10 rather than powers of 2.)