Received: by 10.223.185.116 with SMTP id b49csp2700347wrg; Mon, 12 Feb 2018 14:26:05 -0800 (PST) X-Google-Smtp-Source: AH8x2242g8SbMnLMTbJPsC43bHtTcuiUnQ0wrF+XWd9vGzlW1QO45Im9fSWUHrsN7LnLaSyPdUsc X-Received: by 10.98.9.138 with SMTP id 10mr2644505pfj.122.1518474364944; Mon, 12 Feb 2018 14:26:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518474364; cv=none; d=google.com; s=arc-20160816; b=c0raYOFpW/hyAU1PsZ8+T4Ouvyx0Xlg6kLvDcIfBzUFIu7dntS6PjWIn7nILDT1J4g YoaC0PMTgYBBGcMCmcrzAvRK72h05L4T8jqvZlp9t1jrCU71R5pW3BX3gte+OL8axQBM oG6Ri4YOyDEQAywCiFk7b5kEYVn+OyYO0v+ihxHB3R5rHqnjjBQOfFcyKyn84+xynr2G s67fKq+B65lDT8sb0YTvablRTURmmHR+PAfrbUXplato4qTyPiJwnK0Yk8+m600FbX3z 2YHkI3jlPiH9l9ISBOWqZGAzT18p1O3Zeyik8dLm8Uf8NBvWhI22ROWV0bF7ssnK6Rv+ H6tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=8eoVI/dpx85pAGfWiILLl+67v1kmRrbwupkZEtNcl9k=; b=fkDhv35IxIdMhsZ4Zh0g4epQeoHWb9ArnDbnWfwiA3+Q+VczfzR7EyQozZSxRCbBUi wkYLzBUG55OrjJipIVLYVFDqG/LO7ilkeKKZ467vsBl+IlE4CUNUU2x26n7nrnNvf89K MRI7qmXje7JjAq1ccditK/agkbeVZ+9f5gQ614uKXqVxB/3CoOXb0Z8bN+Uhw1Iv3LcM s76R2iF9ES0+aIhopQC7lz6oF4BUHGyD2bi6lZonFgq/PtzQIXvKdUD7JpYxk/tcE5LW Hh+Cjcmk1uzw2RhiHI62kCyxvuVsMQ0OK0StzBWr8OtD7e/Ct4VZh/7FOR1CGl/IIEEZ keeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=DiPH6I2N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p123si18511pga.143.2018.02.12.14.25.49; Mon, 12 Feb 2018 14:26:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=DiPH6I2N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932885AbeBLWXw (ORCPT + 99 others); Mon, 12 Feb 2018 17:23:52 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:58356 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932504AbeBLWVs (ORCPT ); Mon, 12 Feb 2018 17:21:48 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w1CMHS76166306; Mon, 12 Feb 2018 22:21:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=8eoVI/dpx85pAGfWiILLl+67v1kmRrbwupkZEtNcl9k=; b=DiPH6I2NPqF/zO+h5lXNwTWjJnwWxu5R97bPv95DxaKkPW+sFQ7tVEX526IZPzsWk29n V/P1/W1Of/0Mk1+OaYUQdopmHT3Fj37HIcTiLQL48tDUBk1UKB0n7sJjVqg00gIsIr+E NFh7k2FUjf8DM5fw68pMQkjUFeV/o0ydKgugaNPTvVyQrGdqgCIXp15OGe5JTTDZ7NTm /mLrwkiNMMenZ2ab98DDAlNSNeqworQwTtrk7zt3xICpGJnLdhOdJrUtE2OEhA+X/f3g Rp/trXEEKgJlLQJGo9dGgR4A7MGNK5OPCi9dT8hq6zCmDPaxxrZwm91oRaHpb2eX7v8q 0Q== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2g3jw0r7bw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Feb 2018 22:21:26 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w1CMLPDA008708 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 12 Feb 2018 22:21:25 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w1CMLMhC017421; Mon, 12 Feb 2018 22:21:23 GMT Received: from monkey.oracle.com (/98.246.252.205) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 12 Feb 2018 14:21:22 -0800 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Michal Hocko , Christopher Lameter , Guy Shattah , Anshuman Khandual , Michal Nazarewicz , Vlastimil Babka , David Nellans , Laura Abbott , Pavel Machek , Dave Hansen , Mike Kravetz Subject: [RFC PATCH 3/3] mm/hugetlb: use find_alloc_contig_pages() to allocate gigantic pages Date: Mon, 12 Feb 2018 14:20:56 -0800 Message-Id: <20180212222056.9735-4-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180212222056.9735-1-mike.kravetz@oracle.com> References: <20180212222056.9735-1-mike.kravetz@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8803 signatures=668668 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=479 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802120282 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the new find_alloc_contig_pages() interface for the allocation of gigantic pages. Signed-off-by: Mike Kravetz --- mm/hugetlb.c | 88 +++++------------------------------------------------------- 1 file changed, 6 insertions(+), 82 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9a334f5fb730..4c0c4f86dcda 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1060,92 +1060,16 @@ static void destroy_compound_gigantic_page(struct page *page, __ClearPageHead(page); } -static void free_gigantic_page(struct page *page, unsigned int order) +static void free_gigantic_page(struct page *page, struct hstate *h) { - free_contig_range(page_to_pfn(page), 1 << order); -} - -static int __alloc_gigantic_page(unsigned long start_pfn, - unsigned long nr_pages, gfp_t gfp_mask) -{ - unsigned long end_pfn = start_pfn + nr_pages; - return alloc_contig_range(start_pfn, end_pfn, MIGRATE_MOVABLE, - gfp_mask); -} - -static bool pfn_range_valid_gigantic(struct zone *z, - unsigned long start_pfn, unsigned long nr_pages) -{ - unsigned long i, end_pfn = start_pfn + nr_pages; - struct page *page; - - for (i = start_pfn; i < end_pfn; i++) { - if (!pfn_valid(i)) - return false; - - page = pfn_to_page(i); - - if (page_zone(page) != z) - return false; - - if (PageReserved(page)) - return false; - - if (page_count(page) > 0) - return false; - - if (PageHuge(page)) - return false; - } - - return true; -} - -static bool zone_spans_last_pfn(const struct zone *zone, - unsigned long start_pfn, unsigned long nr_pages) -{ - unsigned long last_pfn = start_pfn + nr_pages - 1; - return zone_spans_pfn(zone, last_pfn); + free_contig_pages(page, pages_per_huge_page(h)); } static struct page *alloc_gigantic_page(int nid, struct hstate *h) { - unsigned int order = huge_page_order(h); - unsigned long nr_pages = 1 << order; - unsigned long ret, pfn, flags; - struct zonelist *zonelist; - struct zone *zone; - struct zoneref *z; - gfp_t gfp_mask; - - gfp_mask = htlb_alloc_mask(h) | __GFP_THISNODE; - zonelist = node_zonelist(nid, gfp_mask); - for_each_zone_zonelist_nodemask(zone, z, zonelist, gfp_zone(gfp_mask), NULL) { - spin_lock_irqsave(&zone->lock, flags); + gfp_t gfp_mask = htlb_alloc_mask(h) | __GFP_THISNODE; - pfn = ALIGN(zone->zone_start_pfn, nr_pages); - while (zone_spans_last_pfn(zone, pfn, nr_pages)) { - if (pfn_range_valid_gigantic(zone, pfn, nr_pages)) { - /* - * We release the zone lock here because - * alloc_contig_range() will also lock the zone - * at some point. If there's an allocation - * spinning on this lock, it may win the race - * and cause alloc_contig_range() to fail... - */ - spin_unlock_irqrestore(&zone->lock, flags); - ret = __alloc_gigantic_page(pfn, nr_pages, gfp_mask); - if (!ret) - return pfn_to_page(pfn); - spin_lock_irqsave(&zone->lock, flags); - } - pfn += nr_pages; - } - - spin_unlock_irqrestore(&zone->lock, flags); - } - - return NULL; + return find_alloc_contig_pages(huge_page_order(h), gfp_mask, nid, NULL); } static void prep_new_huge_page(struct hstate *h, struct page *page, int nid); @@ -1181,7 +1105,7 @@ static int alloc_fresh_gigantic_page(struct hstate *h, #else /* !CONFIG_ARCH_HAS_GIGANTIC_PAGE */ static inline bool gigantic_page_supported(void) { return false; } -static inline void free_gigantic_page(struct page *page, unsigned int order) { } +static void free_gigantic_page(struct page *page, struct hstate *h) { } static inline void destroy_compound_gigantic_page(struct page *page, unsigned int order) { } static inline int alloc_fresh_gigantic_page(struct hstate *h, @@ -1208,7 +1132,7 @@ static void update_and_free_page(struct hstate *h, struct page *page) set_page_refcounted(page); if (hstate_is_gigantic(h)) { destroy_compound_gigantic_page(page, huge_page_order(h)); - free_gigantic_page(page, huge_page_order(h)); + free_gigantic_page(page, h); } else { __free_pages(page, huge_page_order(h)); } -- 2.13.6