Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp126861pxf; Tue, 30 Mar 2021 22:01:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4lThpG9gEQ7KEYQyDXtXeqIJslDEDwblfkTGkMlGbjtwRwLef+VNqGLF9gZE6HX1ht9zl X-Received: by 2002:a17:906:f953:: with SMTP id ld19mr1517167ejb.164.1617166867555; Tue, 30 Mar 2021 22:01:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617166867; cv=none; d=google.com; s=arc-20160816; b=AE7XISKU0nMKu0KCa3dj1raR1d/A3wNYalBMT86r873P/agWtbkYU4KiGa5DCQoMh5 a6updUsH0nQ5oIaeYI5THfII+3H6hi1Xj1uT8XZ58TPUQHCQJ0kdIU4mC6BCS9w0Q/Cn jziUOS9F6+p9zitVkWyi4SKnYp+a8eKOutJlJdXDlAS1TZ1wYDqdeoSGvJ+08Dg7mleP TbbNUgEKC6JCY/6i/cmmJXxJkv+XI4qS/IJzeFKrrovCtvBpfi4Hi+0Ma6Y4IGWbDwY/ RtpREz7rwfkI8DxllmrM/3qKZT8tPdxj/jscOl53R7+Jbtx0h4yScLyg9iMYNyV90/zn wl3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=IuFbiB26Sb3dU7rtk02ZCczKB4Gc8hOz5qs5qATXub8=; b=RQjJLhQquTt4/BfZGovQRRejZjt04Gy0YgvqkZe0C0BL2uGFA5dyrEolkwZhd+ZN7d Nt2bDek5E5PCeBqE5GNGQ1IHJKnhpRUcrVCm2lUf6Qff5+2CbM5vO3jpScd68/Tg7wzp qVtEJf6UelTlpad8aPZLxSdJFXUgIk7WUjMx+bAvijDSTXqysmUi+QDZAd1QL//nBGUY ZAF2hkYy8Q//TBb8J6eCKXZuwNu4EYVT+aH+h6LtcmoF4Ki8ZmovwXpDQItpavWP08Zb N1YIP6Fk/a/Z9Zu7i6WIg8kaktcdbZFG93lMagVHLeXOQr/D7h8ie03qa12LvdznaWjs 2O2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WWO7bmjz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gs18si774882ejb.648.2021.03.30.22.00.45; Tue, 30 Mar 2021 22:01:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WWO7bmjz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233661AbhCaE7p (ORCPT + 99 others); Wed, 31 Mar 2021 00:59:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233629AbhCaE7a (ORCPT ); Wed, 31 Mar 2021 00:59:30 -0400 Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98210C061574; Tue, 30 Mar 2021 21:59:23 -0700 (PDT) Received: by mail-ot1-x334.google.com with SMTP id k14-20020a9d7dce0000b02901b866632f29so17840165otn.1; Tue, 30 Mar 2021 21:59:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IuFbiB26Sb3dU7rtk02ZCczKB4Gc8hOz5qs5qATXub8=; b=WWO7bmjzkeWN+EV+FTJNZ40JsxeXUFjaknr+X6i2DLvgsdvg5UF2OnYFNeHRBQIRCA KgjqwTUS0d9Sl8ALq9rDb1wEzlAD9ZYLkOJK7/3GraRMsBcwpBjdCme0rZKmP82pgbHZ ruxhbh6fIl85qoEW0QmonZloAnxtyM7VX8pV7Y4u4QrJSszfkKaBNpVGeNTZsekg7nm9 bSHY19ehHY/8r/6OyDDyzxbUwWYOSxvTFpyyxTepwf0ENWRGSgii45wc0WOXrLV+rwUN qzRoHzF6VNJW4k86kPVNE9gUh8eT9j2BDN0yRMUNUgIQ7xApoTX0vmFfilEvqr/ZiPB4 BOJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IuFbiB26Sb3dU7rtk02ZCczKB4Gc8hOz5qs5qATXub8=; b=AJyEAzfZedXYb8ZTcoRm8aFD15SjSMKxwNFw4IGqwaRAesGLIIvOa8yLxvQxZ31gRN B5LpQDwtbi1Sajs/kg+a8ZM4LAwfpZ55SCiOIAyuxzpoXnK1HEGYuV1wXigP9qjNeOSI GmFDtKuFmM639F02EJUpJiXGFkApp6jXBY12z08BjdjXjil3u9hrL80GmpP/KXThlr89 L1m/GbX2kK9II2vYcGCtVtDu3Q8pB8n82f102XEUjQabplGsWMziqxZlgAJ+umH5gx8e I4d9Kb5YFMZdGXafF8JdNREjdcIcc8EAH3c71enPEEPtXXviQ15Y96pb+bCL6x4bgODv /kGg== X-Gm-Message-State: AOAM530g3BXAfFV8z/lBnzlIzzRFzk8Mejp2gFSv97NoPhRz4LN08OIn 3debi3MaWCH5QdD5gVtOowe1vIhuUDLLaKOog3bSHRiQoRc= X-Received: by 2002:a05:6830:22c3:: with SMTP id q3mr1196612otc.56.1617166763033; Tue, 30 Mar 2021 21:59:23 -0700 (PDT) MIME-Version: 1.0 References: <20210331023025.2485960-1-seanjc@google.com> <20210331023025.2485960-2-seanjc@google.com> In-Reply-To: From: Wanpeng Li Date: Wed, 31 Mar 2021 12:59:11 +0800 Message-ID: Subject: Re: [PATCH 1/2] KVM: Account memory allocations for 'struct kvm_vcpu' To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 31 Mar 2021 at 11:24, Sean Christopherson wrote: > > On Wed, Mar 31, 2021, Wanpeng Li wrote: > > On Wed, 31 Mar 2021 at 10:32, Sean Christopherson wrote: > > > > > > Use GFP_KERNEL_ACCOUNT for the vCPU allocations, the vCPUs are very much > > > tied to a single task/VM. For x86, the allocations were accounted up > > > until the allocation code was moved to common KVM. For all other > > > architectures, vCPU allocations were never previously accounted, but only > > > because most architectures lack accounting in general (for KVM). > > > > > > Fixes: e529ef66e6b5 ("KVM: Move vcpu alloc and init invocation to common code") > > > Signed-off-by: Sean Christopherson > > > --- > > > virt/kvm/kvm_main.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > > > index 383df23514b9..3884e9f30251 100644 > > > --- a/virt/kvm/kvm_main.c > > > +++ b/virt/kvm/kvm_main.c > > > @@ -3182,7 +3182,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id) > > > if (r) > > > goto vcpu_decrement; > > > > > > - vcpu = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL); > > > + vcpu = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL_ACCOUNT); > > > > kvm_vcpu_cache is created with SLAB_ACCOUNT flag in kvm_init(), this > > flag will guarantee further slab alloc will be charged to memcg. > > Please refer to memcg_slab_pre_alloc_hook(). So the patch is > > unnecessary. > > Hmm, I missed that. However, AFICT only SLAB/SLUB enforce SLAB_ACCOUNT, SLOB > does not appear to honor the flag. The caveat to SLOB is that the > GFP_KERNEL_ACCOUNT will only come into play when allocating new pages, and so > allocations smaller than a page will be accounted incorrectly (I think). > But, a vcpu is larger than a page (on x86), which means the vcpu allocation will > always be correctly accounted. > > I've no idea if anyone actually uses KVM+SLOB, let alone cares about accounting I asked maintainer Christoph in 2013, he told me "Well, I have never seen non experimental systems that use SLOB. Others have claimed they exist. It's mostly of academic interest." > in the that case. But, it would be nice for KVM to be consistent with the other > kmem_cache usage in KVM, all of which do double up on SLAB_ACCOUNT + > GFP_KERNEL_ACCOUNT. > > Maybe rewrite the changelog and drop the Fixes? Agreed. Wanpeng