Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp256958pxb; Fri, 16 Apr 2021 05:05:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcvtMDJm+0r12D+sgSEMxS11nApfarHMyP6z12tJ67PP50p1cjnRcLZP9o0I3jQEIh4CJb X-Received: by 2002:a17:90b:4c0c:: with SMTP id na12mr9016906pjb.117.1618574703413; Fri, 16 Apr 2021 05:05:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618574703; cv=none; d=google.com; s=arc-20160816; b=TDQz2cmhRPkGCCSS6rqzTAzW/CHAfnComiCeiwwl4KntxZtJSy89TFyuNfFkCdFKlK NqaGcXYGKRkOG8zbmAi6tMwuDLDiOMIw1Cml7TdfaTwmWqckCd+oEbSPq5jyUyYElD7x HpjD2w8viNQt1LBLXsoO03gb4QVAawtR+B9YDfVJcof2lgOyoIXO8FQhti4KkChI16GQ NOBovqPmKQzAHihj067gjJKL0ou2VqEzYCtXOp3CuCrAinpIkLq6B3Uav1L3CaaS2/hC q2RyHgN3hhJIlMCaSraWo3lgSV0AtJBcVmCZhl7gI7a9rsZdwNCv/O524DjiExLquhtA ZmTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=pL4/0WJEqGhEKqqgK/B3s9Ma+T2AYRInru9aztuxIYY=; b=EifJ+VfilZ2Km9SveNWfUufVJ/4iQlJK3dLfR8H0MDHwOkXfEkp7lB3GjDkjPYVmWD 80e3YYLm2YnW5kHEB6+hOJITa5pEaUxf6x9aQsVi9uIH/VkoreM2dQcjPxf9sFj/HmHV fgf71RqoSnqsp1JvtC0vu7RRYBykA0UYmdk9XAGNr86DiZ3SZ7vF+2Ay834TnbCRqybl P2JayL15RLMd9qeSJyd9ijG1Tsa9k7vXuGm2qCEJj/qzycbfRPJojlKvOLzyIjOEgZ7F L5ggLEIdwYCaPegqKudmvzp2VDnLn0vxTBCC4NdMrIu95kO0xJqgWdUpuMIpQ03f371c G8xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Jx/o+Udl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t25si6682994pgu.261.2021.04.16.05.04.50; Fri, 16 Apr 2021 05:05:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Jx/o+Udl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242055AbhDPJty (ORCPT + 99 others); Fri, 16 Apr 2021 05:49:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28273 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232022AbhDPJty (ORCPT ); Fri, 16 Apr 2021 05:49:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618566569; 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: in-reply-to:in-reply-to:references:references; bh=pL4/0WJEqGhEKqqgK/B3s9Ma+T2AYRInru9aztuxIYY=; b=Jx/o+UdlJHlTVBSGZY0cLX5+aogIIYs2D2vEJykfGX1QCbVtAAbdMJ3vOYmGypvXFxMKMN yGMba/MmMNpyPbSJdr3KiNWp2OlRikLM6bljvxMWP0BvDZC1RCEJE5ozLC9Ka60sOf0UWz CaBBHNAiqQXkwUGozA1wDwdUt+jR8oQ= 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-585-mW1SmpBpNbC06zBXKRyOag-1; Fri, 16 Apr 2021 05:49:27 -0400 X-MC-Unique: mW1SmpBpNbC06zBXKRyOag-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7A036D246; Fri, 16 Apr 2021 09:49:25 +0000 (UTC) Received: from localhost (ovpn-12-94.pek2.redhat.com [10.72.12.94]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 04F6E6294D; Fri, 16 Apr 2021 09:49:22 +0000 (UTC) Date: Fri, 16 Apr 2021 17:49:20 +0800 From: Baoquan He To: Oscar Salvador Cc: Andrew Morton , Mike Kravetz , Vlastimil Babka , David Hildenbrand , Michal Hocko , Muchun Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Michal Hocko Subject: Re: [PATCH v9 5/7] mm: Make alloc_contig_range handle free hugetlb pages Message-ID: <20210416094920.GA8560@MiWiFi-R3L-srv> References: <20210416070023.4742-1-osalvador@suse.de> <20210416070023.4742-6-osalvador@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210416070023.4742-6-osalvador@suse.de> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/16/21 at 09:00am, Oscar Salvador wrote: ... > +/* > + * alloc_and_dissolve_huge_page - Allocate a new page and dissolve the old one > + * @h: struct hstate old page belongs to > + * @old_page: Old page to dissolve > + * Returns 0 on success, otherwise negated error. > + */ > +static int alloc_and_dissolve_huge_page(struct hstate *h, struct page *old_page) > +{ > + gfp_t gfp_mask = htlb_alloc_mask(h) | __GFP_THISNODE; > + int nid = page_to_nid(old_page); > + struct page *new_page; > + int ret = 0; > + > + /* > + * Before dissolving the page, we need to allocate a new one for the > + * pool to remain stable. Using alloc_buddy_huge_page() allows us to > + * not having to deal with prep_new_page() and avoids dealing of any ~ prep_new_huge_page() ? > + * counters. This simplifies and let us do the whole thing under the > + * lock. > + */ > + new_page = alloc_buddy_huge_page(h, gfp_mask, nid, NULL, NULL); > + if (!new_page) > + return -ENOMEM; > + > +retry: > + spin_lock_irq(&hugetlb_lock); ...