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=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 EB0A4C433DB for ; Tue, 12 Jan 2021 14:28:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6AC282312F for ; Tue, 12 Jan 2021 14:28:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6AC282312F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7D07F6B016B; Tue, 12 Jan 2021 09:28:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7595E6B0182; Tue, 12 Jan 2021 09:28:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5ABA66B0185; Tue, 12 Jan 2021 09:28:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id 3F5906B016B for ; Tue, 12 Jan 2021 09:28:36 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 0367C8248068 for ; Tue, 12 Jan 2021 14:28:36 +0000 (UTC) X-FDA: 77697353832.12.shoe43_171411227516 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id D616C1801B762 for ; Tue, 12 Jan 2021 14:28:35 +0000 (UTC) X-HE-Tag: shoe43_171411227516 X-Filterd-Recvd-Size: 6079 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 14:28:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610461714; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Sqqrc9MHCImT3FqMOgxcNyYnN8HnQccjuF8KQxEVLmU=; b=dSTXtZTTVckhVSR56rA8Abab+bRIRHTO+IjaRDHirhtWsOobpeXqlnW/w9nVrBZL0SfDiT 8ViqrnuFelN7xJkp5mTVqijPjbdq+VHUCvZ3kb4FwQd+FTP0GfVkMHcCSuAX5Tl/6sigzg PycCSVSxS1WCcrZ0EqqQYel6kTwVboA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-578-v4rIJzhQNjyxl0G1b_-msQ-1; Tue, 12 Jan 2021 09:28:30 -0500 X-MC-Unique: v4rIJzhQNjyxl0G1b_-msQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8A658C73A5; Tue, 12 Jan 2021 14:28:28 +0000 (UTC) Received: from [10.36.115.140] (ovpn-115-140.ams2.redhat.com [10.36.115.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CA2F2BFE7; Tue, 12 Jan 2021 14:28:26 +0000 (UTC) Subject: Re: [External] Re: [PATCH v3 1/6] mm: migrate: do not migrate HugeTLB page whose refcount is one To: Muchun Song Cc: Mike Kravetz , Andrew Morton , Naoya Horiguchi , Andi Kleen , mhocko@suse.cz, Linux Memory Management List , LKML , Yang Shi 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> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <3386dc6d-5f68-c1e3-ba27-d0e95364aa3e@redhat.com> Date: Tue, 12 Jan 2021 15:28:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 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(). 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