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=-10.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,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 6F18BC433DB for ; Fri, 26 Feb 2021 09:45:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E06EE64ED5 for ; Fri, 26 Feb 2021 09:45:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E06EE64ED5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 13DE76B0005; Fri, 26 Feb 2021 04:45:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F6E96B0006; Fri, 26 Feb 2021 04:45:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02A0D6B006C; Fri, 26 Feb 2021 04:45:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id D6C6C6B0005 for ; Fri, 26 Feb 2021 04:45:18 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A27BF181CBC1C for ; Fri, 26 Feb 2021 09:45:18 +0000 (UTC) X-FDA: 77859935916.25.D43714B Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf15.hostedemail.com (Postfix) with ESMTP id E9196A0009C5 for ; Fri, 26 Feb 2021 09:45:16 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9F928AAAE; Fri, 26 Feb 2021 09:45:16 +0000 (UTC) Date: Fri, 26 Feb 2021 10:45:14 +0100 From: Oscar Salvador To: Michal Hocko Cc: Andrew Morton , Mike Kravetz , David Hildenbrand , Muchun Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/2] mm: Make alloc_contig_range handle free hugetlb pages Message-ID: <20210226094507.GA3240@linux> References: <20210222135137.25717-1-osalvador@suse.de> <20210222135137.25717-2-osalvador@suse.de> 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-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E9196A0009C5 X-Stat-Signature: gjyt47ndrzoz8sr8p7769uwpz598z841 Received-SPF: none (suse.de>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1614332716-200251 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 Fri, Feb 26, 2021 at 09:35:09AM +0100, Michal Hocko wrote: > I think it would be helpful to call out that specific case explicitly > here. I can see only one scenario (are there more?) > __free_huge_page() isolate_or_dissolve_huge_page > PageHuge() == T > alloc_and_dissolve_huge_page > alloc_fresh_huge_page() > spin_lock(hugetlb_lock) > // PageHuge() && !PageHugeFreed && > // !PageCount() > spin_unlock(hugetlb_lock) > spin_lock(hugetlb_lock) > 1) update_and_free_page > PageHuge() == F > __free_pages() > 2) enqueue_huge_page > SetPageHugeFreed() > spin_unlock(&hugetlb_lock) I do not think there are more scenarios. The thing is to find a !page_count && !PageHugeFreed. AFAICS, this can only happen after: put_page->put_page_test_zero->..->_free_huge_page gets called but __free_huge_page has not reached enqueue_huge_page yet (as you just described above) By calling out this case, you meant to describe it in the changelog? > > > In this case we retry as the window race is quite small and we have high > > chances to succeed next time. > > > > With regard to the allocation, we restrict it to the node the page belongs > > to with __GFP_THISNODE, meaning we do not fallback on other node's zones. > > > > Note that gigantic hugetlb pages are fenced off since there is a cyclic > > dependency between them and alloc_contig_range. > > > > Signed-off-by: Oscar Salvador > > Thanks this looks much better than the initial version. One nit below. > Acked-by: Michal Hocko Thanks! > > +bool isolate_or_dissolve_huge_page(struct page *page) > > +{ > > + struct hstate *h = NULL; > > + struct page *head; > > + bool ret = false; > > + > > + spin_lock(&hugetlb_lock); > > + if (PageHuge(page)) { > > + head = compound_head(page); > > + h = page_hstate(head); > > + } > > + spin_unlock(&hugetlb_lock); > > + > > + /* > > + * The page might have been dissolved from under our feet. > > + * If that is the case, return success as if we dissolved it ourselves. > > + */ > > + if (!h) > > + return true; > > I am still fighting with this construct a bit. It is not really clear > what the lock is protecting us from here. alloc_fresh_huge_page deals > with all potential races and this looks like an optimistic check to save > some work. But in fact the lock is really necessary for correctness > because hstate might be completely bogus without the lock or us holding > a reference on the poage. The following construct would be more > explicit and compact. What do you think? > > struct hstate *h; > > /* > * The page might have been dissloved from under our feet > * so make sure to carefully check the state under the lock. > * Return success on when racing as if we dissloved the page > * ourselves. > */ > spin_lock(&hugetlb_lock); > if (PageHuge(page)) { > head = compound_head(page); > h = page_hstate(head); > } else { > spin_unlock(&hugetlb_lock); > return true; > } > spin_unlock(&hugetlb_lock); Yes, I find this less eyesore. I will fix it up in v4. -- Oscar Salvador SUSE L3