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=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 B0DB4C433DB for ; Mon, 1 Mar 2021 14:09:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 335B864D99 for ; Mon, 1 Mar 2021 14:09:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 335B864D99 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 B73658D0072; Mon, 1 Mar 2021 09:09:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B22958D0063; Mon, 1 Mar 2021 09:09:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A39358D0072; Mon, 1 Mar 2021 09:09:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0242.hostedemail.com [216.40.44.242]) by kanga.kvack.org (Postfix) with ESMTP id 8D8E28D0063 for ; Mon, 1 Mar 2021 09:09:39 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 44F3C363E for ; Mon, 1 Mar 2021 14:09:38 +0000 (UTC) X-FDA: 77871488436.19.E248002 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 46E184080F6A for ; Mon, 1 Mar 2021 14:09:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614607775; 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=Ri9XDuJqxC9BSq44voletKdjAlrsHvrvulgnxCXLswI=; b=fZT9KjuH9uEnqY4ZbhiygqZ9lzJC0eVUowNnJZn09LNfz/LUrS694iGsY4q/IZTIL+0xNq VKkhBTqengB5xIbWgJCPFItQjbzx2ZLfHgSKgVA1fHefXO67tckhSiPCOmj3SdJ+7P3Mmk vovJj7XNVOO5+lR1B8jpCZRyqEMGhVg= 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-206-YKLDpw9JOCe6-C14jCxYpw-1; Mon, 01 Mar 2021 09:09:31 -0500 X-MC-Unique: YKLDpw9JOCe6-C14jCxYpw-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 B7DC5189C2A9; Mon, 1 Mar 2021 14:09:09 +0000 (UTC) Received: from [10.36.114.87] (ovpn-114-87.ams2.redhat.com [10.36.114.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD81A5B4A7; Mon, 1 Mar 2021 14:09:07 +0000 (UTC) To: Oscar Salvador , Andrew Morton Cc: Mike Kravetz , Muchun Song , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20210222135137.25717-1-osalvador@suse.de> <20210222135137.25717-2-osalvador@suse.de> From: David Hildenbrand Organization: Red Hat GmbH Subject: Re: [PATCH v3 1/2] mm: Make alloc_contig_range handle free hugetlb pages Message-ID: <3f071dd4-3181-f4e0-fd56-1a70f6ac72fe@redhat.com> Date: Mon, 1 Mar 2021 15:09:06 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <20210222135137.25717-2-osalvador@suse.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 46E184080F6A X-Stat-Signature: azsu4eqntn9bpinnj7oho4aubzp1kis4 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf26; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=63.128.21.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614607770-699555 Content-Transfer-Encoding: quoted-printable 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 22.02.21 14:51, Oscar Salvador wrote: > alloc_contig_range will fail if it ever sees a HugeTLB page within the > range we are trying to allocate, even when that page is free and can be > easily reallocated. > This has proved to be problematic for some users of alloc_contic_range, > e.g: CMA and virtio-mem, where those would fail the call even when thos= e > pages lay in ZONE_MOVABLE and are free. >=20 > We can do better by trying to replace such page. >=20 > Free hugepages are tricky to handle so as to no userspace application > notices disruption, we need to replace the current free hugepage with > a new one. >=20 > In order to do that, a new function called alloc_and_dissolve_huge_page > is introduced. > This function will first try to get a new fresh hugepage, and if it > succeeds, it will replace the old one in the free hugepage pool. >=20 > All operations are being handled under hugetlb_lock, so no races are > possible. The only exception is when page's refcount is 0, but it still > has not been flagged as PageHugeFreed. > In this case we retry as the window race is quite small and we have hig= h > chances to succeed next time. >=20 > With regard to the allocation, we restrict it to the node the page belo= ngs > to with __GFP_THISNODE, meaning we do not fallback on other node's zone= s. >=20 > Note that gigantic hugetlb pages are fenced off since there is a cyclic > dependency between them and alloc_contig_range. >=20 > Signed-off-by: Oscar Salvador > --- > include/linux/hugetlb.h | 6 +++ > mm/compaction.c | 12 ++++++ > mm/hugetlb.c | 111 +++++++++++++++++++++++++++++++++++++++= ++++++++- > 3 files changed, 127 insertions(+), 2 deletions(-) >=20 > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > index b5807f23caf8..72352d718829 100644 > --- a/include/linux/hugetlb.h > +++ b/include/linux/hugetlb.h > @@ -505,6 +505,7 @@ struct huge_bootmem_page { > struct hstate *hstate; > }; > =20 > +bool isolate_or_dissolve_huge_page(struct page *page); > struct page *alloc_huge_page(struct vm_area_struct *vma, > unsigned long addr, int avoid_reserve); > struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred= _nid, > @@ -775,6 +776,11 @@ void set_page_huge_active(struct page *page); > #else /* CONFIG_HUGETLB_PAGE */ > struct hstate {}; > =20 > +static inline bool isolate_or_dissolve_huge_page(struct page *page) > +{ > + return false; > +} > + > static inline struct page *alloc_huge_page(struct vm_area_struct *vma= , > unsigned long addr, > int avoid_reserve) > diff --git a/mm/compaction.c b/mm/compaction.c > index 190ccdaa6c19..d52506ed9db7 100644 > --- a/mm/compaction.c > +++ b/mm/compaction.c > @@ -905,6 +905,18 @@ isolate_migratepages_block(struct compact_control = *cc, unsigned long low_pfn, > valid_page =3D page; > } > =20 > + if (PageHuge(page) && cc->alloc_contig) { > + if (!isolate_or_dissolve_huge_page(page)) > + goto isolate_fail; So, the callchain is: alloc_contig_range()->__alloc_contig_migrate_range()->isolate_migratepage= s_range()->isolate_migratepages_block() The case I am thinking about is if we run out of memory and would return=20 -ENOMEM from alloc_and_dissolve_huge_page(). We silently drop the real=20 error (e.g., -ENOMEM vs. -EBUSY vs. e.g., -EAGAIN) we had in=20 isolate_or_dissolve_huge_page(). I think we should not swallo such return values in=20 isolate_or_dissolve_huge_page() and instead properly report esp. -ENOMEM=20 properly up this callchain now. Otherwise we'll end up retrying /=20 reporting -EBUSY, which is misleading. From isolate_migratepages_range()/isolate_migratepages_block() we'll=20 keep reporting "pfn > 0". a) In isolate_migratepages_range() we'll keep iterating over pageblocks=20 although we should just fail with -ENOMEM right away. b) In __alloc_contig_migrate_range() we'll keep retrying up to 5 times=20 although we should just fail with -ENOMEM. We end up returning "-EBUSY"=20 after retrying. c) In alloc_contig_range() we'll continue trying to isolate although we=20 should just return -ENOMEM. I think we have should start returning proper errors from=20 isolate_migratepages_range()/isolate_migratepages_block() on critical=20 issues (-EINTR, -ENOMEM) instead of going via "!pfn vs. pfn" and=20 retrying on "pfn". So we should then fail with -ENOMEM during isolate_migratepages_range()=20 cleanly, just as we would do when we get -ENOMEM during migrate_pages(). --=20 Thanks, David / dhildenb