Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp7051660ybf; Fri, 6 Mar 2020 09:25:09 -0800 (PST) X-Google-Smtp-Source: ADFU+vunFWNrAtvuxLA23dxgI1UmVf7OSirzZ6PHpbfHAZLMUy/AOSElZHhqmHuT2OXcRCOHkUDJ X-Received: by 2002:a9d:463:: with SMTP id 90mr3518764otc.283.1583515509404; Fri, 06 Mar 2020 09:25:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583515509; cv=none; d=google.com; s=arc-20160816; b=ww+HfsfmiskImB8xfV0aHa9inG+wBb0A0EMrZkEA2Uu2uxwhz7DD0NnsVK0pQ0jhz+ JhkeGwHt9XxqyfY/ELAIoJ0qQhs34FcJPEZCGJs4yS4HQBXOYcOEidt686Es3lDBKOh8 HOs58eh6n3O7M/wouCz2kwvUXbFjha6zf66nUEbMz2j752lh2mIxPzH94Q4Lj4N5P9WN uRek4HAZJ0uHK7/YPOMNnMNexgbMZc6PjfccIi1VWyw3dgyH+5ubWJruzcbvUasx8PJR C46FoLbwiEtSpGwLhSNNMAiBQvvJrP3l27fMJtYlY3MRTm3mUpAE5pOwfgfHdbyIAOvR DRtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=WZVF3WeW7a9wrdSl0zBcs9raA78Uf8UokFbAXMs0MtY=; b=w33TX65XsjgpJb6Eaxtr1VmJtnJ4P51Znz7xkGxxdaTmj+Vzheazyo+nUl3vseTgGg IvXsT83cSD/0zjbfp5aRUkZ3M4TA7EXVF4kqiIP5DvlF2xLJq8PiqWQrsaCHo/LXQISp TAFFHaOe3wYeDrKpb4eWxw+vRtoCUoq9V1LEpHZp4FEHvx0zReXVI8onzv9nVRJVH1sA tfvp+VVujyf8hS1HOgM/Ei0yp3EXRyxPMNzyVdHgoMUDCEJTQmXC0r6ehkAWzJdAaz6h 2vfEezJYHgm7zK9qCM895gVL9M5aet+5iMoO95i06oDxoSbdNotVvfTXDJxNuu1lgzi/ P6iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=g8MbbuGf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b20si17533oic.136.2020.03.06.09.24.57; Fri, 06 Mar 2020 09:25:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=g8MbbuGf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726788AbgCFRYQ (ORCPT + 99 others); Fri, 6 Mar 2020 12:24:16 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:36988 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726185AbgCFRYQ (ORCPT ); Fri, 6 Mar 2020 12:24:16 -0500 Received: by mail-ed1-f65.google.com with SMTP id m9so3406433edl.4 for ; Fri, 06 Mar 2020 09:24:14 -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=WZVF3WeW7a9wrdSl0zBcs9raA78Uf8UokFbAXMs0MtY=; b=g8MbbuGfSPFiXaKugqYxPbsI+w1HDaJneroTSsByaWf9QRcxgtnRqXWjdFLdwGQ+NG AMoljN6kLEhM9XqiFZViwOtz4THPxiF+zMkHIoxAKRJ70yI79J0zpc7iNgLOvZoOwLO3 h8+w9+UBXn5J/ytjOtHGJ8zaLSI38Mv+DEiQiHcWOx4Ew8XHC007awxBQzAEdrX3+kfb qH1oumcl+U4aldZHNfmEJHOoNA6KZhtjrJSuutd+9qjRlnNECX7wb0T0h/fnMnjmFEfB 6usF1E3yTLbc6+Sda0Cq//wYp/ZVg7jMqIWnaejkuO1tNLs5rRONZJ1c1PbpC2sVLA3h 7EDg== 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=WZVF3WeW7a9wrdSl0zBcs9raA78Uf8UokFbAXMs0MtY=; b=MwRBZn4F4TAOzQILsAOcm+4hCHUx4yFkbhNMGhf+E7A7gHrdB6boK7+i/8J7RvFB19 egF7CSwQncEuIpPT+S9qgXPY08/LWhVgdFojLNSYbEUJ1V62v75Rj5isZa+eYf2tpAwb suVx2BdfKkLbWYF74sSu+oSvv3I7dAi4wOHNKOqRdSTVkAkYXvuC5Vqngf0eY6dB0W3M xiIpoTNtuYsPnag6mtR7V/+DIrOrvFnLhlpcG7gG+5AabSylX8+RErGRG6ypZEDhCe8E D/MTCcJjtJrZQfbyHrlloPH/2UqQnBU6Spy6fAQA+Azdc4tzUdiqC2dM6eDZ3es2bl8g dP6Q== X-Gm-Message-State: ANhLgQ3uG6oAiu8PAYtWTgOQ5sCkfhQmB/ykXE39xpZPzvzojaaOQ1fD d5kAjQyzG7YkTdkpPmzGFZMZ5fgBEYscKCVn4Yc= X-Received: by 2002:a17:906:1cc2:: with SMTP id i2mr3962727ejh.283.1583515453642; Fri, 06 Mar 2020 09:24:13 -0800 (PST) MIME-Version: 1.0 References: <20200220131202.i77zt3zj53mimrnu@box> In-Reply-To: <20200220131202.i77zt3zj53mimrnu@box> From: Yang Shi Date: Fri, 6 Mar 2020 09:23:59 -0800 Message-ID: Subject: Re: [patch 1/2] mm, shmem: add thp fault alloc and fallback stats To: "Kirill A. Shutemov" Cc: David Rientjes , Andrew Morton , "Kirill A. Shutemov" , Mike Rapoport , Jeremy Cline , Linux Kernel Mailing List , Linux MM Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 20, 2020 at 5:11 AM Kirill A. Shutemov wrote: > > On Wed, Feb 19, 2020 at 09:01:23AM -0800, Yang Shi wrote: > > 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. > > I like this option. > > Problem with THP_FAULT_* is that shmem_getpage_gfp() is called not only > from fault path, but also from syscalls. I found another usecase for THP_FILE_FALLBACK. I wanted to measure file THP allocation success rate in our uecase. It looks nr_file_alloc / (nr_file_alloc + nr_file_fallback) is the most simple way. David, are you still working on this patch? > > -- > Kirill A. Shutemov