Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp229632pxf; Tue, 6 Apr 2021 20:30:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxw4ghFdz6N3+JXpMM8fdJcrgOgMVPzLFzEw1SSHpFZiZ/4LXGK9498sImMsu2iMB2aW2Ga X-Received: by 2002:a92:d1cb:: with SMTP id u11mr1137052ilg.184.1617766257602; Tue, 06 Apr 2021 20:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617766257; cv=none; d=google.com; s=arc-20160816; b=hPX3v0b2U+XlqKqNP8MM9Ho0SVo0uR1HqJYKSE75OW5dtXy4yWOteWUjcpj4vD2eYS ESDyFPM0ByseW1gfWtdbtPjZR8SYu2KDzUpc4SNQw0L7RTb7X/aG7cQ2Bryi2qEwzkz/ TKE5f4X2zY4TeNiiYJK2Hd68gKvj61Ecz9kf4NTSrtFxTi52BbskodUgFQNSqflanV9I ETaRkjr7PVOhPZiY9ok1GThJ5iu9/0h7ravy7BDnnnYMHU/YYTSTiNSoHvxIRG5S+ezQ V3kFnMNm6jPCPFGU16p6dahzr3GNtjQGzFifcU+R+nC15sJjrPgn72aql1ciAwe1YW4c H4ow== 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; bh=A00NO8H+v//3WkcDmthp09pje8imxH9Q6/p8mVmOdis=; b=SYnjmHfiq4ymxCzaUe+JjYqOBOnU7y0veY83GLAKNNC6NPtPqyqvk8udcFUc/F7YxC 87OzGONreNHcBLgtTv4RYjUgLKbdLh2deFOZLY3kYnhR2+fc5s3K/gw2c4Y84kUN5Az0 n4tHEBkB7fB4QcWwnR3PKncYLd5bhcp/H0slf48NZ79Z5jjGfoyWj2YPpxktI3I9vz0f EjXeZZGEN0eGeH2aC37XR46HDFoxPFfF77m5YgNOUva6a1dhors1vwujWCS7p7gKtX7r LRaHhU7JOk3qKSPPhnSYWoqeCI9DDR58omEx4blM9egzw+hZJ9rGduImgc+fnDko+41U Vm1w== 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 b16si20033610iob.27.2021.04.06.20.30.45; Tue, 06 Apr 2021 20:30:57 -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 S244049AbhDFNlW (ORCPT + 99 others); Tue, 6 Apr 2021 09:41:22 -0400 Received: from mx2.suse.de ([195.135.220.15]:46748 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238827AbhDFNlW (ORCPT ); Tue, 6 Apr 2021 09:41:22 -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 811DAB1AD; Tue, 6 Apr 2021 13:41:13 +0000 (UTC) Date: Tue, 6 Apr 2021 15:41:07 +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 4/8] hugetlb: create remove_hugetlb_page() to separate functionality Message-ID: References: <20210405230043.182734-1-mike.kravetz@oracle.com> <20210405230043.182734-5-mike.kravetz@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210405230043.182734-5-mike.kravetz@oracle.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 05, 2021 at 04:00:39PM -0700, Mike Kravetz wrote: > +static void remove_hugetlb_page(struct hstate *h, struct page *page, > + bool adjust_surplus) > +{ > + int nid = page_to_nid(page); > + > + if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) > + return; > + > + list_del(&page->lru); > + > + if (HPageFreed(page)) { > + h->free_huge_pages--; > + h->free_huge_pages_node[nid]--; > + ClearHPageFreed(page); > + } > + if (adjust_surplus) { > + h->surplus_huge_pages--; > + h->surplus_huge_pages_node[nid]--; > + } > + > + VM_BUG_ON_PAGE(hugetlb_cgroup_from_page(page), page); > + VM_BUG_ON_PAGE(hugetlb_cgroup_from_page_rsvd(page), page); These checks feel a bit odd here. I would move them above, before we start messing with the counters? > + > + ClearHPageTemporary(page); Why clearing it unconditionally? I guess we do not really care, but someone might wonder why when reading the core. So I would either do as we used to do and only clear it in case of HPageTemporary(), or drop a comment. > + set_page_refcounted(page); > + set_compound_page_dtor(page, NULL_COMPOUND_DTOR); > + > + h->nr_huge_pages--; > + h->nr_huge_pages_node[nid]--; > +} As Michal pointed out, remove_hugetlb_page() from alloc_and_dissolve_huge_page() might be problematic in some cases because the new_page has not been enqueued yet. Now, I guess this might be easily fixed with checking list_empty() before going ahead with list_del() call, or with another bool parameter 'delete', with a fat comment explaining why we can get to call remove_huge_page() on a page that is not in any list. Another solution that comes to my mind is to split remove_huge_page() functionality in 1) delete from list + unaccount free and surplus pages and 2) reset page's state + unaccount nr_huge_pages But that might be just biased as would fit for my usecase. So maybe a list_empty() or the bool parameter might just do. -- Oscar Salvador SUSE L3