From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 781E9C282E7 for ; Mon, 15 Aug 2022 13:09:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C009E6B0073; Mon, 15 Aug 2022 09:09:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BAFB86B0074; Mon, 15 Aug 2022 09:09:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A780F8D0002; Mon, 15 Aug 2022 09:09:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 983306B0073 for ; Mon, 15 Aug 2022 09:09:11 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 27BAB120EAA for ; Mon, 15 Aug 2022 13:09:11 +0000 (UTC) X-FDA: 79801857702.20.F39882A Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf19.hostedemail.com (Postfix) with ESMTP id 886181A018D for ; Mon, 15 Aug 2022 13:09:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660568949; x=1692104949; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=uC6wcjTIjKWZdEEUC6nc6q/QLuQ42xa9S3mFqSAWmAc=; b=NyLXfs7rCL5LySh/CciWbJYOB0yN3QYhzn8ncDsE+dQFk7BhJ5+cc1uq z4aggTPLXsbdwaVF/WxkDgBlf1F588V4GmucUHEvwk8hXH1s9foVG0QBs HGkVV9QZtvzX3tV6eHp5VLW/HwYD8nKr6aKYMtjkEOrKwH2Kbcwr529Hd xm98NQA4QABmsCIse7qM5W92+lGgiiyQMgq2nC9zvin+HYoEDwxzP1xCp ykzsmJT5LwliwNlSCDUFZLFTvVuKXZs8nj7za9au41PjUsWcaJ9Rn/38a uA731CKAAlr2cNXguadfBq7pVA9OGHapjOzDIww34vzbRdg59vYaxlkpo A==; X-IronPort-AV: E=McAfee;i="6400,9594,10440"; a="378241138" X-IronPort-AV: E=Sophos;i="5.93,238,1654585200"; d="scan'208";a="378241138" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Aug 2022 06:09:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,238,1654585200"; d="scan'208";a="635470742" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.193.75]) by orsmga008.jf.intel.com with ESMTP; 15 Aug 2022 06:08:56 -0700 Date: Mon, 15 Aug 2022 21:04:11 +0800 From: Chao Peng To: "Nikunj A. Dadhania" Cc: "Gupta, Pankaj" , Sean Christopherson , Paolo Bonzini , Jonathan Corbet , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Shuah Khan , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , Michael Roth , mhocko@suse.com, Muchun Song , bharata@amd.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v7 00/14] KVM: mm: fd-based approach for supporting KVM guest private memory Message-ID: <20220815130411.GA1073443@chaop.bj.intel.com> Reply-To: Chao Peng References: <20220706082016.2603916-1-chao.p.peng@linux.intel.com> <9e86daea-5619-a216-fe02-0562cf14c501@amd.com> <9dc91ce8-4cb6-37e6-4c25-27a72dc11dd0@amd.com> <422b9f97-fdf5-54bf-6c56-3c45eff5e174@amd.com> <1407c70c-0c0b-6955-10bb-d44c5928f2d9@amd.com> <1136925c-2e37-6af4-acac-be8bed9f6ed5@amd.com> <1b02db9d-f2f1-94dd-6f37-59481525abff@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1b02db9d-f2f1-94dd-6f37-59481525abff@amd.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660568949; a=rsa-sha256; cv=none; b=brQJf6luizmdcz3EUkVPwZY0Uamg7L+0g09xcWB2wplZjjD6t1dU5Pt7dIZ+cQ4YbalJDP 8ZDJmTmkfjzo2AR4UBTaZdtKGREFLg/SpmZX1xMuW4K+RfunFSWyKyxTrf5BIiGsGNwVOE ohIxu1yBDCHkrc++u1SIAOCIvKIeR9U= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=NyLXfs7r; spf=none (imf19.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.43) smtp.mailfrom=chao.p.peng@linux.intel.com; dmarc=fail reason="No valid SPF" header.from=intel.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660568949; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7u+uMYJ8ZgjA7MkQbnSRBdFBtglkmzpcgQtiWpAzXkg=; b=pnwlXayexSLKLQIJLP8uxue5DECiGJRVhMRawpQF8QkdQsFRs1YJgQlDudU/MqwkAOtyPE 5f1MY3U7HzFlRclvwLyi12MKL+/2SYNuH7vOQLSf3KIcPxz378+LbhCYB5FyyOCamLO3yT dTecvLv/rg8ulhz8TADNmeA7tSCR7uE= X-Stat-Signature: ufka8zzjrumn5ei9coue56w3gmzpktat X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 886181A018D Authentication-Results: imf19.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=NyLXfs7r; spf=none (imf19.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.43) smtp.mailfrom=chao.p.peng@linux.intel.com; dmarc=fail reason="No valid SPF" header.from=intel.com (policy=none) X-Rspam-User: X-HE-Tag: 1660568949-23176 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Aug 12, 2022 at 02:18:43PM +0530, Nikunj A. Dadhania wrote: > > > On 12/08/22 12:48, Gupta, Pankaj wrote: > > > >>>>>> > >>>>>> However, fallocate() preallocates full guest memory before starting the guest. > >>>>>> With this behaviour guest memory is *not* demand pinned. Is there a way to > >>>>>> prevent fallocate() from reserving full guest memory? > >>>>> > >>>>> Isn't the pinning being handled by the corresponding host memory backend with mmu > notifier and architecture support while doing the memory operations e.g page> migration and swapping/reclaim (not supported currently AFAIU). But yes, we need> to allocate entire guest memory with the new flags MEMFILE_F_{UNMOVABLE, UNRECLAIMABLE etc}. > >>>> > >>>> That is correct, but the question is when does the memory allocated, as these flags are set, > >>>> memory is neither moved nor reclaimed. In current scenario, if I start a 32GB guest, all 32GB is > >>>> allocated. > >>> > >>> I guess so if guest memory is private by default. > >>> > >>> Other option would be to allocate memory as shared by default and > >>> handle on demand allocation and RMPUPDATE with page state change event. But still that would be done at guest boot time, IIUC. > >> > >> Sorry! Don't want to hijack the other thread so replying here. > >> > >> I thought the question is for SEV SNP. For SEV, maybe the hypercall with the page state information can be used to allocate memory as we use it or something like quota based memory allocation (just thinking). > > > > But all this would have considerable performance overhead (if by default memory is shared) and used mostly at boot time. > > > So, preallocating memory (default memory private) seems better approach for both SEV & SEV SNP with later page management (pinning, reclaim) taken care by host memory backend & architecture together. > > I am not sure how will pre-allocating memory help, even if guest would not use full memory it will be pre-allocated. Which if I understand correctly is not expected. Actually the current version allows you to delay the allocation to a later time (e.g. page fault time) if you don't call fallocate() on the private fd. fallocate() is necessary in previous versions because we treat the existense in the fd as 'private' but in this version we track private/shared info in KVM so we don't rely on that fact from memory backstores. Definitely the page will still be pinned once it's allocated, there is no way to swap it out for example just with the current code. That kind of support, if desirable, can be extended through MOVABLE flag and some other callbacks to let feature-specific code to involve. Chao > > Regards > Nikunj