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 X-Spam-Level: X-Spam-Status: No, score=-2.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no 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 4C72BCA9EBB for ; Thu, 24 Oct 2019 13:55:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1253321655 for ; Thu, 24 Oct 2019 13:55:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="N6vNRt71" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1253321655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A30176B0003; Thu, 24 Oct 2019 09:55:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DFFE6B0005; Thu, 24 Oct 2019 09:55:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F5F26B0007; Thu, 24 Oct 2019 09:55:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0123.hostedemail.com [216.40.44.123]) by kanga.kvack.org (Postfix) with ESMTP id 6F1306B0003 for ; Thu, 24 Oct 2019 09:55:57 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id B7CF88141 for ; Thu, 24 Oct 2019 13:55:56 +0000 (UTC) X-FDA: 76078826712.06.books48_33d7fe1e6984a X-HE-Tag: books48_33d7fe1e6984a X-Filterd-Recvd-Size: 4118 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Oct 2019 13:55:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=kg4p9QmhdYnEgh5fEIpCK0L9e+qEFrZicmEw63GMdL4=; b=N6vNRt713Eoqm74U78+NNGSdn Ca5QDmEc0clEfBPYdPqUqLA/TFXSOfH0EUVQQMLN9RE6Cda7w+xR5hOmrB8BQ1xpsys6G6mydq2RY SBIRFhAWG1MmBtv8JPiuxCVKNWEWL3IC77HhcOnD/reExSF7qr3aOw5P7I2OHGfUALECXl0+c9K4K aA6+Z1QFehO7Ng/YR55OIHKDvPsXeGQ1QbcDZXqc//4SWbkjFslRgbpkX5NFAFS95UsSfxPhKoroe O13CVMb0FKJ5EK1CcwogvlT/ZwY+SRXoBEPHIkbzvxdnU4EDnhvBUN73MN/OXoVYnJeMdNEF2DAiO 6n3r8rgdw==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1iNdad-0005C2-Dp; Thu, 24 Oct 2019 13:55:47 +0000 Date: Thu, 24 Oct 2019 06:55:47 -0700 From: Matthew Wilcox To: Yang Shi Cc: hughd@google.com, aarcange@redhat.com, kirill.shutemov@linux.intel.com, gavin.dg@linux.alibaba.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [v4 PATCH] mm: thp: handle page cache THP correctly in PageTransCompoundMap Message-ID: <20191024135547.GH2963@bombadil.infradead.org> References: <1571865575-42913-1-git-send-email-yang.shi@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1571865575-42913-1-git-send-email-yang.shi@linux.alibaba.com> User-Agent: Mutt/1.12.1 (2019-06-15) 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 Thu, Oct 24, 2019 at 05:19:35AM +0800, Yang Shi wrote: > We have usecase to use tmpfs as QEMU memory backend and we would like to > take the advantage of THP as well. But, our test shows the EPT is not > PMD mapped even though the underlying THP are PMD mapped on host. > The number showed by /sys/kernel/debug/kvm/largepage is much less than > the number of PMD mapped shmem pages as the below: > > 7f2778200000-7f2878200000 rw-s 00000000 00:14 262232 /dev/shm/qemu_back_mem.mem.Hz2hSf (deleted) > Size: 4194304 kB > [snip] > AnonHugePages: 0 kB > ShmemPmdMapped: 579584 kB > [snip] > Locked: 0 kB > > cat /sys/kernel/debug/kvm/largepages > 12 > > And some benchmarks do worse than with anonymous THPs. > > By digging into the code we figured out that commit 127393fbe597 ("mm: > thp: kvm: fix memory corruption in KVM with THP enabled") checks if > there is a single PTE mapping on the page for anonymous THP when > setting up EPT map. But, the _mapcount < 0 check doesn't fit to page > cache THP since every subpage of page cache THP would get _mapcount > inc'ed once it is PMD mapped, so PageTransCompoundMap() always returns > false for page cache THP. This would prevent KVM from setting up PMD > mapped EPT entry. > > So we need handle page cache THP correctly. However, when page cache > THP's PMD gets split, kernel just remove the map instead of setting up > PTE map like what anonymous THP does. Before KVM calls get_user_pages() > the subpages may get PTE mapped even though it is still a THP since the > page cache THP may be mapped by other processes at the mean time. > > Checking its _mapcount and whether the THP has PTE mapped or not. > Although this may report some false negative cases (PTE mapped by other > processes), it looks not trivial to make this accurate. I don't understand why you care how it's mapped into userspace. If there is a PMD-sized page in the page cache, then you can use a PMD mapping in the EPT tables to map it. Why would another process having a PTE mapping on the page cause you to not use a PMD mapping?