Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1267515rwb; Wed, 16 Nov 2022 14:56:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf5WwOMdV3dMVOAWs0NkHftP3izmx3Bfvxikm0o0rWBPuiB4dazqEkKZ3Sf91c1RwduuATKm X-Received: by 2002:a17:902:c085:b0:17e:802b:fd6e with SMTP id j5-20020a170902c08500b0017e802bfd6emr11341273pld.116.1668639363184; Wed, 16 Nov 2022 14:56:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668639363; cv=none; d=google.com; s=arc-20160816; b=UDK4sMrpSXcoXb47NpIhtOhm/PrY2HlDYKFGAroaXEfyn1NKRdVT8Njcc6MZ+3+K7j cpcEcW2cJTvryONnEbOZM0jC+3BfkY8kqHnIP1WLnbSSlDbVUyWeh7UbsEAJIY6M9m66 9+5+B4b4H4E2RiEMPG0DwYO9yoD1EMcFhft/pI3vDGMS5eE/+O5JHQhrqMJ5lq4DcINb lskYXlKLaSNCo38nY86GhmvCc+TRlde0scV0Ta19lN1YUbUG1okZl/FHtX/VSXmH7sC6 vMZ8YFXfAT+5qFDzrnAEg8xZD6ZmKyXb+seoXmqBnNokB/MEo+Tlo8PilEJSZk5Azbzb lzvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=eLacVH9A13gWTXV0mKgk98a/BsqmzWChzF1U5/Q2nY4=; b=LHeFYRtn/gdLyZw9DcHCnNija10JNPwfL3b69RS7SJ1nPBlccGE0Iyjmuf4rt4lBI9 zoneDDmTl8WiLg3HbGTrblh0T/clYgQIAJ8c1OzS04axJ14rJYLtD3eSflKDSDfhxc2R n4n2+8O8n2YqZ96nbUAju2Lb4zn4npLvUolao0bFbzeqD6qRmn74c8vQtJ/ug9XOAnk1 74GXYOLjJ8/YQ1yhN/P5cdkv/4/Q10FuNZu3CepaX0wu0psm3LXSPmtT42pNtXr8+wtP SLNi9rvYGtWKJoDN86Q2CsClI764YnZvU762mBsBVbZ7n3jU3eAfY+UdP4QjJK+Ms8r5 /lxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WsHo4+p1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a6540cb000000b00476e62744a8si3310971pgp.388.2022.11.16.14.55.51; Wed, 16 Nov 2022 14:56:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WsHo4+p1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234328AbiKPWTC (ORCPT + 90 others); Wed, 16 Nov 2022 17:19:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231734AbiKPWTA (ORCPT ); Wed, 16 Nov 2022 17:19:00 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE1E85BD7D for ; Wed, 16 Nov 2022 14:18:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668637087; 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: in-reply-to:in-reply-to:references:references; bh=eLacVH9A13gWTXV0mKgk98a/BsqmzWChzF1U5/Q2nY4=; b=WsHo4+p1fhTFuRdF1tJPoPlCdJySXZ+961ogc5J8PgIh8yoQiKQeK/L0dzBxoE612UdxmT G/GULdDqoXieknkWNC54EdFplYPPtqm+YUv801zwmMik90T0dl68M6d3qhd8TDelU5Mmab 20SfNo+bN+DVKcGrZy/aU0ZS05noHc4= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-10-qiXQclMqPZq8TS62i3wjew-1; Wed, 16 Nov 2022 17:18:05 -0500 X-MC-Unique: qiXQclMqPZq8TS62i3wjew-1 Received: by mail-qt1-f198.google.com with SMTP id y19-20020a05622a121300b003a526e0ff9bso31425qtx.15 for ; Wed, 16 Nov 2022 14:18:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=eLacVH9A13gWTXV0mKgk98a/BsqmzWChzF1U5/Q2nY4=; b=5wj2lerKvfOm54UAPspWVUFlu9vYotijot4VJPbuhqJW1bZAN0drOdcIhJnpL9BWPM FYSwvqGaO3u9xEig2pjnw4rwBXelJAv58C3Tldgw9FpiBkDWsXi1JZAv1H5W3tB5C4Gw OMnjZ8NXUrXA4NpiUYGjAiar/AqaxUZft/t3/Ab40+gPuOMALGDVhxHKCXH0Ig8yYvQr L7Qp2AJOX/kT3gMjkVVsJa3ry8Bw1kSxlfYhJ3Dh6uBPjk6HlxGx3bSbv4x3GAuWdqO5 A9vLV3nw1NwEz52wKpETcGv6yLoMpH62ZjCnzRYv3CoD8cf+pYJWUGfK/cs8otOP2bJP zCkg== X-Gm-Message-State: ANoB5pmpxyq9GsucNlDxpmeyj48nMSUR40KS0On3o72v9TUIKcSLtExn I3/bcl29w+tZyU9ML+7hxqWVSKXoXPgb/GewDnRFgYA43yh4osMKrKu1v8PZY1VqmCZzq6Pi9Fu EmuM1VUlh/u4kIjW35sfU3tqt X-Received: by 2002:ac8:44ab:0:b0:3a5:4859:8176 with SMTP id a11-20020ac844ab000000b003a548598176mr23466901qto.478.1668637085205; Wed, 16 Nov 2022 14:18:05 -0800 (PST) X-Received: by 2002:ac8:44ab:0:b0:3a5:4859:8176 with SMTP id a11-20020ac844ab000000b003a548598176mr23466874qto.478.1668637084937; Wed, 16 Nov 2022 14:18:04 -0800 (PST) Received: from x1n (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id h21-20020ac846d5000000b003a4f22c6507sm9441673qto.48.2022.11.16.14.18.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Nov 2022 14:18:00 -0800 (PST) Date: Wed, 16 Nov 2022 17:17:59 -0500 From: Peter Xu To: James Houghton Cc: Mike Kravetz , Muchun Song , David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , Zach O'Keefe , Manish Mishra , Naoya Horiguchi , "Dr . David Alan Gilbert" , "Matthew Wilcox (Oracle)" , Vlastimil Babka , Baolin Wang , Miaohe Lin , Yang Shi , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH v2 10/47] hugetlb: add hugetlb_pte to track HugeTLB page table entries Message-ID: References: <20221021163703.3218176-1-jthoughton@google.com> <20221021163703.3218176-11-jthoughton@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221021163703.3218176-11-jthoughton@google.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 21, 2022 at 04:36:26PM +0000, James Houghton wrote: > +struct hugetlb_pte { > + pte_t *ptep; > + unsigned int shift; > + enum hugetlb_level level; > + spinlock_t *ptl; > +}; Do we need both shift + level? Maybe it's only meaningful for ARM where the shift may not be directly calculcated from level? I'm wondering whether we can just maintain "shift" then we calculate "level" realtime. It just reads a bit weird to have these two fields, also a burden to most of the call sites where shift and level exactly match.. > + > +static inline > +void hugetlb_pte_populate(struct hugetlb_pte *hpte, pte_t *ptep, > + unsigned int shift, enum hugetlb_level level) I'd think it's nicer to replace "populate" with something else, as populate is definitely a meaningful word in vm world for "making something appear if it wasn't". Maybe hugetlb_pte_setup()? Even one step back, on the naming of hugetlb_pte.. Sorry to comment on namings especially on this one, I really don't like to do that normally.. but here hugetlb_pte only walks the sub-page level of pgtables, meanwhile it's not really a pte but an iterator. How about hugetlb_hgm_iter? "hgm" tells that it only walks sub-level, and "iter" tells that it is an iterator, being updated for each stepping downwards. Then hugetlb_pte_populate() can be hugetlb_hgm_iter_init(). Take these comments with a grain of salt, and it never hurts to wait for a 2nd opinion before anything. > +{ > + WARN_ON_ONCE(!ptep); > + hpte->ptep = ptep; > + hpte->shift = shift; > + hpte->level = level; > + hpte->ptl = NULL; > +} > + > +static inline > +unsigned long hugetlb_pte_size(const struct hugetlb_pte *hpte) > +{ > + WARN_ON_ONCE(!hpte->ptep); > + return 1UL << hpte->shift; > +} > + > +static inline > +unsigned long hugetlb_pte_mask(const struct hugetlb_pte *hpte) > +{ > + WARN_ON_ONCE(!hpte->ptep); > + return ~(hugetlb_pte_size(hpte) - 1); > +} > + > +static inline > +unsigned int hugetlb_pte_shift(const struct hugetlb_pte *hpte) > +{ > + WARN_ON_ONCE(!hpte->ptep); > + return hpte->shift; > +} > + > +static inline > +enum hugetlb_level hugetlb_pte_level(const struct hugetlb_pte *hpte) > +{ > + WARN_ON_ONCE(!hpte->ptep); There're definitely a bunch of hpte->ptep WARN_ON_ONCE()s.. AFAIK the hugetlb_pte* will be setup once with valid ptep and then it should always be. I rem someone commented on these helpers look not useful, which I must confess I had the same feeling. But besides that, I'd rather drop all these WARN_ON_ONCE()s but only check it when init() the iterator/pte. > + return hpte->level; > +} > + > +static inline > +void hugetlb_pte_copy(struct hugetlb_pte *dest, const struct hugetlb_pte *src) > +{ > + dest->ptep = src->ptep; > + dest->shift = src->shift; > + dest->level = src->level; > + dest->ptl = src->ptl; > +} > + > +bool hugetlb_pte_present_leaf(const struct hugetlb_pte *hpte, pte_t pte); > + > struct hugepage_subpool { > spinlock_t lock; > long count; > @@ -1210,6 +1279,25 @@ static inline spinlock_t *huge_pte_lock(struct hstate *h, > return ptl; > } > > +static inline > +spinlock_t *hugetlb_pte_lockptr(struct mm_struct *mm, struct hugetlb_pte *hpte) > +{ > + > + BUG_ON(!hpte->ptep); Another BUG_ON(); better be dropped too. > + if (hpte->ptl) > + return hpte->ptl; > + return huge_pte_lockptr(hugetlb_pte_shift(hpte), mm, hpte->ptep); I'm curious whether we can always have hpte->ptl set for a valid hugetlb_pte. I think that means we'll need to also init the ptl in the init() fn of the iterator. Then it'll be clear on which lock to take for each valid hugetlb_pte. > +} -- Peter Xu