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=-12.7 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,URIBL_RED 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 50674C433E0 for ; Wed, 6 Jan 2021 19:02:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B77332312F for ; Wed, 6 Jan 2021 19:02:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B77332312F 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 CA02F6B02BC; Wed, 6 Jan 2021 14:02:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C505A6B02BE; Wed, 6 Jan 2021 14:02:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3FF76B02BF; Wed, 6 Jan 2021 14:02:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0222.hostedemail.com [216.40.44.222]) by kanga.kvack.org (Postfix) with ESMTP id 9C2B36B02BC for ; Wed, 6 Jan 2021 14:02:21 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5A661824556B for ; Wed, 6 Jan 2021 19:02:21 +0000 (UTC) X-FDA: 77676270882.02.lace18_600540e274e3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 3619C10097AA0 for ; Wed, 6 Jan 2021 19:02:21 +0000 (UTC) X-HE-Tag: lace18_600540e274e3 X-Filterd-Recvd-Size: 8776 Received: from mail-io1-f50.google.com (mail-io1-f50.google.com [209.85.166.50]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Jan 2021 19:02:20 +0000 (UTC) Received: by mail-io1-f50.google.com with SMTP id r9so3722248ioo.7 for ; Wed, 06 Jan 2021 11:02:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=M0UU3Fnq+AFDY3LyEvzo+8UIeemvleyG8FxASGXtzZk=; b=IJqte2brsbiUjTAqQUQIwhUXLXNmzSbuAyYTBcwfoRLDJuH5UjOHFTqsMqjS7wzZB+ Ji0sLhgN9+cJbBPWkhgX2dxAzCxKTRZKN9sPXkbhxrPeOyI4UWoDMvp2DzSVxDiEo/Sc rKnK6d/p/ySoeU1FNBiF0FfpC34+1xcvYleNpVTm5MxlM9tQTYeUeSeI08YrFvA7uAQb jmpvoThYXuyDb+d19wJpAOYHobwgZpp6xdVW8hhbXPabz0N1Um3R7MiAKA5tAKDqCluC ejrtfIZg+EKBGPyTnE4N06p5NshM5kq2PflPknc2sOUZNDiNX3gvbanBNxqzl/Tx8JLB tkSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=M0UU3Fnq+AFDY3LyEvzo+8UIeemvleyG8FxASGXtzZk=; b=PVKn9NW/GsYVbBuWZ2jsOX5PydZGeC1LrsfGliYMHl8InYUNoPtp/1HN9N67S3wL82 1ep2/fUfAHUtgWHrjRKfqRhTwLsUwVKTg6LMpwoAQv3nC986/WnDL0S2SUFcaZZ5c42A ZY41rKQ8nVjxOop87UtZCWew/0xzkkpfd0mBjA2TaB8h+FXpBG5/iRTRGH2sZ9exYALa zIhbJFiIoWFvnhXh1TT4hTX8aFjauJhuejBs4DSOrZJJ8PJBDdzJ0iumKZ5jtrTey4j6 WMMiMpia/E+/8xoXEcrwQ1gu3N+QOkst1zvh+T5LflDlKnUjCeCTCLdt9uiZqsqPa4K4 rxUQ== X-Gm-Message-State: AOAM5320XgfdYRJZne40rUg81/6LLrB/C7cYFNz9vYNQ6U0TFQ7i+z+g +ih8oyx/aVjdt3uWldSQomAAcrwuTNqeePrJKM5BfOKQ6HU= X-Google-Smtp-Source: ABdhPJwG+edIgaoxPvZl0LuFM4yyoTnhPu3VBY7ANESudQRB2S8rG/6gT8xCNFuG5VHx3Oslf/WUOA+1pU6/vpHEOjA= X-Received: by 2002:a6b:8e41:: with SMTP id q62mr3935276iod.5.1609959739977; Wed, 06 Jan 2021 11:02:19 -0800 (PST) MIME-Version: 1.0 References: <20210106035027.GA1160@open-light-1.localdomain> In-Reply-To: <20210106035027.GA1160@open-light-1.localdomain> From: Alexander Duyck Date: Wed, 6 Jan 2021 11:02:09 -0800 Message-ID: Subject: Re: [PATCH 4/6] hugetlb: avoid allocation failed when page reporting is on going To: 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 , LKML , virtualization@lists.linux-foundation.org Cc: Liang Li Content-Type: text/plain; charset="UTF-8" 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 Tue, Jan 5, 2021 at 7:50 PM Liang Li wrote: > > 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 Please don't use this email address for me anymore. Either use alexander.duyck@gmail.com or alexanderduyck@fb.com. I am getting bounces when I reply to this thread because of the old address. > 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); > + } This seems like a bad idea. It kind of defeats the whole point of doing the page zeroing outside of the hugetlb_lock. Also it is operating on the assumption that the only way you might get a page is from the page zeroing logic. With the page reporting code we wouldn't drop the count to zero. We had checks that were going through and monitoring the watermarks and if we started to hit the low watermark we would stop page reporting and just assume there aren't enough pages to report. You might need to look at doing something similar here so that you can avoid colliding with the allocator. > /* > * 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; > } > -- > 2.18.2 > >