From patchwork Wed Jan 6 03:50:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liang Li X-Patchwork-Id: 12000919 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=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 EFC55C433E0 for ; Wed, 6 Jan 2021 03:50:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9322522CB1 for ; Wed, 6 Jan 2021 03:50:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9322522CB1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1CED98D00D1; Tue, 5 Jan 2021 22:50:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 17EB28D0090; Tue, 5 Jan 2021 22:50:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06E758D00D1; Tue, 5 Jan 2021 22:50:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id E5F1D8D0090 for ; Tue, 5 Jan 2021 22:50:35 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A6AAD824556B for ; Wed, 6 Jan 2021 03:50:35 +0000 (UTC) X-FDA: 77673973230.08.brain96_1500b08274de Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 89D131819E76C for ; Wed, 6 Jan 2021 03:50:35 +0000 (UTC) X-HE-Tag: brain96_1500b08274de X-Filterd-Recvd-Size: 8185 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Jan 2021 03:50:35 +0000 (UTC) Received: by mail-pg1-f172.google.com with SMTP id i5so1337715pgo.1 for ; Tue, 05 Jan 2021 19:50:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=vjozGeH0DLUu5oDcu6sd/j2j59t7TfqorAS7kIj0og4=; b=cB8IknFCHfwQTUc4eD+XI8HFf02mJt83IhhReI+NBrD7IjqJmV0OLeqrMy/t4c+RHC U6CgIhtQmjlxEaQSkgbunWFDNBIRUrryYr49JMAem5NfsQDJ3yPvJwYlGhuDaPt6oukB NrZCRdkvUQ1iKBusU9sLG8dmYD1wGWgz1jCjsyR2ymzoESR2vugOLhAZxfLTCFzYxNmH 9siNnxcynZ8tyh1GiH2aFj37kccCVuvaprUTCDj4EDzTzsRI2EJ4EcUvbQd4FdKWDov8 DOB9u4Pt9gk//014cc2L5tvlwvtozrWAD4WfkF8veQOCfe5y3F9drcsGN1p26CmOeCbd eSYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id :mail-followup-to:mime-version:content-disposition:user-agent; bh=vjozGeH0DLUu5oDcu6sd/j2j59t7TfqorAS7kIj0og4=; b=LHAFEUowDBb6ASB2oL6AHNlAkidrcNztSezugVi64ZSC9pl5gicyeIo8C0mYZ1akrY 6ZaNsl11pD0Qar5A6Q2XExT3/MmuYDR5VlzUDGLO7UXd39XLUsM5L2uawK0RNn7bYJxS nFemAqWjYyG5baFbyxHSLnEBddKVJALFQowongDhkSrF/xVLcnb+VzUTBfJw7PmloPOZ xGefEcYr9g3yTHxfVyer+afFaZjeGpA/jjUFWSxqmwezhJ+NPSS9vrktQe6jwvYDYyPn dNJUL1E8RzKwmoCZzyT/QGdlRBnpzi9wJij0fD7gJbYTXN+s5f/H6Fc6bXFpJ5AaYb5A Tv0Q== X-Gm-Message-State: AOAM530BV16o0kVFDOx6+ohoqE2nTgcSVATRFRmd/AGEX0EzrTuWQfHf Ge/m+4hGKettAxtX75Avc58= X-Google-Smtp-Source: ABdhPJx3UVAdnbo3q8qAcpUMRqlMo/+9TS95oG+EkORfpLfFTM4NBjJQnPC+fi+osFhdS8KdCq1qdw== X-Received: by 2002:a63:78ca:: with SMTP id t193mr2351201pgc.391.1609905034313; Tue, 05 Jan 2021 19:50:34 -0800 (PST) Received: from open-light-1.localdomain (66.98.113.28.16clouds.com. [66.98.113.28]) by smtp.gmail.com with ESMTPSA id m15sm735974pfa.72.2021.01.05.19.50.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jan 2021 19:50:33 -0800 (PST) From: Liang Li X-Google-Original-From: Liang Li Date: Tue, 5 Jan 2021 22:50:31 -0500 To: Alexander Duyck , Mel Gorman , Andrew Morton , Andrea Arcangeli , Dan Williams , "Michael S. Tsirkin" , David Hildenbrand , Jason Wang , Dave Hansen , Michal Hocko , Liang Li , Liang Li , Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH 4/6] hugetlb: avoid allocation failed when page reporting is on going Message-ID: <20210106035027.GA1160@open-light-1.localdomain> Mail-Followup-To: Alexander Duyck , Mel Gorman , Andrew Morton , Andrea Arcangeli , Dan Williams , "Michael S. Tsirkin" , David Hildenbrand , Jason Wang , Dave Hansen , Michal Hocko , Liang Li , Mike Kravetz , linux-mm@kvack.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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: Page reporting isolates free pages temporarily when reporting free pages information. It will reduce the actual free pages and may cause application failed for no enough available memory. This patch try to solve this issue, when there is no free page and page repoting is on going, wait until it is done. Cc: Alexander Duyck Cc: Mel Gorman Cc: Andrea Arcangeli Cc: Dan Williams Cc: Dave Hansen Cc: David Hildenbrand Cc: Michal Hocko Cc: Andrew Morton Cc: Alex Williamson Cc: Michael S. Tsirkin Cc: Liang Li Signed-off-by: Liang Li --- include/linux/hugetlb.h | 2 ++ mm/hugetlb.c | 9 +++++++++ mm/page_reporting.c | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index d55e6a00b3dc..73b2934ba91c 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -490,6 +490,7 @@ struct hstate { unsigned long resv_huge_pages; unsigned long surplus_huge_pages; unsigned long nr_overcommit_huge_pages; + unsigned long isolated_huge_pages; struct list_head hugepage_activelist; struct list_head hugepage_freelists[MAX_NUMNODES]; unsigned int nr_huge_pages_node[MAX_NUMNODES]; @@ -500,6 +501,7 @@ struct hstate { struct cftype cgroup_files_dfl[7]; struct cftype cgroup_files_legacy[9]; #endif + struct mutex mtx_prezero; char name[HSTATE_NAME_LEN]; }; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index eb533995cb49..0fccd5f96954 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2320,6 +2320,12 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, goto out_uncharge_cgroup_reservation; spin_lock(&hugetlb_lock); + while (h->free_huge_pages <= 1 && h->isolated_huge_pages) { + spin_unlock(&hugetlb_lock); + mutex_lock(&h->mtx_prezero); + mutex_unlock(&h->mtx_prezero); + spin_lock(&hugetlb_lock); + } /* * glb_chg is passed to indicate whether or not a page must be taken * from the global free pool (global change). gbl_chg == 0 indicates @@ -3208,6 +3214,7 @@ void __init hugetlb_add_hstate(unsigned int order) INIT_LIST_HEAD(&h->hugepage_activelist); h->next_nid_to_alloc = first_memory_node; h->next_nid_to_free = first_memory_node; + mutex_init(&h->mtx_prezero); snprintf(h->name, HSTATE_NAME_LEN, "hugepages-%lukB", huge_page_size(h)/1024); @@ -5541,6 +5548,7 @@ void isolate_free_huge_page(struct page *page, struct hstate *h, int nid) list_move(&page->lru, &h->hugepage_activelist); set_page_refcounted(page); + h->isolated_huge_pages++; } void putback_isolate_huge_page(struct hstate *h, struct page *page) @@ -5548,6 +5556,7 @@ void putback_isolate_huge_page(struct hstate *h, struct page *page) int nid = page_to_nid(page); list_move(&page->lru, &h->hugepage_freelists[nid]); + h->isolated_huge_pages--; } bool isolate_huge_page(struct page *page, struct list_head *list) diff --git a/mm/page_reporting.c b/mm/page_reporting.c index cc31696225bb..99e1e688d7c1 100644 --- a/mm/page_reporting.c +++ b/mm/page_reporting.c @@ -272,12 +272,15 @@ hugepage_reporting_process_hstate(struct page_reporting_dev_info *prdev, int ret = 0, nid; offset = max_items; + mutex_lock(&h->mtx_prezero); for (nid = 0; nid < MAX_NUMNODES; nid++) { ret = hugepage_reporting_cycle(prdev, h, nid, sgl, &offset, max_items); - if (ret < 0) + if (ret < 0) { + mutex_unlock(&h->mtx_prezero); return ret; + } } /* report the leftover pages before going idle */ @@ -291,6 +294,7 @@ hugepage_reporting_process_hstate(struct page_reporting_dev_info *prdev, hugepage_reporting_drain(prdev, h, sgl, leftover, !ret); spin_unlock(&hugetlb_lock); } + mutex_unlock(&h->mtx_prezero); return ret; }