Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7926678pxb; Fri, 19 Feb 2021 03:02:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzx9YhlSak2/gvY0p7SbTMgNnkLqDt4Pho5oHtTd1VRT7Y4C2UQ1pn/l+bZlUMBWqSpzd8C X-Received: by 2002:a17:907:7691:: with SMTP id jv17mr8057687ejc.75.1613732550231; Fri, 19 Feb 2021 03:02:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613732550; cv=none; d=google.com; s=arc-20160816; b=j2E0UISt95jZQKa4Rv/wEd0ZnAovuWDhUdH/uZLM21tSiC4P3ItI07LZxTKzU7krsz sL/uAjkdPYw6ESaZejrh2FY8fFtQrdE0iFsTbDffW5+SaliYyXBPMQHUCUf/ctUxIbzU k2hnVTt7HHCMP8dtsp5cMcCfo20MfCnHppdDKDrxGNOGMwk95fCN9XCNHWvKwwK1eh3M Ed1WRyvAAQhH8kKyARBpbIn8H7zPK/cvgf5U3CNR9r+mYWtYBNvStoJ5Bw8f39F/5nUL EMzsJYNQLOVu/iZlTChx/9LdwQNkF72WffUV6gWvmpAV08lHaE88oYnnbb4jWNaPwzRG 5b+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=rFG8P9Ie0qeQWrQfmu4nspdfkX+zgZBg6iq8S0zq+4o=; b=hRENlr9iKO0l2p7sfYOsY1fRQSZLF+Bb7bMl9E/9+JhsgU7iBLDjTQ3waJqyeOyI9r Lxc67pp4sk7jNSFDSA93J0jy3axg9xG043+U1Yk2rQq7qoMgWMt3BJ5RnZUbUw2/0hyJ KyAofTrzPOLOA+ovCxRSpfUHpA+B7wHFkO+7rBCVZDtBUn++Yc/yU5M0fUaX7daex7sA Mzm3yS8OZ2/jKpmwdg2oQCqp1GP1pboBGI6UypOk1HP6dA0sHMyhC0V+bKeTRpFtI3sK +2VvTk4v9onHNYhz6ZhphNIXXLmcnSdVs+V0Q0GI+wbOsq/Ignx6CEDaSHwkdo6uNNG1 lRFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=ghVSU2tW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z23si6339387edm.39.2021.02.19.03.02.04; Fri, 19 Feb 2021 03:02:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=ghVSU2tW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230222AbhBSK6z (ORCPT + 99 others); Fri, 19 Feb 2021 05:58:55 -0500 Received: from mx2.suse.de ([195.135.220.15]:51392 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230196AbhBSKzr (ORCPT ); Fri, 19 Feb 2021 05:55:47 -0500 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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