0

Test environment: Virtual Machine(Windows 11, VMware Workstation Pro), Ubuntu 22.04, mechanical hard drive.

Use the following command to generate 1GB of test data:

dd if=/dev/urandom of=test.data count=1M bs=1024 

Clear the cache:

sync; echo 3 > /proc/sys/vm/drop_caches 

Run:

time cat test.data > /dev/null 

Execution time:

real 0m14.814s user 0m0.011s sys 0m4.034s 

Clear the cache again:

sync; echo 3 > /proc/sys/vm/drop_caches 

Run:

time cat test.data > /dev/null 

Execution time:

real 0m1.761s user 0m0.020s sys 0m1.679s 

Run immediately again (without clearing cache):

time cat test.data > /dev/null 

Execution time:

real 0m0.227s user 0m0.009s sys 0m0.218s 

After clearing the cache, I checked /proc/meminfo to confirm that the cache was indeed cleared. Why is the second run still significantly faster even after clearing the cache?

Screenshot of the execution process:

Screenshot of the execution process

4
  • 1
    Have you tried clearing the cache on the host too? Commented May 22 at 2:53
  • @StephenKitt Thank you for reply. The virtual machine is running on VMware, and the host operating system is Windows 11. How can I clear the cache? Commented May 22 at 3:14
  • See this Q&A on SO. Commented May 22 at 3:53
  • 1
    Note that not only Windows, but also VMWare might implement in-RAM caching for disk images. (It's something I'd expect an advanced virtualizer to do.) Commented May 22 at 6:38

1 Answer 1

1

I haven't used VMware Workstation in a long time, but what you're seeing is disk caching on the host side.

For VirtualBox storage, simply uncheck the box labeled "Use host IO cache."

Host IO cache for storage in VirtualBox

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.