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=-5.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 19D45CA9EBC for ; Fri, 25 Oct 2019 15:27:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C06FE20679 for ; Fri, 25 Oct 2019 15:27:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="UjpzsMme" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C06FE20679 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5190E6B0005; Fri, 25 Oct 2019 11:27:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C96A6B0006; Fri, 25 Oct 2019 11:27:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B7AD6B0007; Fri, 25 Oct 2019 11:27:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0158.hostedemail.com [216.40.44.158]) by kanga.kvack.org (Postfix) with ESMTP id 15C5C6B0005 for ; Fri, 25 Oct 2019 11:27:58 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id B6E4E82499A8 for ; Fri, 25 Oct 2019 15:27:57 +0000 (UTC) X-FDA: 76082687394.08.thumb45_2851089ebd049 X-HE-Tag: thumb45_2851089ebd049 X-Filterd-Recvd-Size: 6201 Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Fri, 25 Oct 2019 15:27:56 +0000 (UTC) Received: by mail-lf1-f68.google.com with SMTP id f5so2113907lfp.1 for ; Fri, 25 Oct 2019 08:27:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=p1Hpmsd781iQPQDBjQH17bW2u73+OuLAp5jOLLAjrpU=; b=UjpzsMmefP9GXBLnHTmzYQaImtlmjwNNXQBPcTENIshdDReqiRpsXTajTZ5+KU5WOr sMORwXoI9mw57B1wzSdN9dDcXPRDeKZ2E/Cwj26oupxnaWLqtZ8gjpoW3CvuTVuQQu7U UipzSYuGz4Htd+a0tUdJRH9nHwoBEfud7JY0wppGc/BIWMzXb1hwTtXy7G8R117Yr4aF a789TgwI+45jxxaL8wR5yp/78EU06i3pcebfatjq4+2dwfY/Wgijw8bLrDn9vASP4YBa Cz+a6j1fBxpDKKljotXQqF5dP4xcCJI2v4IvM7v3awR5zJflIA/ZGIPKa32z+Q7QVf+s PeWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=p1Hpmsd781iQPQDBjQH17bW2u73+OuLAp5jOLLAjrpU=; b=chhMhQNuA7Ua/4ECZvhbQ/0GbahdNXpmEHenyPKnNFqQ8ORMPWFPrj2lYpFcfT/5+m k9LVpVI6MlrzknYf6DGa9DwBwlsftmuBUFQE5dTAL21PReqiGgIc5ZxUs6KPtuqMfbrn ZaTEAB9uhrDnlSNFvQ7owdd/ik+mMQlUGFgE3lnivSvhpXpKBaX8HNwy4Fgx5RW9sKB8 hC/5vWvSCBm54yq7qVyqpfNWZQ0TZ0xuQdfF6h3PaDJoNnS4e5JyvkHXAKnYxf7EytP/ SDPUvHFK4FRd7CWgEONqI/5/5RUJ9NcgxjKUnvEccIKzvwR9y2HKMsnoBNReKJkrud81 OTrQ== X-Gm-Message-State: APjAAAXAyz03AOlob/6kzs3BemdFpiHg+BFJLSYe7es9azHTuEnG/i2R e2vc05m0X0vlXrixqul9WUS2zw== X-Google-Smtp-Source: APXvYqx8ut170aduTcnwpN2s58bh8CtaxjaBrLwb48WkUcqiuDYotYDlIZtCagLNprtwWMYn8tqYbQ== X-Received: by 2002:a19:c6d6:: with SMTP id w205mr2917433lff.17.1572017275214; Fri, 25 Oct 2019 08:27:55 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id c21sm1020556lfh.33.2019.10.25.08.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 08:27:54 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id D8B1010267F; Fri, 25 Oct 2019 18:27:53 +0300 (+03) Date: Fri, 25 Oct 2019 18:27:53 +0300 From: "Kirill A. Shutemov" To: Yang Shi Cc: hughd@google.com, aarcange@redhat.com, kirill.shutemov@linux.intel.com, willy@infradead.org, 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: <20191025152753.qdob7tpdnnzlje6k@box> 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: NeoMutt/20180716 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. > > With this fix /sys/kernel/debug/kvm/largepage would show reasonable > pages are PMD mapped by EPT as the below: > > 7fbeaee00000-7fbfaee00000 rw-s 00000000 00:14 275464 /dev/shm/qemu_back_mem.mem.SKUvat (deleted) > Size: 4194304 kB > [snip] > AnonHugePages: 0 kB > ShmemPmdMapped: 557056 kB > [snip] > Locked: 0 kB > > cat /sys/kernel/debug/kvm/largepages > 271 > > And the benchmarks are as same as anonymous THPs. > > Fixes: dd78fedde4b9 ("rmap: support file thp") > Signed-off-by: Yang Shi > Reported-by: Gang Deng > Tested-by: Gang Deng > Suggested-by: Hugh Dickins > Cc: Andrea Arcangeli > Cc: Kirill A. Shutemov > Cc: Matthew Wilcox > Cc: 4.8+ Looks good to me. Acked-by: Kirill A. Shutemov -- Kirill A. Shutemov