Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp201170pxa; Tue, 11 Aug 2020 22:42:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCKgIAiXyMgqEFa/JREUfA3oNft4ogC6nwjFsuxYI/EM7/Ran5T45NQJ7i60i66J/8CHEd X-Received: by 2002:a17:906:af51:: with SMTP id ly17mr28729280ejb.81.1597210945563; Tue, 11 Aug 2020 22:42:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597210945; cv=none; d=google.com; s=arc-20160816; b=iGxobmrSpR2DVgIigTVrmCvtIUcnNcYKyQHVk9KPa7CHqLzQ0V1luNYElZ34jCtQJp bQxq3YsovHOE5GoYfotN1MZxiRRDGJvgFWCPnBjMeBt/p6IpelfhIXZcvC67ydOUry+M biMIQlYY3fkbnvGQjMV+bUHxOOnD1Gt2KDEtMHHRu7e+mfTstJZpmubLB9rb8p8Ynqt5 CFL2Q5YJRFHp4LZuDNsEzqmMWa0koCel2hwS/0FrJXfXZxM69r8odpc3cmrPzpz1SHVd aRZQ0HCf0nCDDrCWyaU/B69IiasYF63cGP4ODMUoA0I4K8KYX8kmSOYK5GaFILkSiLZZ XZbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=YjQCImwrKKAQU3JlwtdjkqTIDAo/dvR77KpYtYakGUs=; b=fRNVD6ndRVqLCpg2Fz3Bv/xY+yfweMRiDdMRg8MeuCwJzfl5xsww9AtfTDFbDsiS5G tqqwWBL1sHf6P0fsX2R/oVRubRnAjTJ2v8SrC6lvzD6ZEAEaq6KJ8fUuEN46AcUFLC3P Xf3SBafgfRlme4YMz6JKyu1pD+7O0/T4FtCH78gH/qgGsEOpZcRkaT364r2W+bpflwHN 0srFDmOpxnyycR+AjKjTgXApiwkkGVBSL3O8PP9BLE+yLNM+yp/IR2j0K3TyL3zD9HQF hvNCgenzAAuBu8XEI72XBOItSAkzjb2MGhJPMisK3z5ZO0aVfuVucgFZgiuDkpqnkblj c8Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MVRkze2i; 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 k20si541037ejq.330.2020.08.11.22.42.02; Tue, 11 Aug 2020 22:42:25 -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=MVRkze2i; 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 S1726510AbgHLFkp (ORCPT + 99 others); Wed, 12 Aug 2020 01:40:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21901 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726264AbgHLFkp (ORCPT ); Wed, 12 Aug 2020 01:40:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597210843; 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=YjQCImwrKKAQU3JlwtdjkqTIDAo/dvR77KpYtYakGUs=; b=MVRkze2iQR/FBTpy53Oam6KzZ5sZXt3QQLUh6X2Gkxk4qr6wEB0npFYpExiD8Rl4Ig30bk 3yvzz2GThxRL7bV+Jot6K6R/NXnZd6lpvwTClgnU6HU0w/3Uv8uKYv0GTER/7Knska8QDD hxBnZnTdw9rK0wsn4AkVjx5Gkbb8IWo= 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-498-ejtbnAT5P5yGMymPcfsSEg-1; Wed, 12 Aug 2020 01:40:41 -0400 X-MC-Unique: ejtbnAT5P5yGMymPcfsSEg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 302A61005504; Wed, 12 Aug 2020 05:40:40 +0000 (UTC) Received: from localhost (ovpn-12-45.pek2.redhat.com [10.72.12.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 377D360C84; Wed, 12 Aug 2020 05:40:37 +0000 (UTC) Date: Wed, 12 Aug 2020 13:40:35 +0800 From: Baoquan He To: Mike Kravetz Cc: Michal Hocko , Wei Yang , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 10/10] mm/hugetlb: not necessary to abuse temporary page to workaround the nasty free_huge_page Message-ID: <20200812054035.GD10792@MiWiFi-R3L-srv> References: <20200807091251.12129-1-richard.weiyang@linux.alibaba.com> <20200807091251.12129-11-richard.weiyang@linux.alibaba.com> <20200810021737.GV14854@MiWiFi-R3L-srv> <129cc03e-c6d5-24f8-2f3c-f5a3cc821e76@oracle.com> <20200811015148.GA10792@MiWiFi-R3L-srv> <20200811065406.GC4793@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/11/20 at 02:43pm, Mike Kravetz wrote: > Here is a patch to do that. However, we are optimizing a return path in > a race condition that we are unlikely to ever hit. I 'tested' it by allocating > an 'extra' page and freeing it via this method in alloc_surplus_huge_page. > > From 864c5f8ef4900c95ca3f6f2363a85f3cb25e793e Mon Sep 17 00:00:00 2001 > From: Mike Kravetz > Date: Tue, 11 Aug 2020 12:45:41 -0700 > Subject: [PATCH] hugetlb: optimize race error return in > alloc_surplus_huge_page > > The routine alloc_surplus_huge_page() could race with with a pool > size change. If this happens, the allocated page may not be needed. > To free the page, the current code will 'Abuse temporary page to > workaround the nasty free_huge_page codeflow'. Instead, directly > call the low level routine that free_huge_page uses. This works > out well because the page is new, we hold the only reference and > already hold the hugetlb_lock. > > Signed-off-by: Mike Kravetz > --- > mm/hugetlb.c | 13 ++++++++----- > 1 file changed, 8 insertions(+), 5 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 590111ea6975..ac89b91fba86 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -1923,14 +1923,17 @@ static struct page *alloc_surplus_huge_page(struct hstate *h, gfp_t gfp_mask, > /* > * We could have raced with the pool size change. > * Double check that and simply deallocate the new page > - * if we would end up overcommiting the surpluses. Abuse > - * temporary page to workaround the nasty free_huge_page > - * codeflow > + * if we would end up overcommiting the surpluses. > */ > if (h->surplus_huge_pages >= h->nr_overcommit_huge_pages) { > - SetPageHugeTemporary(page); > + /* > + * Since this page is new, we hold the only reference, and > + * we already hold the hugetlb_lock call the low level free > + * page routine. This saves at least a lock roundtrip. > + */ > + (void)put_page_testzero(page); /* don't call destructor */ > + update_and_free_page(h, page); Yeah, taking this code change, or keeping the temporary page way as is, both looks good. > spin_unlock(&hugetlb_lock); > - put_page(page); > return NULL; > } else { > h->surplus_huge_pages++;