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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 8CAC0C47082 for ; Mon, 7 Jun 2021 18:41:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1A51961108 for ; Mon, 7 Jun 2021 18:41:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A51961108 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 39A5F6B006C; Mon, 7 Jun 2021 14:41:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 34C0C6B006E; Mon, 7 Jun 2021 14:41:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C5346B0070; Mon, 7 Jun 2021 14:41:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0191.hostedemail.com [216.40.44.191]) by kanga.kvack.org (Postfix) with ESMTP id DCF716B006C for ; Mon, 7 Jun 2021 14:41:41 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6EF4682DAEE3 for ; Mon, 7 Jun 2021 18:41:41 +0000 (UTC) X-FDA: 78227796402.38.5A867C0 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by imf01.hostedemail.com (Postfix) with ESMTP id 80D355001533 for ; Mon, 7 Jun 2021 18:41:38 +0000 (UTC) Received: by mail-ed1-f51.google.com with SMTP id dj8so21590895edb.6 for ; Mon, 07 Jun 2021 11:41:40 -0700 (PDT) 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=uH3JX7eLYLyOx1BXQqsWzSMIggN9SNhVfMkmQqWxCNc=; b=ikWnpIie5hZMfnWHLaAlHOf3oFbHhY+zg+SStiWL60r5U+C0O4Ue2By9cpXdtflevA uWT39JDJ19Cm+CO+hACPkQJyJY5t0jPVbHzfaZqjESs07e14KndIApuWEMYzopEuXvzN 0Aml7wOvBPkK8Eq8PyrYVZGn5r0ZsN9mv58nFGPbjC1HZMYobQBZSwBTWxxL7k7r6/YZ Tshq72TGLuXYsLvaJBytxAfSZJASVXMWAHLRxoXzohOSQb6z+V/6/Ob+bZc0CFYJNqkA jyFkgEDete6cM1nyN61V+H/vnGEa+aNDriUXOySLUkbg2DneeT3nhegxTvbCLi+w+QtO 6lPA== 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=uH3JX7eLYLyOx1BXQqsWzSMIggN9SNhVfMkmQqWxCNc=; b=HUTi3sAzftZRQANGW3Wi4RMKAUspagNaGkekJGTVV5BoXmMG0Iw5eHfib49hxoah/l jJOPxRerWBGW83OCp+OecbvyznL1ldJ3hk9M6K/EDEGDMm04miILNenOj5moDVbLzgPJ ctX8Ynf2kq8rDERNo6u8d2keNZ7sIg16vewa9tQpQseaZ9PWAlPMQbLJGj+ZJrmEncm1 BhrYMLVwJDl6xd2PTOjUVSGzzsR01DX5BCn/IEvnZaWXT5zMzrnfCnv71+Bh1HADdemv M712YhqBfAPwpKJeUxk7VFOWES+fVpJDQ2J1hU7tTWI0c2Cx1DfMhqnbG1MZ9mCgdwB+ kkvQ== X-Gm-Message-State: AOAM531Qat7PbSIfdUB/O8MurH82YLc0vgu7/7TO7cAuM6K5aXFJJlxR EMDMLbR7x0Bm/KJsTOaH/+vkTgOGTwG8oGypkTI= X-Google-Smtp-Source: ABdhPJxXXvFSZ4J8Womwhx/S9wH7EqXmcyHijmzrDfdRjsFBFnuDp0KcoJnDN2VODbCoopayt21wrEL7t478AIamAko= X-Received: by 2002:a05:6402:42d2:: with SMTP id i18mr21378919edc.168.1623091299806; Mon, 07 Jun 2021 11:41:39 -0700 (PDT) MIME-Version: 1.0 References: <20210604203513.240709-1-shy828301@gmail.com> In-Reply-To: From: Yang Shi Date: Mon, 7 Jun 2021 11:41:27 -0700 Message-ID: Subject: Re: [PATCH] mm: mempolicy: don't have to split pmd for huge zero page To: Michal Hocko Cc: Zi Yan , nao.horiguchi@gmail.com, "Kirill A. Shutemov" , Hugh Dickins , Andrew Morton , Linux MM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=ikWnpIie; spf=pass (imf01.hostedemail.com: domain of shy828301@gmail.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 80D355001533 X-Stat-Signature: q6oqgyb4e68gr83xthxwjhpkm4oqpka1 X-HE-Tag: 1623091298-33170 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 Mon, Jun 7, 2021 at 10:00 AM Yang Shi wrote: > > On Sun, Jun 6, 2021 at 11:21 PM Michal Hocko wrote: > > > > On Fri 04-06-21 13:35:13, Yang Shi wrote: > > > When trying to migrate pages to obey mempolicy, the huge zero page is > > > split then the page table walk at PTE level just skips zero page. So it > > > seems pointless to split huge zero page, it could be just skipped like > > > base zero page. > > > > My THP knowledge is not the best but this is incorrect AIACS. Huge zero > > page is not split. We do split the pmd which is mapping the said page. I > > suspect you refer to vm_normal_page when talking about a zero page but > > please be aware that huge zero page is not a normal zero page. It is > > allocated dynamically (see get_huge_zero_page). > > For a normal huge page, yes, split_huge_pmd() just splits pmd. But > actually the base zero pfn will be inserted to PTEs when splitting > huge zero pmd. Please check __split_huge_zero_page_pmd() out. > > I should make this point clearer in the commit log. Sorry for the confusion. > > > > > So in the end you patch disables mbind of zero pages to a target node > > and that is a regression. > > Do we really migrate zero page? IIUC zero page is just skipped by > vm_normal_page() check in queue_pages_pte_range(), isn't it? > > > > > Have you tested the patch? > > No, just build test. I thought this change was straightforward. Just came up with a quick test, the test is trying to mbind 1G address space (use huge zero page) to another node, the result is: w/o patch: pgmigrate_success 0 pgmigrate_fail 0 thp_migration_success 0 thp_migration_fail 0 thp_migration_split 0 thp_split_pmd 512 thp_split_pud 0 thp_zero_page_alloc 1 w/ patch: pgmigrate_success 0 pgmigrate_fail 0 thp_migration_success 0 thp_migration_fail 0 thp_migration_split 0 thp_split_pmd 0 thp_split_pud 0 thp_zero_page_alloc 1 We can tell neither huge zero nor base zero was migrated even before the patch. The patch just kills the pointless pmd split and we keep the huge zero page. > > > > > > Set ACTION_CONTINUE to prevent the walk_page_range() split the pmd for > > > this case. > > > > Btw. this changelog is missing a problem statement. I suspect there is > > no actual problem that it should fix and it is likely driven by reading > > the code. Right? > > The actual problem is it is pointless to split a huge zero pmd. Yes, > it is driven by visual inspection. > > The behavior before the patch for huge zero page is: > split huge zero pmd (insert base zero pfn to ptes) > walk ptes > skip zero pfn > > So why not just skip the huge zero page in the first place? > > > > > > Signed-off-by: Yang Shi > > > --- > > > mm/mempolicy.c | 9 +++++---- > > > 1 file changed, 5 insertions(+), 4 deletions(-) > > > > > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c > > > index b5f4f584009b..205c1a768775 100644 > > > --- a/mm/mempolicy.c > > > +++ b/mm/mempolicy.c > > > @@ -436,7 +436,8 @@ static inline bool queue_pages_required(struct page *page, > > > > > > /* > > > * queue_pages_pmd() has four possible return values: > > > - * 0 - pages are placed on the right node or queued successfully. > > > + * 0 - pages are placed on the right node or queued successfully, or > > > + * special page is met, i.e. huge zero page. > > > * 1 - there is unmovable page, and MPOL_MF_MOVE* & MPOL_MF_STRICT were > > > * specified. > > > * 2 - THP was split. > > > @@ -460,8 +461,7 @@ static int queue_pages_pmd(pmd_t *pmd, spinlock_t *ptl, unsigned long addr, > > > page = pmd_page(*pmd); > > > if (is_huge_zero_page(page)) { > > > spin_unlock(ptl); > > > - __split_huge_pmd(walk->vma, pmd, addr, false, NULL); > > > - ret = 2; > > > + walk->action = ACTION_CONTINUE; > > > goto out; > > > } > > > if (!queue_pages_required(page, qp)) > > > @@ -488,7 +488,8 @@ static int queue_pages_pmd(pmd_t *pmd, spinlock_t *ptl, unsigned long addr, > > > * and move them to the pagelist if they do. > > > * > > > * queue_pages_pte_range() has three possible return values: > > > - * 0 - pages are placed on the right node or queued successfully. > > > + * 0 - pages are placed on the right node or queued successfully, or > > > + * special page is met, i.e. zero page. > > > * 1 - there is unmovable page, and MPOL_MF_MOVE* & MPOL_MF_STRICT were > > > * specified. > > > * -EIO - only MPOL_MF_STRICT was specified and an existing page was already > > > -- > > > 2.26.2 > > > > -- > > Michal Hocko > > SUSE Labs