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.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 039B5C4320E for ; Wed, 1 Sep 2021 16:11:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A4E2A60EE3 for ; Wed, 1 Sep 2021 16:11:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A4E2A60EE3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 3101F900003; Wed, 1 Sep 2021 12:11:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2989B6B0073; Wed, 1 Sep 2021 12:11:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1145A900003; Wed, 1 Sep 2021 12:11:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id F02916B0072 for ; Wed, 1 Sep 2021 12:11:00 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A50861DACE for ; Wed, 1 Sep 2021 16:11:00 +0000 (UTC) X-FDA: 78539493480.22.46E7A92 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 54FAF10000AC for ; Wed, 1 Sep 2021 16:11:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630512659; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mT4QIhya+0xdZYe/0Zyc1Hnz1PU8Nz7fJMWnC7SmgOo=; b=XAUYrMBPoq5sXrerogC+k4AMJCjksictOzTaq+WokV8oaGVnZs5xRngDHee+k3H00UAJVE X3ohyaZAOVz8O/ZyVMaUD2rPtP8vCXVkTQRD/BbWKbFfjxSCBeG6hErro/HT0p//SsfBb7 vpTbzPvG6ad3/x8RpqKQWw36zk3/cB8= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-445-1W3KpWKiNd-TW4lfZARNEw-1; Wed, 01 Sep 2021 12:10:58 -0400 X-MC-Unique: 1W3KpWKiNd-TW4lfZARNEw-1 Received: by mail-wm1-f69.google.com with SMTP id a201-20020a1c7fd2000000b002e748bf0544so26293wmd.2 for ; Wed, 01 Sep 2021 09:10:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=mT4QIhya+0xdZYe/0Zyc1Hnz1PU8Nz7fJMWnC7SmgOo=; b=RsAP0Zo+7YvssnBL58MggWFZgva4/VDDJgpXZrdNWoKyKz6S3mxgAxrx72QRrJfJMh ODY/CWTDJWuPLFHYBpOBiqG2kUbZy80Vl1JZp77g/+hJ5MlINR9AnSxn+vLVOdJqIJS/ e0BB8qOEl+keo5jnnWest+ROmUfvOl//oB1YM0zImmKDn/DP6PIeuiwFCsOR4bTmE/xq woPfBYL8ywTAyqOIKKwBNYMTLTXS2VV/b00bCw2hxv2fFn6d0Mk4THx64dRouwpfiNsQ gAmbux8PjrrfkUEn4qE2Tu3bFJ1uWoxJHOdBXagaUnPER39hb4IoSGSViVZi9t60oLiR 5Dpw== X-Gm-Message-State: AOAM530wDbGku9VnMy82rp5SAw3MyvmLesEffwe9nLdf91bN3XmEP7ct s2uBqnLVKJpew4KYc/Z2pgcgdgrYgosnGov+zU2n5PD8FaTR/4OT9wXBXArknJqvVs3L339U6JF jnZBBVHOHcCI= X-Received: by 2002:adf:9e08:: with SMTP id u8mr78365wre.383.1630512657483; Wed, 01 Sep 2021 09:10:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybwshSMTwTpFwbu/boQ/+Fuo8ShMQQyVxqlM2ZX1sFjop+HUylkUhe8YE6xALeAwPvCgllUA== X-Received: by 2002:adf:9e08:: with SMTP id u8mr78325wre.383.1630512657206; Wed, 01 Sep 2021 09:10:57 -0700 (PDT) Received: from [192.168.3.132] (p4ff23f71.dip0.t-ipconnect.de. [79.242.63.113]) by smtp.gmail.com with ESMTPSA id l17sm1482748wrz.35.2021.09.01.09.10.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Sep 2021 09:10:56 -0700 (PDT) Subject: Re: [PATCH v2 0/9] Free user PTE page table pages To: Jason Gunthorpe 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 References: <20210819031858.98043-1-zhengqi.arch@bytedance.com> <5b9348fc-95fe-5be2-e9df-7c906e0c9b81@redhat.com> <20210901160742.GR1200268@ziepe.ca> From: David Hildenbrand Organization: Red Hat Message-ID: <0d2cb431-bd43-7064-4311-ab541f11fbf8@redhat.com> Date: Wed, 1 Sep 2021 18:10:55 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210901160742.GR1200268@ziepe.ca> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 54FAF10000AC Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XAUYrMBP; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf07.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam01 X-Stat-Signature: i6srwfi6myqkrj4w5o49cj9ozds5zsca X-HE-Tag: 1630512660-328698 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 01.09.21 18:07, Jason Gunthorpe wrote: > 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: That was my exactly my first idea and I tried to rework the code for roughly 2 days and failed. Especially in pagefault logic, we temporarily unmap/unlock to map/lock again later and don't want the page table to just vanish. I think I met similar cases when allocating a page table and not wanting it to vanish and not wanting to map/lock it. But I don't recall all the corner cases: it didn't work for me. > > 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. It didn't work when I tried. -- Thanks, David / dhildenb