[PATCH 2/2] KVM: arm64: Add memcg accounting to KVM allocations

Marc Zyngier maz at kernel.org
Thu Sep 2 11:11:48 PDT 2021


On Thu, 02 Sep 2021 01:28:01 +0100,
Jia He <justin.he at arm.com> wrote:
> 
> Inspired by commit 254272ce6505 ("kvm: x86: Add memcg accounting to KVM
> allocations"), it would be better to make arm64 KVM consistent with
> common kvm codes.
> 
> The memory allocations of VM scope should be charged into VM process
> cgroup, hence change GFP_KERNEL to GFP_KERNEL_ACCOUNT.
> 
> There remained a few cases since these allocations are global, not in VM
> scope.
> 
> Signed-off-by: Jia He <justin.he at arm.com>
> ---
>  arch/arm64/kvm/arm.c      | 6 ++++--
>  arch/arm64/kvm/mmu.c      | 2 +-
>  arch/arm64/kvm/pmu-emul.c | 2 +-
>  arch/arm64/kvm/reset.c    | 2 +-
>  4 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index e9a2b8f27792..9d6f5bcaddef 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -289,10 +289,12 @@ long kvm_arch_dev_ioctl(struct file *filp,
>  
>  struct kvm *kvm_arch_alloc_vm(void)
>  {
> +	unsigned long sz = sizeof(struct kvm);

If you are going to introduce an extra variable, please use the
correct type (size_t).

> +
>  	if (!has_vhe())
> -		return kzalloc(sizeof(struct kvm), GFP_KERNEL);
> +		return kzalloc(sz, GFP_KERNEL | GFP_KERNEL_ACCOUNT);

Why both GFP_KERNEL and GFP_KERNEL_ACCOUNT?

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.



More information about the linux-arm-kernel mailing list