# sharing filesystem cache with KVM

## MorpheuS.Ibis

Hi

I am looking for a way to share filesystem cache between my virtual systems and the host (all running gentoo), as I don't have that much memory and wasting it by having files cached two times doesn't seem very economical to me. I have tried KSM, but AFAIK that can't merge cache pages (those probably aren't marked madvise(MADV_MEDGEABLE)-ed)

any way to do this? maybe disabling filesystem cache altogether in virtual systems?

sorry if this is not the right place to put this

EDIT: I don't mean fscache kernel feature, but "standard" cacheing of disk reads

----------

## prymitive

If host and guest machines are all gentoo than use isolation istead of virtualization, this way You will have one kernel and one cache. You can't share cache between two kernels, doesn't matter if they are virtual or not.

EDIT: this means for example openvz instead of kvm.

----------

## VinzC

 *prymitive wrote:*   

> EDIT: this means for example openvz instead of kvm.

 

I second that. I've installed several OpenVZ hosts if you need some help.

----------

## MorpheuS.Ibis

 *prymitive wrote:*   

> You can't share cache between two kernels

 

crap, not what I was hoping for

I can't use single kernel for all the VMs as they are configured for different purposes and have quite different configs/versions (stable/testing, hardened/standard, 64/32bit), plus I have some windows VMs as well which would have to use KVM anyway

well thanks for saving me the time spend on more research and digging through kernel caching code

EDIT: the server should have enough free memory slots, so I will solve/postpone the problem by adding some more memory modules, thanks for help

----------

## Mad Merlin

 *MorpheuS.Ibis wrote:*   

> Hi
> 
> I am looking for a way to share filesystem cache between my virtual systems and the host (all running gentoo), as I don't have that much memory and wasting it by having files cached two times doesn't seem very economical to me. I have tried KSM, but AFAIK that can't merge cache pages (those probably aren't marked madvise(MADV_MEDGEABLE)-ed)
> 
> any way to do this? maybe disabling filesystem cache altogether in virtual systems?
> ...

 

AFAIK, the entire guest memory is marked as mergeable, and thus can be reclaimed with KSM. To KVM, it doesn't matter what the guest is doing with the memory (disk cache, application code, zeroing it for fun...), it's all the same.

----------

## MorpheuS.Ibis

 *Mad Merlin wrote:*   

> AFAIK, the entire guest memory is marked as mergeable, and thus can be reclaimed with KSM. To KVM, it doesn't matter what the guest is doing with the memory (disk cache, application code, zeroing it for fun...), it's all the same.

 

well, yes, but AFAIK both/all the same pages need to be marked mergeable to be merged by KSM, and host cache isn't marked (thus I can merge cache of two guests, but I can't merge it with hosts)

correct me if I'm wrong, that is very much possible

Thanks

----------

## Mad Merlin

 *MorpheuS.Ibis wrote:*   

>  *Mad Merlin wrote:*   AFAIK, the entire guest memory is marked as mergeable, and thus can be reclaimed with KSM. To KVM, it doesn't matter what the guest is doing with the memory (disk cache, application code, zeroing it for fun...), it's all the same. 
> 
> well, yes, but AFAIK both/all the same pages need to be marked mergeable to be merged by KSM, and host cache isn't marked (thus I can merge cache of two guests, but I can't merge it with hosts)
> 
> correct me if I'm wrong, that is very much possible
> ...

 

Yes, I'm fairly sure this is correct. It's probably best to either commit all of your memory to guests and let the guests cache (which could then be reclaimed with KSM) or give super minimal amounts of memory to guests so that they have no space to cache things with, and let the host cache everything. Neither approach is ideal, but it's better than nothing.

----------

