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.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 A539BC433E0 for ; Fri, 26 Feb 2021 08:38:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 20F2864EE7 for ; Fri, 26 Feb 2021 08:38:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 20F2864EE7 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 78F8C6B0005; Fri, 26 Feb 2021 03:38:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 743136B0006; Fri, 26 Feb 2021 03:38:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6555D6B006C; Fri, 26 Feb 2021 03:38:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0048.hostedemail.com [216.40.44.48]) by kanga.kvack.org (Postfix) with ESMTP id 4CEFB6B0005 for ; Fri, 26 Feb 2021 03:38:38 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 0B53C181B049D for ; Fri, 26 Feb 2021 08:38:38 +0000 (UTC) X-FDA: 77859767916.19.D9EEEEC Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf21.hostedemail.com (Postfix) with ESMTP id EEC08E0011DD for ; Fri, 26 Feb 2021 08:38:33 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1614328716; h=from:from:reply-to: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=ryNEoNrCU7SPStlbI4pZYs4/RAqN6mJpaGrcrqsuyT4=; b=kqPUtCnkz5X8zHmu2iF/9P7RwnnGl9g+rV3GmSwWupGNXw4KeotqBW8boZs9DRfQQBiRkU K7tFA/9V6arLBwUVYQ2y7PFEcQgvShArJDBV25WFz6zXgHG7bwx/t7iuS+vwk2BTa9eUeQ YYfXd+Ejq+sv20lqhpzXCaH8B4zzm1U= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 68A12AAAE; Fri, 26 Feb 2021 08:38:36 +0000 (UTC) Date: Fri, 26 Feb 2021 09:38:35 +0100 From: Michal Hocko To: Oscar Salvador 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: 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: X-Stat-Signature: oxkqqqd55j9wz6wbttsh7gdfffup7uqi X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: EEC08E0011DD Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf21; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614328713-552545 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 26-02-21 09:35:10, Michal Hocko wrote: > On Mon 22-02-21 14:51:36, Oscar Salvador wrote: > > alloc_contig_range will fail if it ever sees a HugeTLB page within the > > range we are trying to allocate, even when that page is free and can be > > easily reallocated. > > This has proved to be problematic for some users of alloc_contic_range, > > e.g: CMA and virtio-mem, where those would fail the call even when those > > pages lay in ZONE_MOVABLE and are free. > > > > We can do better by trying to replace such page. > > > > Free hugepages are tricky to handle so as to no userspace application > > notices disruption, we need to replace the current free hugepage with > > a new one. > > > > In order to do that, a new function called alloc_and_dissolve_huge_page > > is introduced. > > This function will first try to get a new fresh hugepage, and if it > > succeeds, it will replace the old one in the free hugepage pool. > > > > All operations are being handled under hugetlb_lock, so no races are > > possible. The only exception is when page's refcount is 0, but it still > > has not been flagged as PageHugeFreed. > > 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) > > > 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 Btw. if David has some numbers it would be great to add them to the changelog. -- Michal Hocko SUSE Labs