[PATCH v10 19/21] virt: geniezone: Provide individual VM memory statistics within debugfs

Simon Horman horms at kernel.org
Mon Apr 15 09:32:12 PDT 2024


On Fri, Apr 12, 2024 at 02:57:16PM +0800, Yi-De Wu wrote:
> From: "Jerry Wang" <ze-yu.wang at mediatek.com>
> 
> Created a dedicated per-VM debugfs folder under gzvm, providing
> user-level programs with easy access to per-VM memory statistics for
> debugging and profiling purposes. This enables users to effectively
> analyze and optimize the memory usage of individual virtual machines.
> 
> Two types of information can be obtained:
> 
> `cat /sys/kernel/debug/gzvm/<pid>-<vmid>/protected_hyp_mem` shows memory
> used by the hypervisor and the size of the stage 2 table in bytes.
> 
> `cat /sys/kernel/debug/gzvm/<pid>-<vmid>/protected_shared_mem` gives
> memory used by the shared resources of the guest and host in bytes.
> 
> For example:
> console:/ # cat /sys/kernel/debug/gzvm/3417-15/protected_hyp_mem
> 180328
> console:/ # cat /sys/kernel/debug/gzvm/3417-15/protected_shared_mem
> 262144
> console:/ #
> 
> More stats will be added in the future.
> 
> Signed-off-by: Jerry Wang <ze-yu.wang at mediatek.com>
> Signed-off-by: Liju-Clr Chen <liju-clr.chen at mediatek.com>
> Signed-off-by: Yi-De Wu <yi-de.wu at mediatek.com>

...

> diff --git a/drivers/virt/geniezone/gzvm_vm.c b/drivers/virt/geniezone/gzvm_vm.c

...

> @@ -398,6 +409,113 @@ static void setup_vm_demand_paging(struct gzvm *vm)
>  	}
>  }
>  
> +static int debugfs_open(struct inode *inode, struct file *file)
> +{
> +	file->private_data = inode->i_private;
> +	return 0;
> +}

nit: Coccinelle suggests that simple_open() can be used in place
     of the debugfs_open() implementation above.

...

> +static const struct file_operations hyp_mem_fops = {
> +	.owner = THIS_MODULE,
> +	.open = debugfs_open,
> +	.read = hyp_mem_read,
> +	.llseek = no_llseek,
> +};
> +
> +static const struct file_operations shared_mem_fops = {
> +	.owner = THIS_MODULE,
> +	.open = debugfs_open,
> +	.read = shared_mem_read,
> +	.llseek = no_llseek,
> +};

...



More information about the linux-arm-kernel mailing list