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=-3.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 A9790C4361B for ; Thu, 17 Dec 2020 09:05:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 077E02388E for ; Thu, 17 Dec 2020 09:05:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 077E02388E 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 11E566B005D; Thu, 17 Dec 2020 04:05:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CE0C6B0068; Thu, 17 Dec 2020 04:05:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB07B6B006C; Thu, 17 Dec 2020 04:05:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0019.hostedemail.com [216.40.44.19]) by kanga.kvack.org (Postfix) with ESMTP id D29DC6B005D for ; Thu, 17 Dec 2020 04:05:45 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9068368A5 for ; Thu, 17 Dec 2020 09:05:45 +0000 (UTC) X-FDA: 77602191450.26.straw41_03047af27433 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 744F31804B640 for ; Thu, 17 Dec 2020 09:05:45 +0000 (UTC) X-HE-Tag: straw41_03047af27433 X-Filterd-Recvd-Size: 7641 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Thu, 17 Dec 2020 09:05:44 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id j13so3753207pjz.3 for ; Thu, 17 Dec 2020 01:05:44 -0800 (PST) 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=Jju/bhtr378BZhL5XC8hlXJ5twNsYnX10+jclSTpAtw=; b=oyT19CCeCTvnLuZsgySvYPjdrvjtXQFVUeDBvJPphOXxl/MBFsaAONbs7EtEB9CB16 Z33x5yEq+NVJZyrcFATL9oI8Lom7xeH8H7nWshGuzMO2DfrQXY/ZWSUv25tcCpoYmUWe ZkVeWr5GoxZlMbYI9gRf3oa7luwcmgIo27ljLWVTCs5MDwZfHxpMnDUNGT/+SWzbQ4xw pv7FZal9SXndCn9cAd8vDh4MZXHBPCpYMQKqvakbue1/f7ux2VwzBHjilo3x2BfVxIvI ks3ZW9TKrwk15fo6SLYheJGUS6QGy0019nm1laQvtbRpmEKZE2V15ZEcolLQc23reoZu J8Lw== 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=Jju/bhtr378BZhL5XC8hlXJ5twNsYnX10+jclSTpAtw=; b=dIoFFWcV7RxE8Slyrr6sFGCM5tQA/QRHXLgKMIObLRH7nhS1e/2vfH9FPUi1lF5bWE YRrwxU0pL6hukI9JFrsta0TvU0xHF2FScqoSKz754fbRTJLOd/3OgyO75MOGoItuvPUM FbgL899ENHEAIiVsQleY1T1FuN3wChpxFuDJg5eFWsXpyU1hYN2TQ2ZA24uJWxVdwdUW /YkLGx4JEPaZQSoj7MqW6UtC2S6LLXh8wy2oDaPEKR/b/jGwr5evdWB8TCifAIyjDjfv ALwbizRDmFcsnxMbwWYrSPkJtq0OVq9IssqMShX+xclnm1O/iNDFJQ2UrUL4+ORhPU22 p+bQ== X-Gm-Message-State: AOAM533w7nwjiaqR4lFF5XIwElFMj8q4NGk1Id9p3780FO/2tgsGBULt dAEcLAAp8M1C3RcFcShzuiyUq4ojh1qT3stv1lz9gA== X-Google-Smtp-Source: ABdhPJxDpXsIbZNc4x3sr9DJrY0ZC9PGO9w3Eabe2wNgO5QhVcnZ9m9fZAKWqgGcx69r2FmoF930NeWGyZWQQdyJwZ4= X-Received: by 2002:a17:90a:c588:: with SMTP id l8mr7047657pjt.147.1608195943608; Thu, 17 Dec 2020 01:05:43 -0800 (PST) MIME-Version: 1.0 References: <20201213154534.54826-1-songmuchun@bytedance.com> <20201213154534.54826-4-songmuchun@bytedance.com> <5936a766-505a-eab0-42a6-59aab2585880@oracle.com> <20201216222549.GC3207@localhost.localdomain> <49f6a0f1-c6fa-4642-2db0-69f090e8a392@oracle.com> In-Reply-To: From: Muchun Song Date: Thu, 17 Dec 2020 17:05:07 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v9 03/11] mm/hugetlb: Free the vmemmap pages associated with each HugeTLB page To: Mike Kravetz , Oscar Salvador Cc: 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 , Xiongchun duan , linux-doc@vger.kernel.org, LKML , Linux Memory Management List , linux-fsdevel Content-Type: text/plain; charset="UTF-8" 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, Dec 17, 2020 at 2:54 PM Muchun Song wrote: > > On Thu, Dec 17, 2020 at 6:52 AM Mike Kravetz wrote: > > > > On 12/16/20 2:25 PM, Oscar Salvador wrote: > > > On Wed, Dec 16, 2020 at 02:08:30PM -0800, Mike Kravetz wrote: > > >>> + * vmemmap_rmap_walk - walk vmemmap page table > > >>> + > > >>> +static void vmemmap_pte_range(pmd_t *pmd, unsigned long addr, > > >>> + unsigned long end, struct vmemmap_rmap_walk *walk) > > >>> +{ > > >>> + pte_t *pte; > > >>> + > > >>> + pte = pte_offset_kernel(pmd, addr); > > >>> + do { > > >>> + BUG_ON(pte_none(*pte)); > > >>> + > > >>> + if (!walk->reuse) > > >>> + walk->reuse = pte_page(pte[VMEMMAP_TAIL_PAGE_REUSE]); > > >> > > >> It may be just me, but I don't like the pte[-1] here. It certainly does work > > >> as designed because we want to remap all pages in the range to the page before > > >> the range (at offset -1). But, we do not really validate this 'reuse' page. > > >> There is the BUG_ON(pte_none(*pte)) as a sanity check, but we do nothing similar > > >> for pte[-1]. Based on the usage for HugeTLB pages, we can be confident that > > >> pte[-1] is actually a pte. In discussions with Oscar, you mentioned another > > >> possible use for these routines. > > > > > > Without giving it much of a thought, I guess we could duplicate the > > > BUG_ON for the pte outside the loop, and add a new one for pte[-1]. > > > Also, since walk->reuse seems to not change once it is set, we can take > > > it outside the loop? e.g: > > > > > > pte *pte; > > > > > > pte = pte_offset_kernel(pmd, addr); > > > BUG_ON(pte_none(*pte)); > > > BUG_ON(pte_none(pte[VMEMMAP_TAIL_PAGE_REUSE])); > > > walk->reuse = pte_page(pte[VMEMMAP_TAIL_PAGE_REUSE]); > > > do { > > > .... > > > } while... > > > > > > Or I am not sure whether we want to keep it inside the loop in case > > > future cases change walk->reuse during the operation. > > > But to be honest, I do not think it is realistic of all future possible > > > uses of this, so I would rather keep it simple for now. > > > > I was thinking about possibly passing the 'reuse' address as another parameter > > to vmemmap_remap_reuse(). We could add this addr to the vmemmap_rmap_walk > > struct and set walk->reuse when we get to the pte for that address. Of > > course this would imply that the addr would need to be part of the range. > > Maybe adding another one parameter is unnecessary. How about doing > this in the vmemmap_remap_reuse? > > The 'reuse' address just is start + PAGE_SIZE. > > void vmemmap_remap_free(unsigned long start, unsigned long size) > { > unsigned long end = start + size; > unsigned long reuse_addr = start + PAGE_SIZE; ^^^ Here is "-" Sorry. > LIST_HEAD(vmemmap_pages); > > struct vmemmap_remap_walk walk = { > .remap_pte = vmemmap_remap_pte, > .vmemmap_pages = &vmemmap_pages, > .reuse_addr = reuse_addr. > }; > > } > > > > > Ideally, we would walk the page table to get to the reuse page. My concern > > was not explicitly about adding the BUG_ON. In more general use, *pte could > > be the first entry on a pte page. And, then pte[-1] may not even be a pte. > > > > Again, I don't think this matters for the current HugeTLB use case. Just a > > little concerned if code is put to use for other purposes. > > -- > > Mike Kravetz > > > > -- > Yours, > Muchun -- Yours, Muchun