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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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 DD5FBC4320E for ; Wed, 1 Sep 2021 16:07:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4791361059 for ; Wed, 1 Sep 2021 16:07:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4791361059 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A4174900003; Wed, 1 Sep 2021 12:07:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9EF526B0073; Wed, 1 Sep 2021 12:07:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8DF51900003; Wed, 1 Sep 2021 12:07:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0021.hostedemail.com [216.40.44.21]) by kanga.kvack.org (Postfix) with ESMTP id 7E09D6B0072 for ; Wed, 1 Sep 2021 12:07:45 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0453425718 for ; Wed, 1 Sep 2021 16:07:45 +0000 (UTC) X-FDA: 78539485290.21.3F33FA1 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) by imf17.hostedemail.com (Postfix) with ESMTP id A1336F000136 for ; Wed, 1 Sep 2021 16:07:44 +0000 (UTC) Received: by mail-qv1-f45.google.com with SMTP id g11so48138qvd.2 for ; Wed, 01 Sep 2021 09:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ENgS5NCsCBTF4mXrUN4mnxvn/rv2h7hXBulk866gSRk=; b=hUCCyobyzgyt/MRFzTijqMgOUI5qzMd1zgeqqthZmmgaEZ13QzRtAuChF2YAwYBViL OwSZ0+kn5VbJDrgWQKqPTHHF+QFSQUthIa62T+cst+BeZc4frqUyqsaoQ6r2bZoeSibT ttQnvFKqtontOT0prIiNBo+ig80AiTewp8Sxqxo5jvmfcDH+BfCfhl/8VoSrl4I+UfIN UkUOEiNvGUpTjOP3JprYUaqODoJ3vCQsdOnfQPrjzzj5viJdBD+XGLvl716LSxB0dUWr 7LSOULkdURoi9VJP2mle9GvVXI8FL/GKx/EFefDkDfKr/XP++rxCoW3J/3yz4n6iOnRL RJjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ENgS5NCsCBTF4mXrUN4mnxvn/rv2h7hXBulk866gSRk=; b=kNUe2fGKet+MIF231aojBgN7p/nAlIDvmcE51HM/3Fi2Nes/+pNQmHWHRRAR4VWM0Q TGICK1Zhs68AXhx/+Ld0v6RYbffaP9zYLuBpo1MJFiOE6A7kaeJENBX2YXAuO7qfplQM 0qqJwfm5NBV381WnLPtQlfAoXOtAfZjy3tcrgSxR1Wi8oIqsjirHOHn1AjdQH0Tlga6y sLO6lnnbOOmEPtuISGX8+3ORE5sJhX6qoWGzMYvwezP1Q25iCcFtJ71utMzvNr5ogguD dic4IQtW7SknVPi+674ulzPK/QdnaAMnCoa6mTx2PYRADBn10GQICXcG4qTX4DbB1HJ4 kodA== X-Gm-Message-State: AOAM532ZBVhqxoCn8ryghBBQk1OzmoKf6lJVTV4+iCjvMMp9Z5QZqXLR H2qF4S0drYiIOAtYaI7g0wqP3Q== X-Google-Smtp-Source: ABdhPJx+hJCNSdfKSSiAqLRegfFOCASpINnQ9G2ySwHo5jZJlX3gLxTbwzYUSXoTG+CL9BzmhPqrLg== X-Received: by 2002:a0c:e042:: with SMTP id y2mr413898qvk.21.1630512463956; Wed, 01 Sep 2021 09:07:43 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-162-113-129.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.129]) by smtp.gmail.com with ESMTPSA id h6sm117587qtn.51.2021.09.01.09.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 09:07:43 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mLSm7-007sE0-0B; Wed, 01 Sep 2021 13:07:43 -0300 Date: Wed, 1 Sep 2021 13:07:42 -0300 From: Jason Gunthorpe To: David Hildenbrand Cc: Qi Zheng , akpm@linux-foundation.org, tglx@linutronix.de, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, kirill.shutemov@linux.intel.com, mika.penttila@nextfour.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, songmuchun@bytedance.com Subject: Re: [PATCH v2 0/9] Free user PTE page table pages Message-ID: <20210901160742.GR1200268@ziepe.ca> References: <20210819031858.98043-1-zhengqi.arch@bytedance.com> <5b9348fc-95fe-5be2-e9df-7c906e0c9b81@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5b9348fc-95fe-5be2-e9df-7c906e0c9b81@redhat.com> Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=hUCCyoby; spf=pass (imf17.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.219.45 as permitted sender) smtp.mailfrom=jgg@ziepe.ca; dmarc=none X-Stat-Signature: ggiemgjb83fsektennzo9irqz9wg8o61 X-Rspamd-Queue-Id: A1336F000136 X-Rspamd-Server: rspam04 X-HE-Tag: 1630512464-912490 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 Wed, Sep 01, 2021 at 02:32:08PM +0200, David Hildenbrand wrote: > b) pmd_trans_unstable_or_pte_try_get() and friends are really ugly. I suspect the good API here is really more like: ptep = pte_try_map(pmdp, &pmd_value) if (!ptep) { // pmd_value is guarenteed to not be a PTE table pointer. if (pmd_XXX(pmd_value)) } Ie the core code will do whatever stuff, including the THP data race avoidance, to either return the next level page table or the value of a pmd that is not a enxt level page table. Callers are much clearer in this way. Eg this is a fairly representative sample user: static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, struct mm_walk *walk) { if (pmd_trans_unstable(pmd)) goto out; pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); And it is obviously pretty easy to integrate any refcount into pte_try_map and pte_unmap as in my other email. Jason