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=-3.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,SPF_HELO_NONE, SPF_PASS 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 1B3AEC34056 for ; Wed, 19 Feb 2020 17:04:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C695A24656 for ; Wed, 19 Feb 2020 17:03:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mkrENFfz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C695A24656 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 45E346B0003; Wed, 19 Feb 2020 12:03:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 40D316B0006; Wed, 19 Feb 2020 12:03:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FB7D6B0007; Wed, 19 Feb 2020 12:03:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0170.hostedemail.com [216.40.44.170]) by kanga.kvack.org (Postfix) with ESMTP id 189F56B0003 for ; Wed, 19 Feb 2020 12:03:59 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A387C181AC9CC for ; Wed, 19 Feb 2020 17:03:58 +0000 (UTC) X-FDA: 76507498956.08.brush91_66454551b5636 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 90259181A17AE for ; Wed, 19 Feb 2020 17:01:43 +0000 (UTC) X-HE-Tag: brush91_66454551b5636 X-Filterd-Recvd-Size: 7031 Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Wed, 19 Feb 2020 17:01:42 +0000 (UTC) Received: by mail-ed1-f68.google.com with SMTP id c26so29986575eds.8 for ; Wed, 19 Feb 2020 09:01:42 -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=PjDqYM5WgCtLmWgEiNTMLE2lKEuKKGiGdDMhNeMpRhE=; b=mkrENFfzu+iyPIEOlJwHVA2dipdVpLEX9dIILKnnFzTQ+WWaIgIWHR7DzSxgL+TRU2 XiePxFR9+Ur8T6Ccs7iCnLrr7cmEBuKZ4RJOv8BinUtqpciLSCTLIs3LkHzPNz1uE8qg 2NDL+QvKyqe/jTwqgAECeBRRkYeIPYpjV/gX0CSIp3Q/A4vGP5Hn7qWwmTVSlRbpTDCq Uh89Vy72HydVIMz2wAUzw9TXetRYL3cc8a4/kPccho4vldpnZu1m2PLGpwzRU44jxv4O jy2JbCjs394Nk/pVo3pN7WgB8HC5OC2wyGA4f39ySyTo0wZ9+ohalJn12RvBmldaS8l6 Qqfg== 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=PjDqYM5WgCtLmWgEiNTMLE2lKEuKKGiGdDMhNeMpRhE=; b=j5DYMJF/5A30mhPj8D/6RgT90REZz4YXhoTw9Po+qJrg3OfoUNlUD32sSFfKypjstb JnwP0dZDu7qQopfkKR+lp9155msNrca+akJjoiKgdNEn59JvYPgsGWHH+uuu+OpCiMWS r/dmGww/+ymmzIaBo1ERCjoNuHPiM2IepXp7pKjW3KEG4JgmnUN8BbNdaLnIVvHTv5T1 GFkZC5BL8Vzp1UGhnOK1Y5p+txujBRjwSTR8MFtq4AUdvCuf3jHxh3Ow7YbJBwcyClRu s0iyADuSPBquWpyQEqh9x4uHS+dfRSn9oBcLxD5l5t26oCdI06QbjW287AKS0LS/TGuZ 1Bng== X-Gm-Message-State: APjAAAXeR4Anzo39TeqCL+7BVoTronojpyAtzkA5nXvz88mnfolr/iJI OeGmauY6Sg9v9NACwZz07MzIIu2iSIk1OFGT9Vs= X-Google-Smtp-Source: APXvYqx0uS9pXsx1qNwx4zusRcDSVbfDuUNqQtoiMFHg8v3FhP1ktVsFXdm6iCq5gvhRYOn1fEOVTrBxLFKYOadOfC0= X-Received: by 2002:a05:6402:17aa:: with SMTP id j10mr23067482edy.256.1582131701248; Wed, 19 Feb 2020 09:01:41 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Yang Shi Date: Wed, 19 Feb 2020 09:01:23 -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 7:44 PM David Rientjes wrote: > > On Tue, 18 Feb 2020, Yang Shi wrote: > > > > 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. > > > > I think we can choose to either include file allocations into both > thp_fault_alloc and thp_fault_fallback or we can exclude them from both of > them. I don't think we can account for only one of them. How's about the 3rd option, adding THP_FILE_FALLBACK. According to the past discussion with Hugh and Kirill, basically shmem/file THP is treated differently and separately from anonymous THP, and they have separate enabling knobs (/sys/kernel/mm/transparent_hugepage/enabled just enables anonymous THP). Since we already have THP_FILE_ALLOC for shmem THP allocation, IMHO it makes more sense to have dedicated FALLBACK counter. And, this won't change the old behavior either. > > > > > > > spin_lock_irq(&info->lock); > > > info->alloced += compound_nr(page); > > > > >