Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp938076pxf; Wed, 7 Apr 2021 15:33:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfOKsuI8qHskkI4lF+V1IPXlMtq33cvJs/hgVHv2KElkSHAoUkHGFye9fzFW6c+2Y8Fczw X-Received: by 2002:a17:906:ff41:: with SMTP id zo1mr6466565ejb.19.1617834821968; Wed, 07 Apr 2021 15:33:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617834821; cv=none; d=google.com; s=arc-20160816; b=hOEd6/oNVLfE9Kj0Cu1SsaR1vRK8C1PvpISGVrQTVHEcRq7yLwuIPlMEtOtyr639AB Wh0mrekJG2M7B2hbreSTWBUdeAcSv35njk/p1WHaZlFpoAzyir3uo1+RHIrLVcnO7Ozk 33DASVGPtQZ1ENnsSAs6F7JF6qVaorgDdayCb9w2gxJJv8t2D1S0niWDsRmD0uWjNLtO arb87G7e38+J2j2vm+ohk043VhTIzZ5OArXGyGNT5PoOLj21N26ZMgdQu0aWNM9eoioP Xw6Q3gPfrhBhEZGGohDA9ab8qbtcUaoV3Lulp3uDI0dEhf9BvV8l5WHFg/aofxFM/q1p jASA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=l8vmmB/IjsSVHplQGGdaHbrSQ7hCi/88MCyUmEsCWKA=; b=ls7EPfBXMA4626IlBbqWi9U5rwKQZ8a59oYiex0Qfixw890bFmqbyaq6V2TcUUK2XK PAC5X7wxqVU5wRW0B85aNM85FQcKg9TBqqvFdUaLxoa/GUyvLJwFVIq+pPlAMbreVByi vyeA0wiAnatXrSR/COjx0WAOyOWf6Zweph9Kje8FJ/yy99RbQ6DiLXuegD3jVe9vemuY WXJ5lQves5T+1A1c7XYMpnwPbMSKJVM8ObCS4WRIKNPaTozIkyqMmYyfZ3ZFSiX82WMW QbD8kPi5GixNrnHB1SZ6q4Xn7dtHz8YwNRxEsOAoNsILfvndkbl3k9a4XfAs8zy+ceEN JQnA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r11si14057318edo.275.2021.04.07.15.33.19; Wed, 07 Apr 2021 15:33:41 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235277AbhDGI2L (ORCPT + 99 others); Wed, 7 Apr 2021 04:28:11 -0400 Received: from mx2.suse.de ([195.135.220.15]:48698 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240739AbhDGI2E (ORCPT ); Wed, 7 Apr 2021 04:28:04 -0400 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 77DE9AFCF; Wed, 7 Apr 2021 08:27:53 +0000 (UTC) Date: Wed, 7 Apr 2021 10:27:49 +0200 From: Oscar Salvador To: Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Roman Gushchin , Michal Hocko , Shakeel Butt , David Hildenbrand , Muchun Song , David Rientjes , Miaohe Lin , Peter Zijlstra , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Hillf Danton , Joonsoo Kim , Barry Song , Will Deacon , Andrew Morton Subject: Re: [PATCH v4 5/8] hugetlb: call update_and_free_page without hugetlb_lock Message-ID: <20210407082744.GA10058@linux> References: <20210405230043.182734-1-mike.kravetz@oracle.com> <20210405230043.182734-6-mike.kravetz@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210405230043.182734-6-mike.kravetz@oracle.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 05, 2021 at 04:00:40PM -0700, Mike Kravetz wrote: > With the introduction of remove_hugetlb_page(), there is no need for > update_and_free_page to hold the hugetlb lock. Change all callers to > drop the lock before calling. > > With additional code modifications, this will allow loops which decrease > the huge page pool to drop the hugetlb_lock with each page to reduce > long hold times. > > The ugly unlock/lock cycle in free_pool_huge_page will be removed in > a subsequent patch which restructures free_pool_huge_page. > > Signed-off-by: Mike Kravetz Without looking too close at the changes made to alloc_and_dissolve_huge_page(): Reviewed-by: Oscar Salvador One question below: > @@ -2671,22 +2682,34 @@ static void try_to_free_low(struct hstate *h, unsigned long count, > nodemask_t *nodes_allowed) > { > int i; > + struct page *page, *next; > + LIST_HEAD(page_list); > > if (hstate_is_gigantic(h)) > return; > > + /* > + * Collect pages to be freed on a list, and free after dropping lock > + */ > for_each_node_mask(i, *nodes_allowed) { > - struct page *page, *next; > struct list_head *freel = &h->hugepage_freelists[i]; > list_for_each_entry_safe(page, next, freel, lru) { > if (count >= h->nr_huge_pages) > - return; > + goto out; > if (PageHighMem(page)) > continue; > remove_hugetlb_page(h, page, false); > - update_and_free_page(h, page); > + list_add(&page->lru, &page_list); > } > } > + > +out: > + spin_unlock(&hugetlb_lock); > + list_for_each_entry_safe(page, next, &page_list, lru) { > + update_and_free_page(h, page); > + cond_resched(); > + } > + spin_lock(&hugetlb_lock); Can we get here with an empty list? Maybe if someone raced with us manipulating nr_huge_pages? AFAICS, this gets called under the lock, and the adjusting in remove_hugetlb_page() gets also done under the lock, so I guess this is not possible to happen. The reason I am asking is whether we want to check for the list to be empty before we do the unacquire/acquire lock dancing. -- Oscar Salvador SUSE L3