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.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 B888AC433DB for ; Tue, 23 Feb 2021 10:50:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2DFB664DF5 for ; Tue, 23 Feb 2021 10:50:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2DFB664DF5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 99EE86B0005; Tue, 23 Feb 2021 05:50:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 94FC56B0006; Tue, 23 Feb 2021 05:50:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F0B76B006E; Tue, 23 Feb 2021 05:50:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0004.hostedemail.com [216.40.44.4]) by kanga.kvack.org (Postfix) with ESMTP id 697316B0005 for ; Tue, 23 Feb 2021 05:50:13 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2F7F4183594FA for ; Tue, 23 Feb 2021 10:50:13 +0000 (UTC) X-FDA: 77849213106.09.2EA80B7 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf15.hostedemail.com (Postfix) with ESMTP id 83CC1A0009E3 for ; Tue, 23 Feb 2021 10:50:11 +0000 (UTC) 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 A75CCAC69; Tue, 23 Feb 2021 10:50:10 +0000 (UTC) Date: Tue, 23 Feb 2021 11:50:05 +0100 From: Oscar Salvador To: Muchun Song Cc: Mike Kravetz , Jonathan Corbet , Thomas Gleixner , mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, Peter Zijlstra , viro@zeniv.linux.org.uk, Andrew Morton , paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, Randy Dunlap , oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, Mina Almasry , David Rientjes , Matthew Wilcox , Michal Hocko , "Song Bao Hua (Barry Song)" , David Hildenbrand , HORIGUCHI =?utf-8?B?TkFPWUEo5aCA5Y+jIOebtOS5nyk=?= , Joao Martins , Xiongchun duan , linux-doc@vger.kernel.org, LKML , Linux Memory Management List , linux-fsdevel Subject: Re: [External] Re: [PATCH v16 4/9] mm: hugetlb: alloc the vmemmap pages associated with each HugeTLB page Message-ID: <20210223104957.GA3844@linux> References: <20210219104954.67390-1-songmuchun@bytedance.com> <20210219104954.67390-5-songmuchun@bytedance.com> <13a5363c-6af4-1e1f-9a18-972ca18278b5@oracle.com> <20210223092740.GA1998@linux> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Stat-Signature: 77yw76ms5dc1mr76ktos3dfap4ffq9me X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 83CC1A0009E3 Received-SPF: none (suse.de>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1614077411-861130 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 Tue, Feb 23, 2021 at 06:27:07PM +0800, Muchun Song wrote: > > > > + > > > > + if (alloc_huge_page_vmemmap(h, page)) { > > > > + int zeroed; > > > > + > > > > + spin_lock(&hugetlb_lock); > > > > + INIT_LIST_HEAD(&page->lru); > > > > + set_compound_page_dtor(page, HUGETLB_PAGE_DTOR); > > > > + h->nr_huge_pages++; > > > > + h->nr_huge_pages_node[nid]++; > > > > I think prep_new_huge_page() does this for us? > > Actually, there are some differences. e.g. prep_new_huge_page() > will reset hugetlb cgroup and ClearHPageFreed, but we do not need > them here. And prep_new_huge_page will acquire and release > the hugetlb_lock. But here we also need hold the lock to update > the surplus counter and enqueue the page to the free list. > So I do not think reuse prep_new_huge_page is a good idea. I see, I missed that. > > Can this actually happen? AFAIK, page landed in update_and_free_page should be > > zero refcounted, then we increase the reference, and I cannot see how the > > reference might have changed in the meantime. > > I am not sure whether other modules get the page and then put the > page. I see gather_surplus_pages does the same thing. So I copied > from there. I try to look at the memory_failure routine. > > > CPU0: CPU1: > set_compound_page_dtor(HUGETLB_PAGE_DTOR); > memory_failure_hugetlb > get_hwpoison_page > __get_hwpoison_page > get_page_unless_zero > put_page_testzero() > > Maybe this can happen. But it is a very corner case. If we want to > deal with this. We can put_page_testzero() first and then > set_compound_page_dtor(HUGETLB_PAGE_DTOR). I have to check further, but it looks like this could actually happen. Handling this with VM_BUG_ON is wrong, because memory_failure/soft_offline are entitled to increase the refcount of the page. AFAICS, CPU0: CPU1: set_compound_page_dtor(HUGETLB_PAGE_DTOR); memory_failure_hugetlb get_hwpoison_page __get_hwpoison_page get_page_unless_zero put_page_testzero() identify_page_state me_huge_page I think we can reach me_huge_page with either refcount = 1 or refcount =2, depending whether put_page_testzero has been issued. For now, I would not re-enqueue the page if put_page_testzero == false. I have to see how this can be handled gracefully. -- Oscar Salvador SUSE L3