Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 191ACC433ED for ; Tue, 20 Apr 2021 13:11:14 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6ABAD61073 for ; Tue, 20 Apr 2021 13:11:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6ABAD61073 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:MIME-Version:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:Cc:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ev/OAJRgsEkJdTfGjVCvpNZJ7zb9WYlIGkiUStrWhBQ=; b=bKEaJzbgP4CjMJ8Z89n38Y6cAJ 0P82ZK68p8a8DLfGmBHq4uLNB1MN1ZhKxKARAVNRuMcw9tFMStFWf7O4F7KhdKmBiNO0xMaTw+ypa P1WM4xTf+qW6sshPjJt4nnvbjnxDq4WDp7fDpICsKhZc5RfzL4bdMI2+GEpPmH7redGg5bNW67H7Q UQa9HjGjarXcQDEWpv9vlVizxC4fI9t2MMVeZSxxY342C8IXaideNZsXmdvEQwv8nE9d3I1G5SKsX O+169x3bPiD4zt1s6S3FU+Cdi0YAeetP925Zi6oWVGdA3aYZpd3Ylf/9PatFxo/fwpTzC1Pm6jSHf HHnEwp+g==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lYq7o-00CA7l-6Z; Tue, 20 Apr 2021 13:09:08 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lYq7X-00CA6C-RU for linux-arm-kernel@desiato.infradead.org; Tue, 20 Apr 2021 13:08:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=2s4VnhvgLZ1+L63yjFEMoX7gkuCcGBX7mFUjVL8jyF0=; b=QbV/hWDvnp6YdBMZ8XEJD8LJ0Z L+fUdsOtna0R2LJkxeOjjxpEyZ7zaZdHqv98y12Vw0H2XPEdSA6AkeXESdVyqoJD6oZFWOPuHAe6d Hj75WKUGWLHJihlpeqghTyLPkCCvmLbPtZM/B57hQzF+nE5LMBj2KQd5U/gmsXvMbvfo1lAZYC/Ga VyQNfEjsWIkXbDvvzjJsgcVQagV1kVu4Qz1Py8be9txZV3jZjXBOQRrs/Oi/UMnOQ9d/fek8zqLwW enFaOQX51Vi6XX7v8E4Cvi/lHJuDnWXIVqaycv2ZmM2HmSmtXpPvrZeyQRaAusU1PRpeUCCbaksTC DtI5kkjA==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lYq7V-00C7ts-2r for linux-arm-kernel@lists.infradead.org; Tue, 20 Apr 2021 13:08:50 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 50B6514BF; Tue, 20 Apr 2021 06:08:47 -0700 (PDT) Received: from yoan-MS-7758.Home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EA5FB3F792; Tue, 20 Apr 2021 06:08:45 -0700 (PDT) From: Yoan Picchi To: maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: catalin.marinas@arm.com, will@kernel.org, Yoan Picchi Subject: [PATCH v2 2/3] KVM: arm64: Add two page mapping counters for kvm_stat Date: Tue, 20 Apr 2021 14:08:24 +0100 Message-Id: <20210420130825.15585-3-yoan.picchi@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210420130825.15585-1-yoan.picchi@arm.com> References: <20210420130825.15585-1-yoan.picchi@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210420_060849_241413_9694FD7B X-CRM114-Status: GOOD ( 21.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This patch adds regular_page_mapped and huge_page_mapped. regular_page_mapped is increased when a page of the smallest granularity is mapped. This is usually a 4k, 16k or 64k page. huge_page_mapped is increased when a huge page of any size other than the smallest granularity is mapped. Those counters only count pages allocated for the data and doesn't count the pages/blocks allocated to the page tables as I don't see where those might be needed to be recorded I can see two usecases for those counters : We can detect memory pressure in the host when the guest gets regular pages instead of huge ones. May help detecting an abnormal memory usage like some recurring allocs past the kernel and a few program starts. With the previous patch about stage2_abort_exit, it have the added benefit of specifying the second main cause of stage 2 page fault (the other being mmio access) To test this patch I did start a guest VM and monitor the page allocation. By default it only allocate huge pages. Then I tried to disable the huge pages with : echo never > /sys/kernel/mm/transparent_hugepage/enabled Starting the VM, it no longer allocate any huge page, but only regular pages. I can't log into the guess because it doesn't recognize my keyboard. To circumvent that I added some command to the init script that need some memory : cat /dev/zero | head -c 1000m | tail This take 1GiB of memory before finishing. From memory, it allocate 525 or so huge table which is around what I would expect with 2MB pages. I did check the relation between stage 2 exits, mmio exits and allocation. The mmio + allocation account for almost all the stage 2 exit as expected. There was only about 20 exits that was neither a mmio or an alloc during the kernel boot. I did not look what they are, but it can be a memory permission relaxation, or resizing a page. My main concern here is about the case where we replace a page/block by another/resize a block. I don't fully understand the mechanism yet and so don't know if it should be counted as an allocation or not. For now I don't account it. Signed-off-by: Yoan Picchi --- arch/arm64/include/asm/kvm_host.h | 2 ++ arch/arm64/kvm/guest.c | 2 ++ arch/arm64/kvm/hyp/pgtable.c | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 02891ce94..8f9d27571 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -547,6 +547,8 @@ static inline bool __vcpu_write_sys_reg_to_cpu(u64 val, int reg) struct kvm_vm_stat { ulong remote_tlb_flush; + ulong regular_page_mapped; + ulong huge_page_mapped; }; struct kvm_vcpu_stat { diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index 82a4b6275..41316b30e 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -42,6 +42,8 @@ struct kvm_stats_debugfs_item debugfs_entries[] = { VCPU_STAT("exits", exits), VCPU_STAT("halt_poll_success_ns", halt_poll_success_ns), VCPU_STAT("halt_poll_fail_ns", halt_poll_fail_ns), + VM_STAT("regular_page_mapped", regular_page_mapped), + VM_STAT("huge_page_mapped", huge_page_mapped), { NULL } }; diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 4d177ce1d..2aba2b636 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -498,6 +498,11 @@ static int stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level, smp_store_release(ptep, new); get_page(page); data->phys += granule; + if (level == KVM_PGTABLE_MAX_LEVELS - 1) + data->mmu->kvm->stat.regular_page_mapped++; + else + data->mmu->kvm->stat.huge_page_mapped++; + return 0; } -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel