Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp195467rwl; Wed, 4 Jan 2023 17:38:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXtxlWYqA3WXIx+hp8HO1q0Rx2B7a/5i/E4dFk58ul9oqHV6IfZX/TMs6KgF0M0nNDkRjaOs X-Received: by 2002:a17:907:80ca:b0:7c1:20ff:c044 with SMTP id io10-20020a17090780ca00b007c120ffc044mr43756962ejc.27.1672882735234; Wed, 04 Jan 2023 17:38:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672882735; cv=none; d=google.com; s=arc-20160816; b=G3yXYoTUNkqdH4GNmDzuWvZqM6GrAIrSdxY2oRlLWkp/eLspquzyea9+rnMWY1qGRU +AptC8+ZjgSCt1Ryo0hkVKrWMaCLR8gy14J9w4dmR7V82gp46gM5bqjSPemDmXPiccEy ozvd3DvroJLMXT+XvVjzbXWg7chkpmBOi8mlybgREO2z8Ua2MMKrzYVGZcrUuBZ4/ylX OBOBtyZja7LVlkJns6YQfVG57s3ttGnscN4pMLeA2yTGc8mBDbc5zTsvLZj6SfNcFd88 7imcCZuWXI4ONmWit8ZBM5FvRvHBAv13y4vz2d1wFZREurGO1CqJwITc8hq6d67cGdPs gmuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=iT+lTm4nI7audT05NuAnB4AV4C6eHB3o7/YvWGrh+hA=; b=ALc/4WUTJEceTx8sesIXu3zJpEKIarBdp6FZqAShESrA+vnyd0+fzqfd2WcqVH9Hfy Y5Eg0Ai7m9JCmqImTi7pJ51XDUt9Vb3HtmBLobHNZ+b11VNh7T8oYnQvJgZDmzuo87vm fygcYrQJxQhscL6Z6xAcn2abNsDKGduZKbmKsEook9krtCGJDAHP3UBUnC+blGjH3b/0 hVRp5Tmm8zAYIZKQPHzWP49gYNoh1TDwIkHV2r9SwuJa16EQiXgD2GiD2iDaWwib3BTZ 1sgtCepW4bzkEXEETOuwQVQP8QYod65QAmv7yQX47WhczHbh+Y8C4AQG4ZHlwveNrMON 79Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=I78A5qcp; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id un2-20020a170907cb8200b007ae2dfe020bsi25217584ejc.783.2023.01.04.17.38.42; Wed, 04 Jan 2023 17:38:55 -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=@google.com header.s=20210112 header.b=I78A5qcp; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230093AbjAEBXh (ORCPT + 56 others); Wed, 4 Jan 2023 20:23:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230342AbjAEBXa (ORCPT ); Wed, 4 Jan 2023 20:23:30 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A29623F11E for ; Wed, 4 Jan 2023 17:23:29 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id bk16so21549843wrb.11 for ; Wed, 04 Jan 2023 17:23:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=iT+lTm4nI7audT05NuAnB4AV4C6eHB3o7/YvWGrh+hA=; b=I78A5qcp7WeJPpPbuyAINFilNEdW+GYeP/LiK0lPPlAr02nSoaPMbXu/0lTPQJPdPc 3vtZz4sEla5pQEjQUFxxxB8UH4tUnhx0Gimo/Mon0vJ3hv6AaNpIzwT0/WXz1Ik832j1 ti++CmRF2I74vS8eW0Shuz6UQefUROY5wYOc8BO6QK9LObYHxwLMCsLNhgRQghBPPUDT bHa6E7ta7Yt5/MDGAYFYP+6A0C1Q7DcFghSIfKTqh/EBOrayq3JqWrP08peDM+n14Uzp oCow0HtpTCCFud1Ku9T/SjRiXN0LkPdOQSN65iznIapMxGAffV78lhpYUsFbGHoqqHjp kTbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iT+lTm4nI7audT05NuAnB4AV4C6eHB3o7/YvWGrh+hA=; b=oo3JLm6aVFD+oElLmv6tWSjQl1bzZe/8KLu7UNxrtqyHf4pxkMypUB4/oEH/s6rLsD 2Fvz+ayUQhnfol0ooo9rw/mUvx4Ylid+6WZ0yKaIE+xt6FmeiGQYhyHYQZyOqIMQwoAL BucxzN+XoE2nfAjRfnzXGXsm0erdAKs5brkiqk1wXaQGbrcyMMyGZx8zrr2Qq/sZ9/Wx FcxNoKOkC2/hvC6Jd7Sj25goFwEZk6Ut56nP/VWxx5qP863EVCHNwVnCOlte7d+y9nUZ uLrbmH0R/8uLB2XXuwrErySUgAS+o980ISq8AE4KgrpupE5Mt8NRF4aBZVGCCoHMm3ns KhvQ== X-Gm-Message-State: AFqh2kqh+ftuA2OXd9PsWpEXsmH0nEc+mVQf9CaR66LoIqtazhTTCDqU zkXLdBGBDdUsxbobkajOMYxcuxRK799pC6JA6/ewVw== X-Received: by 2002:a5d:640b:0:b0:290:ef26:df02 with SMTP id z11-20020a5d640b000000b00290ef26df02mr957635wru.664.1672881808043; Wed, 04 Jan 2023 17:23:28 -0800 (PST) MIME-Version: 1.0 References: <20221021163703.3218176-1-jthoughton@google.com> <20221021163703.3218176-13-jthoughton@google.com> In-Reply-To: From: James Houghton Date: Thu, 5 Jan 2023 01:23:15 +0000 Message-ID: Subject: Re: [RFC PATCH v2 12/47] hugetlb: add hugetlb_hgm_walk and hugetlb_walk_step To: Jane Chu Cc: Mike Kravetz , Muchun Song , Peter Xu , 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Thu, Jan 5, 2023 at 12:58 AM Jane Chu wrote: > > > + * @stop_at_none determines what we do when we encounter an empty PTE. If true, > > + * we return that PTE. If false and @sz is less than the current PTE's size, > > + * we make that PTE point to the next level down, going until @sz is the same > > + * as our current PTE. > [..] > > +int hugetlb_hgm_walk(struct mm_struct *mm, struct vm_area_struct *vma, > > + struct hugetlb_pte *hpte, unsigned long addr, > > + unsigned long sz, bool stop_at_none) > > +{ > [..] > > + while (hugetlb_pte_size(hpte) > sz && !ret) { > > + pte = huge_ptep_get(hpte->ptep); > > + if (!pte_present(pte)) { > > + if (stop_at_none) > > + return 0; > > + if (unlikely(!huge_pte_none(pte))) > > + return -EEXIST; > > If 'stop_at_none' means settling down on the just encountered empty PTE, > should the above two "if" clauses switch order? I thought Peter has > raised this question too, but I'm not seeing a response. A better name for "stop_at_none" would be "dont_allocate"; it will be changed in the next version. The idea is that "stop_at_none" would simply do a walk, and the caller will deal with what it finds. If we can't continue the walk for any reason, just return 0. So in this case, if we land on a non-present, non-none PTE, we can't continue the walk, so just return 0. Another way to justify this order: we want to ensure that calls to this function with stop_at_none=1 and sz=PAGE_SIZE will never fail, and that gives us the order that you see. (This requirement is documented in the comment above the definition of hugetlb_hgm_walk(). This guarantee makes it easier to write code that uses HGM walks.) > Also here below, the way 'stop_at_none' is used when HGM isn't enabled > is puzzling. Could you elaborate please? > > > + if (!hugetlb_hgm_enabled(vma)) { > > + if (stop_at_none) > > + return 0; > > + return sz == huge_page_size(hstate_vma(vma)) ? 0 : -EINVAL; > > + } This is for the same reason; if "stop_at_none" is provided, we need to guarantee that this function won't fail. If "stop_at_none" is false and sz != huge_page_size(), then the caller is attempting to use HGM without having enabled it, hence -EINVAL. Both of these bits will be cleaned up with the next version of this series. :) Thanks! - James