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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 19DCFC433DB for ; Fri, 19 Feb 2021 10:55:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 905D964EBF for ; Fri, 19 Feb 2021 10:55:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 905D964EBF 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 E293B8D001A; Fri, 19 Feb 2021 05:55:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DFF568D000A; Fri, 19 Feb 2021 05:55:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3B948D001A; Fri, 19 Feb 2021 05:55:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id B83FA8D000A for ; Fri, 19 Feb 2021 05:55:02 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 757B28249980 for ; Fri, 19 Feb 2021 10:55:02 +0000 (UTC) X-FDA: 77834710044.12.986CB3E Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf10.hostedemail.com (Postfix) with ESMTP id 59F8C407F8EB for ; Fri, 19 Feb 2021 10:54:58 +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=1613732100; 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=rFG8P9Ie0qeQWrQfmu4nspdfkX+zgZBg6iq8S0zq+4o=; b=ghVSU2tWyDJjeKNm5dWJOkhOE1GmVzyU5Kd5XS6Z6dAMvi2zK52pQ2xaoAg4rbS+X++Krs OEyro5aWmQQydkGWFVzt4byaWoGkUYeNv1Bu7a3hAatcXr7cxbZbyF4WdX+9c1MM/1gisl LfYdpToQoAW+6AQT7JzjYgmF0G1Pvf8= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A8714AC6E; Fri, 19 Feb 2021 10:55:00 +0000 (UTC) Date: Fri, 19 Feb 2021 11:55:00 +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 1/2] mm: Make alloc_contig_range handle free hugetlb pages Message-ID: References: <20210217100816.28860-1-osalvador@suse.de> <20210217100816.28860-2-osalvador@suse.de> <20210218100917.GA4842@localhost.localdomain> <20210218133250.GA7983@localhost.localdomain> <20210219090548.GA17266@linux> <20210219103943.GA19945@linux> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210219103943.GA19945@linux> X-Stat-Signature: 44fip7o45p97nxsmtex44fmsr3m86465 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 59F8C407F8EB Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613732098-627965 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 19-02-21 11:40:30, Oscar Salvador wrote: > On Fri, Feb 19, 2021 at 10:56:42AM +0100, Michal Hocko wrote: > > OK, this should work but I am really wondering whether it wouldn't be > > just simpler to replace the old page by a new one in the free list > > directly. Or is there any reason we have to go through the generic > > helpers path? I mean something like this > > > > new_page = alloc_fresh_huge_page(); > > if (!new_page) > > goto fail; > > spin_lock(hugetlb_lock); > > if (!PageHuge(old_page)) { > > /* freed from under us, nothing to do */ > > __update_and_free_page(new_page); > > goto unlock; > > } > > list_del(&old_page->lru); > > __update_and_free_page(old_page); > > __enqueue_huge_page(new_page); > > unlock: > > spin_unlock(hugetlb_lock); > > > > This will require to split update_and_free_page and enqueue_huge_page to > > counters independent parts but that shouldn't be a big deal. But it will > > also protect from any races. Not an act of beauty but seems less hackish > > to me. > > On a closer look, do we really need to decouple update_and_free_page and > enqueue_huge_page? These two functions do not handle the lock, but rather > the functions that call them (as would be in our case). > Only update_and_free_page drops the lock during the freeing of a gigantic page > and then it takes it again, as the caller is who took the lock. > > am I missing anything obvious here? It is not the lock that I care about but more about counters. The intention was that there is a single place to handle both enqueing and dequeing. As not all places require counters to be updated. E.g. the migration which just replaces one page by another. -- Michal Hocko SUSE Labs