From patchwork Mon May 21 03:48:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: TSUKADA Koutaro X-Patchwork-Id: 10413807 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3069B600CC for ; Mon, 21 May 2018 03:48:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 148F72842A for ; Mon, 21 May 2018 03:48:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0456F28446; Mon, 21 May 2018 03:48:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E111C2842A for ; Mon, 21 May 2018 03:48:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27A386B0003; Sun, 20 May 2018 23:48:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 22A066B0005; Sun, 20 May 2018 23:48:26 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 141976B0006; Sun, 20 May 2018 23:48:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f72.google.com (mail-pg0-f72.google.com [74.125.83.72]) by kanga.kvack.org (Postfix) with ESMTP id C8B766B0003 for ; Sun, 20 May 2018 23:48:25 -0400 (EDT) Received: by mail-pg0-f72.google.com with SMTP id s17-v6so3869500pgq.23 for ; Sun, 20 May 2018 20:48:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:to:cc :references:from:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=dOqK9foco5vz0ILz6N0S3E9MGHhcrs5gfwsu2OD18nw=; b=abSSkR1aGm2waQpnP0F6F4FGuTY1EOFleFU1111tiBOBwHb2o2sk/VKX30nsNzjkeo mf2bC4HeMqPl0e1+yiVtAqhku6g+rnUon/eCFFsQympqV03Us3R11J08R7f1gHsQVVAp 9YjrWM0hSUUZPm0DCb+b5auf9paP6rU++c8KR6Y52oWUEfyRnpC3irOGPBHPKzZcXmAw sMc6Ujqg+l1NKfeIc6xuWVt4q0gcKZOsgxZmdvocQYz2D2EdIkCtY56RQcNrcI8804kh 9c/A4GKnR0id0Ys1Ep3Hu735NWj0Q+4K+RTiFrYNifX7+jSofvobpUaMQ5c/+YSz/swK /Glg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of tsukada@ascade.co.jp designates 218.224.228.194 as permitted sender) smtp.mailfrom=tsukada@ascade.co.jp X-Gm-Message-State: ALKqPwdMdw43aEViuB4Wq8mha3xa1n0noQcUu3cHXnO0szvVGbqJMEgd o/gz6ewSVAVr1bE9rITccNx3mcD0jdzfWpcAKQ+NqXgBLWdZUsKKUtgwvzEXzqyLbUChX4KPSgV L7AusTwghe5qkNiMipeHPpoD5qrcMKN3ghUv07LkmpUZL9feE4XnPkZxzVLMDfzd1nQ== X-Received: by 2002:a17:902:9048:: with SMTP id w8-v6mr18727506plz.34.1526874505492; Sun, 20 May 2018 20:48:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqS7zJsEBSll3lP/WxL7KsK6tI5kFdoLAiJ8ouG97OLVBQof7aemFONbdd+IBXC8pdHvzcV X-Received: by 2002:a17:902:9048:: with SMTP id w8-v6mr18727472plz.34.1526874504548; Sun, 20 May 2018 20:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526874504; cv=none; d=google.com; s=arc-20160816; b=bQ+3t5jit2nZZJDoOPgVc354V60ZoJvY+wHfipbfpfDm3ztvgWhTGVEIjtSL1rk35D 0Il+Yuku59N9iR4Nwea19DYPpuaXYLg4TtN0IYMu38PzaXCq4LosB/ZXq43Qe/WV1DIT /6siK0k0V/NPvrh4FrC09dhrayr3l7xQiBLA7sG2U8zqTK8eCoNpILjdBWiqE7Jkk2ee oJ3a0GWk2p+/Z2srNtqubG9G9CdOLrXhoc83EjOmt0m9PA5hf40upXnf6/3If8n1wbFT 2A3KFyPmAeC4XLxsWF1RspYHFFHQ0AbOoXRbe1RwVkwcwympmhiIlLW7ZgHwCnj7yAf5 2JhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject :arc-authentication-results; bh=dOqK9foco5vz0ILz6N0S3E9MGHhcrs5gfwsu2OD18nw=; b=i+H1U1iCzq5o+LX4izFn8eQ1zUZ/IsjuV1+XmxTHA5KBE43hP4VEbdpJ1swv88MZhd qxMiod50lOHrYO/qq9Zc+29MykYiILV9a+VCCcafz9YVR2y12B5fs6YsecLenhGIDS8p Wi8CZYHbRpM2Dxe5hI4YSJqLTT2lbNZD9Dt7c/YXhf+BZaqXYaRrUaI3AdtqpavoJ0tW K2e3RM7Q6hVrKTMUr5lk+5HIuQRwb1YmNLg30XasnJihAQIu2TxIPFijv20+c2Qy7eod zqAbz2E/uTwdWC9+7HTfnHwErXVytgGd6n5DuTr7ro1pCkyMndPxmRgSqlz5s+MzRICp kF6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of tsukada@ascade.co.jp designates 218.224.228.194 as permitted sender) smtp.mailfrom=tsukada@ascade.co.jp Received: from ns.ascade.co.jp (ext-host0001.ascade.co.jp. [218.224.228.194]) by mx.google.com with ESMTP id g1-v6si13044739pld.11.2018.05.20.20.48.24 for ; Sun, 20 May 2018 20:48:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of tsukada@ascade.co.jp designates 218.224.228.194 as permitted sender) client-ip=218.224.228.194; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of tsukada@ascade.co.jp designates 218.224.228.194 as permitted sender) smtp.mailfrom=tsukada@ascade.co.jp Received: from server0001.ascade.co.jp (server0001.ascade.co.jp [10.1.1.63]) by ns.ascade.co.jp (Postfix) with ESMTP id 3C31D993BD; Mon, 21 May 2018 12:48:23 +0900 (JST) Received: from [127.0.0.1] (dh176.ascade.co.jp [10.1.1.176]) by server0001.ascade.co.jp (Postfix) with ESMTP id 37558100512; Mon, 21 May 2018 12:48:23 +0900 (JST) Subject: Re: [PATCH v2 3/7] memcg: use compound_order rather than hpage_nr_pages To: Punit Agrawal Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Jonathan Corbet , "Luis R. Rodriguez" , Kees Cook , Andrew Morton , Roman Gushchin , David Rientjes , Mike Kravetz , "Aneesh Kumar K.V" , Naoya Horiguchi , Anshuman Khandual , Marc-Andre Lureau , Dan Williams , Vlastimil Babka , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org References: <262267fe-d98c-0b25-9013-3dafb52e8679@ascade.co.jp> <87wow0zwja.fsf@e105922-lin.cambridge.arm.com> <87sh6ozwc4.fsf@e105922-lin.cambridge.arm.com> From: TSUKADA Koutaro Message-ID: <2053ac36-74df-b05e-d1ce-36f69dde2a47@ascade.co.jp> Date: Mon, 21 May 2018 12:48:22 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <87sh6ozwc4.fsf@e105922-lin.cambridge.arm.com> Content-Language: en-US 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: X-Virus-Scanned: ClamAV using ClamSMTP On 2018/05/19 2:51, Punit Agrawal wrote: > Punit Agrawal writes: > >> Tsukada-san, >> >> I am not familiar with memcg so can't comment about whether the patchset >> is the right way to solve the problem outlined in the cover letter but >> had a couple of comments about this patch. >> >> TSUKADA Koutaro writes: >> >>> The current memcg implementation assumes that the compound page is THP. >>> In order to be able to charge surplus hugepage, we use compound_order. >>> >>> Signed-off-by: TSUKADA Koutaro >> >> Please move this before Patch 1/7. This is to prevent wrong accounting >> of pages to memcg for size != PMD_SIZE. > > I just noticed that the default state is off so the change isn't enabled > until the sysfs node is exposed in the next patch. Please ignore this > comment. > > One below still applies. > >> >>> --- >>> memcontrol.c | 10 +++++----- >>> 1 file changed, 5 insertions(+), 5 deletions(-) >>> >>> diff --git a/mm/memcontrol.c b/mm/memcontrol.c >>> index 2bd3df3..a8f1ff8 100644 >>> --- a/mm/memcontrol.c >>> +++ b/mm/memcontrol.c >>> @@ -4483,7 +4483,7 @@ static int mem_cgroup_move_account(struct page *page, >>> struct mem_cgroup *to) >>> { >>> unsigned long flags; >>> - unsigned int nr_pages = compound ? hpage_nr_pages(page) : 1; >>> + unsigned int nr_pages = compound ? (1 << compound_order(page)) : 1; >> >> Instead of replacing calls to hpage_nr_pages(), is it possible to modify >> it to do the calculation? Thank you for review my code and please just call me Tsukada. I think it is possible to modify the inside of itself rather than replacing the call to hpage_nr_pages(). Inferring from the processing that hpage_nr_pages() desires, I thought that the definition of hpage_nr_pages() could be moved outside the CONFIG_TRANSPARENT_HUGEPAGE. It seems that THP and HugeTLBfs can be handled correctly because compound_order() is judged by seeing whether it is PageHead or not. Also, I would like to use compound_order() inside hpage_nr_pages(), but since huge_mm.h is included before mm.h where compound_order() is defined, move hpage_nr_pages to mm.h. Instead of patch 3/7, are the following patches implementing what you intended? diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index a8a1262..1186ab7 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -204,12 +204,6 @@ static inline spinlock_t *pud_trans_huge_lock(pud_t *pud, else return NULL; } -static inline int hpage_nr_pages(struct page *page) -{ - if (unlikely(PageTransHuge(page))) - return HPAGE_PMD_NR; - return 1; -} struct page *follow_devmap_pmd(struct vm_area_struct *vma, unsigned long addr, pmd_t *pmd, int flags); @@ -254,8 +248,6 @@ static inline bool thp_migration_supported(void) #define HPAGE_PUD_MASK ({ BUILD_BUG(); 0; }) #define HPAGE_PUD_SIZE ({ BUILD_BUG(); 0; }) -#define hpage_nr_pages(x) 1 - static inline bool transparent_hugepage_enabled(struct vm_area_struct *vma) { return false; diff --git a/include/linux/mm.h b/include/linux/mm.h index 1ac1f06..082f2ee 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -673,6 +673,12 @@ static inline unsigned int compound_order(struct page *page) return page[1].compound_order; } +static inline int hpage_nr_pages(struct page *page) +{ + VM_BUG_ON_PAGE(PageTail(page), page); + return (1 << compound_order(page)); +} + static inline void set_compound_order(struct page *page, unsigned int order) { page[1].compound_order = order;