I noticed my PHP sessions folder is filled with millions of files with the same session data. For example let's assume its a 48 byte long string, content remains the same.
Let's assume there are approximately 1.5 million of these session files in /var/tmp/php/sessions
If I do the math right 48 bytes * 1500000 files / 1024 / 1024 = 68 MB approx.
But if I do the following I get a 6G result
cd /var/tmp/php/sessions du -ch
1) Why does it show 6G (approximately)? (Possible answer in my 2nd question below)
More checks : Sorting files in descending order of file size to check the largest file size. Individual file size is 4k
du -a | sort -n -r | head -n 10 6464600 . 4 ./sess_fffffABCDcdf9c312340f094d165678
I've replaced some characters in the filename above.
2) Why does it show 4k? This is related to file system block size. 6G usage makes sense a bit now. Reference : https://stackoverflow.com/questions/26666642/why-the-size-of-an-empty-directory-in-linux-is-4kb
3) If I go with Redis as a the session handle for PHP it will definitely be faster than disk but will it theoretically only use around 68 MB of data on the RAM, plus some overhead maybe?
4) Does Redis try to reduce actual memory usage if the the values stored on it are the same, i.e. same value repeated 1.5 million times for different session keys?
I've no control over the session and it's data and cannot prevent sessions from being created or remove their content even though it's repetitive.
I'm looking for confirmation on my first two questions and slightly more explanation with references on questions 3 and 4 if possible.