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=-8.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 7E6E6C47E48 for ; Thu, 15 Jul 2021 03:14:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E586F610A7 for ; Thu, 15 Jul 2021 03:14:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E586F610A7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 24F9A6B00B2; Wed, 14 Jul 2021 23:14:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D8CA6B00B4; Wed, 14 Jul 2021 23:14:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02ACE6B00B7; Wed, 14 Jul 2021 23:14:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0204.hostedemail.com [216.40.44.204]) by kanga.kvack.org (Postfix) with ESMTP id CD4A36B00B2 for ; Wed, 14 Jul 2021 23:14:42 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A6692231D8 for ; Thu, 15 Jul 2021 03:14:41 +0000 (UTC) X-FDA: 78363354762.09.3569841 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf29.hostedemail.com (Postfix) with ESMTP id 59478900024A for ; Thu, 15 Jul 2021 03:14:40 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id s18so4586026pgq.3 for ; Wed, 14 Jul 2021 20:14:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=abyDHR0XRwSMrhA06McE4t3PEmRieAURZX1e2KLvRB4=; b=GpJrAxJZnwq6fPqj8j+JHs+SBdIKLopRRZJAb5ZcmyHLusiVn99YhZBxYgVboYwU9u US0lZR9SBIKwKCWkN3F/BhKpLSaRyOW5gW7jy5fz4a8kOLH40jTC6NlJTTJeWLJhA11v 8JGETmCMlhSucSeLzyOxmakWCODX48tCeF9PgB9wnvm0nbpWl5kHDhV0hA6RVr1Jg4Uo uqmqEkc77BVC9ZQcww9O/bFKW92oWMJ8+DQBjPdL851Qu3I8eBLOkiKhqUXKQ+E7t7cz lmkhegsbt6bIAehkd8FtcU4/1NvoDbz+ESe3D54NCuYvJI8dTErWVITaDvqR05rsf7BN WBmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=abyDHR0XRwSMrhA06McE4t3PEmRieAURZX1e2KLvRB4=; b=d5CGrWW6xiuPsm5weena8TOapEfTtgCF18Bikep5s4eaUARK2GV3aOXSXaRol1GI0I gkm/N+4l5TmLXZPIlJcwflMU4XltF09Nn9R54huB8AXXv+QAlDm7aH3DH0BvD7IxReuo vxPD8m9FX5TYcGtgGyQUoCD1YhLYDRU/vZKzts8Fjrgc2pTBPoYRm0LAiT1czuxkZu7y b3Jo4bWANQQqbeNL5P/0ssY5RObNq4xMNI2sxG4O009aYMUwsGcJjcCbm45U+mFspldd qdebKZAU31OjIhEQU07E4/WBULksaHRMUiGAMF0VLtn6PFCIAparfomizu+qokT+3vW8 nxYg== X-Gm-Message-State: AOAM530bEuIq7QTX1BG363bT6iEj3RzEI1zytpu7VVlVY100lrGohpnt Nz0/gyc0DnH1115R0NEiu8iF/hUMuHle/5ehPtt2mQ== X-Google-Smtp-Source: ABdhPJzOV/c1LX6O04F3PPyi2lFcjnNcqYqiySbWv2hUD0oiEItNo7TlW6+E2Zb4oR9B+ECHbIgo9Bnly2g2+ovg/vs= X-Received: by 2002:a65:63ce:: with SMTP id n14mr1740199pgv.273.1626318879171; Wed, 14 Jul 2021 20:14:39 -0700 (PDT) MIME-Version: 1.0 References: <20210710002441.167759-1-mike.kravetz@oracle.com> <20210710002441.167759-4-mike.kravetz@oracle.com> <6c38223b-83f4-ef7d-68d7-27c0f6ae6359@oracle.com> In-Reply-To: <6c38223b-83f4-ef7d-68d7-27c0f6ae6359@oracle.com> From: Muchun Song Date: Thu, 15 Jul 2021 11:14:03 +0800 Message-ID: Subject: Re: [External] [PATCH 3/3] hugetlb: before freeing hugetlb page set dtor to appropriate value To: Mike Kravetz Cc: Linux Memory Management List , LKML , Michal Hocko , Oscar Salvador , David Hildenbrand , Matthew Wilcox , Naoya Horiguchi , Mina Almasry , Andrew Morton Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 59478900024A X-Stat-Signature: zeufo6zzmxgz9xsdsrfi5yy644ys9con Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=GpJrAxJZ; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-HE-Tag: 1626318880-836350 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 Thu, Jul 15, 2021 at 1:39 AM Mike Kravetz wrote: > > On 7/14/21 3:57 AM, Muchun Song wrote: > > On Sat, Jul 10, 2021 at 8:25 AM Mike Kravetz wrote: > >> + /* > >> + * Very subtle > >> + * > >> + * For non-gigantic pages set the destructor to the normal compound > >> + * page dtor. This is needed in case someone takes an additional > >> + * temporary ref to the page, and freeing is delayed until they drop > >> + * their reference. > >> + * > >> + * For gigantic pages set the destructor to the null dtor. This > >> + * destructor will never be called. Before freeing the gigantic > >> + * page destroy_compound_gigantic_page will turn the compound page > >> + * into a simple group of pages. After this the destructor does not > >> + * apply. > >> + * > >> + * This handles the case where more than one ref is held when and > >> + * after update_and_free_page is called. > >> + */ > >> set_page_refcounted(page); > >> - set_compound_page_dtor(page, NULL_COMPOUND_DTOR); > >> + if (hstate_is_gigantic(h)) > >> + set_compound_page_dtor(page, NULL_COMPOUND_DTOR); > >> + else > >> + set_compound_page_dtor(page, COMPOUND_PAGE_DTOR); > > > > Hi Mike, > > > > The race is really subtle. But we also should remove the WARN from > > free_contig_range, right? Because the refcount of the head page of > > the gigantic page can be greater than one, but free_contig_range has > > the following warning. > > > > WARN(count != 0, "%lu pages are still in use!\n", count); > > > > I did hit that warning in my testing and thought about removing it. > However, I decided to keep it because non-hugetlb code also makes use of > alloc_contig_range/free_contig_range and it might be useful in those > cases. > > My 'guess' is that the warning was added not because of temporary ref > count increases but rather to point out any code that forgot to drop a > reference. Got it. At least this patch looks good to me. So Reviewed-by: Muchun Song > > BTW - It is not just the 'head' page which could trigger this warning, but > any 'tail' page as well. That is because we do not call free_contig_range > with a compound page, but rather a group of pages all with ref count of > at least one. Right. > > I'm happy to remove the warning if people do not think it is generally > useful. For me, I suggest removing it. If someone has any ideas, please let us know. > -- > Mike Kravetz