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=-6.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS 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 1E45CC34022 for ; Wed, 19 Feb 2020 03:22:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C326024658 for ; Wed, 19 Feb 2020 03:22:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eSd7Al7O" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C326024658 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 719F46B0008; Tue, 18 Feb 2020 22:22:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CB0B6B000A; Tue, 18 Feb 2020 22:22:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 607706B000C; Tue, 18 Feb 2020 22:22:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0113.hostedemail.com [216.40.44.113]) by kanga.kvack.org (Postfix) with ESMTP id 4942B6B0008 for ; Tue, 18 Feb 2020 22:22:35 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C4E1E8248047 for ; Wed, 19 Feb 2020 03:22:34 +0000 (UTC) X-FDA: 76505429028.22.knee47_50a94672b080a X-HE-Tag: knee47_50a94672b080a X-Filterd-Recvd-Size: 6385 Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Wed, 19 Feb 2020 03:22:34 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id t7so15749687edr.4 for ; Tue, 18 Feb 2020 19:22:34 -0800 (PST) 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=mOwsfCxIuEAE5EfWzjTqJ5OG19WWGU0wtmPirueEhaU=; b=eSd7Al7OY+mz5Or3VCm94r/VJDi1/bdRrhb9Ior3AMIH15vekk9WuEMIusd4zqBes5 Ntpj53PgI/pKghFIQWbSVCEz2D+DuJSIFFryKUtFft133BNTw3XCqOJs2vcM24tXZC6p qV5O/UsBAxe0uidFndVqxdqOdu6aOn2zCHOciFcQT1ZlT+gj4X0qe+wlR0IVIEBkQBkW kKDGqcTRPcjqA/PmZs18SGduB1UMRGZmw4CGAAuRQDvv1kPAWyUD0bsbSE/yYGsxcS4q vVHspuASnEQYPUC1OrN0gCMRSmkAKy0yqd6u9L1ZQ3FL6O57Na+9hDemklOQWRDXkICx N0Aw== 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=mOwsfCxIuEAE5EfWzjTqJ5OG19WWGU0wtmPirueEhaU=; b=MuTkJjJWXiEdXuFgBIIagOWsWTOG1XRpdZDNKBm8o2szzg2Qq6lDleX4cosH8T/FgE 9C54mKYqxzTBYhQUVB+frC9Cpu43k9DjaWP5YG2/bdu4lstQy4RdRteVEzEyVzK40JYT jvXMq9xE2TlOKlclF3++L8mn6XcrINRbHUnT9uSUn0EpqT43alWYN2ICKzuR8WafGDoE mh0WhghEG/eetBY7bc9ZKI5K/bbCAejUCiVBNWoJbQWg3KmOJLsyf3BomN2ew7xCo1Bi ioq1BB+zhNVAULLPNxS/8lY22/RVQQtqp5UTRcTx7Ngk+knTDmRG1epF5Rb8VVPr91GT mSvA== X-Gm-Message-State: APjAAAXK+Xt9NIuoHoIlYaoIXFfEPsxphzdHddCvqLkWv034qnYZrlx7 TttCmmRfRTWqD9oZLkvRYZ4FUPb0Xu1tUINaAog= X-Google-Smtp-Source: APXvYqzwIb1FUBaecbUsJa4vYm6bhf8m9qyf9cN1RF7nJCD/1BOnd7Jb98IDNKDk4iocVSXjGHIlPjoZ9TBqh9WZA1A= X-Received: by 2002:a05:6402:c0f:: with SMTP id co15mr21926223edb.200.1582082553048; Tue, 18 Feb 2020 19:22:33 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Yang Shi Date: Tue, 18 Feb 2020 19:22:16 -0800 Message-ID: Subject: Re: [patch 1/2] mm, shmem: add thp fault alloc and fallback stats To: David Rientjes Cc: Andrew Morton , "Kirill A. Shutemov" , Mike Rapoport , Jeremy Cline , Linux Kernel Mailing List , Linux MM Content-Type: text/plain; charset="UTF-8" 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 Tue, Feb 18, 2020 at 6:29 PM David Rientjes wrote: > > The thp_fault_alloc and thp_fault_fallback vmstats are incremented when a > hugepage is successfully or unsuccessfully allocated, respectively, during > a page fault for anonymous memory. > > Extend this to shmem as well. Note that care is taken to increment > thp_fault_alloc only when the fault succeeds; this is the same behavior as > anonymous thp. > > Signed-off-by: David Rientjes > --- > mm/shmem.c | 23 ++++++++++++++--------- > 1 file changed, 14 insertions(+), 9 deletions(-) > > diff --git a/mm/shmem.c b/mm/shmem.c > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -1502,9 +1502,8 @@ static struct page *shmem_alloc_page(gfp_t gfp, > return page; > } > > -static struct page *shmem_alloc_and_acct_page(gfp_t gfp, > - struct inode *inode, > - pgoff_t index, bool huge) > +static struct page *shmem_alloc_and_acct_page(gfp_t gfp, struct inode *inode, > + pgoff_t index, bool fault, bool huge) > { > struct shmem_inode_info *info = SHMEM_I(inode); > struct page *page; > @@ -1518,9 +1517,11 @@ static struct page *shmem_alloc_and_acct_page(gfp_t gfp, > if (!shmem_inode_acct_block(inode, nr)) > goto failed; > > - if (huge) > + if (huge) { > page = shmem_alloc_hugepage(gfp, info, index); > - else > + if (!page && fault) > + count_vm_event(THP_FAULT_FALLBACK); > + } else > page = shmem_alloc_page(gfp, info, index); > if (page) { > __SetPageLocked(page); > @@ -1832,11 +1833,10 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, > } > > alloc_huge: > - page = shmem_alloc_and_acct_page(gfp, inode, index, true); > + page = shmem_alloc_and_acct_page(gfp, inode, index, vmf, true); > if (IS_ERR(page)) { > alloc_nohuge: > - page = shmem_alloc_and_acct_page(gfp, inode, > - index, false); > + page = shmem_alloc_and_acct_page(gfp, inode, index, vmf, false); > } > if (IS_ERR(page)) { > int retry = 5; > @@ -1871,8 +1871,11 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, > > error = mem_cgroup_try_charge_delay(page, charge_mm, gfp, &memcg, > PageTransHuge(page)); > - if (error) > + if (error) { > + if (vmf && PageTransHuge(page)) > + count_vm_event(THP_FAULT_FALLBACK); > goto unacct; > + } > error = shmem_add_to_page_cache(page, mapping, hindex, > NULL, gfp & GFP_RECLAIM_MASK); > if (error) { > @@ -1883,6 +1886,8 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, > mem_cgroup_commit_charge(page, memcg, false, > PageTransHuge(page)); > lru_cache_add_anon(page); > + if (vmf && PageTransHuge(page)) > + count_vm_event(THP_FAULT_ALLOC); I think shmem THP alloc is accounted to THP_FILE_ALLOC. And it has been accounted by shmem_add_to_page_cache(). So, it sounds like a double count. > > spin_lock_irq(&info->lock); > info->alloced += compound_nr(page); >