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=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 8875AC433DB for ; Tue, 12 Jan 2021 14:59:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DB87023101 for ; Tue, 12 Jan 2021 14:59:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB87023101 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 268ED8D00AD; Tue, 12 Jan 2021 09:59:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 218238D00AA; Tue, 12 Jan 2021 09:59:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 107EF8D00AD; Tue, 12 Jan 2021 09:59:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id EC5728D00AA for ; Tue, 12 Jan 2021 09:59:48 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A9B41181AEF07 for ; Tue, 12 Jan 2021 14:59:48 +0000 (UTC) X-FDA: 77697432456.14.cook71_48074f827516 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 83553182299A7 for ; Tue, 12 Jan 2021 14:59:48 +0000 (UTC) X-HE-Tag: cook71_48074f827516 X-Filterd-Recvd-Size: 6857 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 14:59:47 +0000 (UTC) Received: by mail-pj1-f43.google.com with SMTP id b5so1846165pjl.0 for ; Tue, 12 Jan 2021 06:59:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=a38rsa+oJPxhFV5dbDxkGdFt7ckWx72VOIR5CzRWxbo=; b=ilkHdplTgxpRIFCuJ9bYoUCQXd+TBCSuJci7gKx14NEBzoudleiWjfE0mwbWobGHD4 xm5b3PA51/3AzeMI4TPFL4zjJbrl4NnMiV7gEH4wGo+AMcHZLIfj0X5+jdhoToPELku0 N68QTvRmLjft4vpxZOtTrmBqYVu2DURPZEsn9je984dLKgrXnnKzJZVox0djshEuxRwn 8L44CZrYM47qMXZMvRO+Hyqxhna9NgFKwDNVHSNouzc87HJYUWLSe2fJi0NpUIDMA3Bn GKqj2JG9AoTumN840MLj10h//aMdc70jin9/wVvqP5ocBHEojg3lYEnY/peX139tU/0H 185Q== 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=a38rsa+oJPxhFV5dbDxkGdFt7ckWx72VOIR5CzRWxbo=; b=gxt7PtUjXvdhw6zA8sXm0fw9FJDg5VUVnk5l2KSDTNJ7sRYdkiIsTdO1VQbLMz0bPO tjIpRuvv1fCFOnuwN2eXVaYyewyTfJekpADEENMHf993xz8WMagfI6GH4nKV8/eqsrtU Noh4b6yBb4BcrlNEezrMFjbC6hINRKu0YOBOoJZuwpUHh9LMHcBbV3QMRtKt5KqARn15 EQKrph9n8ooZkM52eivwt4nHBt203rBAxLExx0aYzIxqoo1NJ5KXck8Fs5tTY1EQz0s0 kez518QEZVQoT98rnS6Gd5iI6sgCqeTjh9BnRmr3ZO0MGDtCTY7CiP3W8hRATil/vM4V vBHg== X-Gm-Message-State: AOAM533/54/KBQ+OehInzxtpHNuz830TzUUpp0dne4YSGdxn6N8N5Eae bMh67Z20KyRqZowlYigGGIHde4FpHbHScX1F6LK5tA== X-Google-Smtp-Source: ABdhPJyhgal5NozlKzbp3qJRFGeaEGAi1pquLRa2OCtb3h3QSICphnx0otTEbid82VuZT2Ef6+XbTfkLI/VLRG1q+zQ= X-Received: by 2002:a17:90a:5405:: with SMTP id z5mr5238068pjh.13.1610463585073; Tue, 12 Jan 2021 06:59:45 -0800 (PST) MIME-Version: 1.0 References: <20210110124017.86750-1-songmuchun@bytedance.com> <20210110124017.86750-2-songmuchun@bytedance.com> <1b39d654-0b8c-de3a-55d1-6ab8c2b2e0ba@redhat.com> <423ee403-bba7-acf6-8934-9db36d3a719a@redhat.com> <3386dc6d-5f68-c1e3-ba27-d0e95364aa3e@redhat.com> In-Reply-To: <3386dc6d-5f68-c1e3-ba27-d0e95364aa3e@redhat.com> From: Muchun Song Date: Tue, 12 Jan 2021 22:59:03 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v3 1/6] mm: migrate: do not migrate HugeTLB page whose refcount is one To: David Hildenbrand Cc: Mike Kravetz , Andrew Morton , Naoya Horiguchi , Andi Kleen , mhocko@suse.cz, Linux Memory Management List , LKML , Yang Shi 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, Jan 12, 2021 at 10:28 PM David Hildenbrand wrote: > > On 12.01.21 15:17, Muchun Song wrote: > > On Tue, Jan 12, 2021 at 9:51 PM David Hildenbrand wrote: > >> > >> On 12.01.21 14:40, Muchun Song wrote: > >>> On Tue, Jan 12, 2021 at 7:11 PM David Hildenbrand wrote: > >>>> > >>>> On 12.01.21 12:00, David Hildenbrand wrote: > >>>>> On 10.01.21 13:40, Muchun Song wrote: > >>>>>> If the refcount is one when it is migrated, it means that the page > >>>>>> was freed from under us. So we are done and do not need to migrate. > >>>>>> > >>>>>> This optimization is consistent with the regular pages, just like > >>>>>> unmap_and_move() does. > >>>>>> > >>>>>> Signed-off-by: Muchun Song > >>>>>> Reviewed-by: Mike Kravetz > >>>>>> Acked-by: Yang Shi > >>>>>> --- > >>>>>> mm/migrate.c | 6 ++++++ > >>>>>> 1 file changed, 6 insertions(+) > >>>>>> > >>>>>> diff --git a/mm/migrate.c b/mm/migrate.c > >>>>>> index 4385f2fb5d18..a6631c4eb6a6 100644 > >>>>>> --- a/mm/migrate.c > >>>>>> +++ b/mm/migrate.c > >>>>>> @@ -1279,6 +1279,12 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, > >>>>>> return -ENOSYS; > >>>>>> } > >>>>>> > >>>>>> + if (page_count(hpage) == 1) { > >>>>>> + /* page was freed from under us. So we are done. */ > >>>>>> + putback_active_hugepage(hpage); > >>>>>> + return MIGRATEPAGE_SUCCESS; > >>>>>> + } > >>>>>> + > >>>>>> new_hpage = get_new_page(hpage, private); > >>>>>> if (!new_hpage) > >>>>>> return -ENOMEM; > >>>>>> > >>>>> > >>>>> Question: What if called via alloc_contig_range() where we even want to > >>>>> "migrate" free pages, meaning, relocate it? > >>>>> > >>>> > >>>> To be more precise: > >>>> > >>>> a) We don't have dissolve_free_huge_pages() calls on the > >>>> alloc_contig_range() path. So we *need* migration IIUC. > >>> > >>> Without this patch, if you want to migrate a HUgeTLB page, > >>> the page is freed to the hugepage pool. With this patch, > >>> the page is also freed to the hugepage pool. > >>> I didn't see any different. I am missing something? > >> > >> I am definitely not an expert on hugetlb pools, that's why I am asking. > >> > >> Isn't it, that with your code, no new page is allocated - so > >> dissolve_free_huge_pages() might just refuse to dissolve due to > >> reservations, bailing out, no? > > > > Without this patch, the new page can be allocated from the > > hugepage pool. The dissolve_free_huge_pages() also > > can refuse to dissolve due to reservations. Right? > > Oh, you mean the migration target might be coming from the pool? I guess > yes, looking at alloc_migration_target()->alloc_huge_page_nodemask(). Yeah, you are right. If we want to free a HugeTLB page to the buddy allocator, we should dissolve_free_huge_page() to do that. Migrating cannot guarantee this at least now. > > In that case, yes, I think we run into a similar issue already. > > Instead of trying to allocate new huge pages in > dissolve_free_huge_pages() to "relocate free pages", we bail out. > > This all feels kind of wrong. After we migrated a huge page we should > free it back to the buddy, so most of our machinery just keeps working > without caring about free huge pages. > > > I can see how your patch will not change the current (IMHO broken) behavior. > > -- > Thanks, > > David / dhildenb >