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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EDE9C46467 for ; Thu, 5 Jan 2023 01:23:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A61648E0002; Wed, 4 Jan 2023 20:23:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9EA5B8E0001; Wed, 4 Jan 2023 20:23:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88A338E0002; Wed, 4 Jan 2023 20:23:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 72AD18E0001 for ; Wed, 4 Jan 2023 20:23:31 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4C016401A6 for ; Thu, 5 Jan 2023 01:23:31 +0000 (UTC) X-FDA: 80318997822.27.BBCC6F2 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by imf04.hostedemail.com (Postfix) with ESMTP id AAD3340003 for ; Thu, 5 Jan 2023 01:23:29 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=I78A5qcp; spf=pass (imf04.hostedemail.com: domain of jthoughton@google.com designates 209.85.221.44 as permitted sender) smtp.mailfrom=jthoughton@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672881809; a=rsa-sha256; cv=none; b=zE6CHNUjRJokpiBXvJwhtV8SEet6VhW+23fjn5G5HLLbtMjBL3PyxuHACuCuFQaJR5uRfN tBJjVYGzE8gkMyVRqtunQB71vOz+8kjZ6sf8S+MysFxWmnWnlLYelJOtKXNisk1k8JJdS7 BpquWddXOyrU1BBJlF9uTGAxSiB2nBE= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=I78A5qcp; spf=pass (imf04.hostedemail.com: domain of jthoughton@google.com designates 209.85.221.44 as permitted sender) smtp.mailfrom=jthoughton@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672881809; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iT+lTm4nI7audT05NuAnB4AV4C6eHB3o7/YvWGrh+hA=; b=eLIOoOuUk+zzAfixk5erlZj0oCNqm9D1VbfF64YOCX4onZg7Ib5CUXK1dPCJYh4OJO6lRV uHpSgKpVFyvLJ56OiU88+uYNUOVS21RUj2BtW6qMzeB81jJlpRszLoDlfEtwMwZQRM+wrT wQvdq3CA0rG02Y/T4g7hsBQ891D35Zw= Received: by mail-wr1-f44.google.com with SMTP id bk16so21549845wrb.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=E6/WxXgwKwGLUyoyyNd+khJX/ZDmnC7iMSnWObYbhiyWLUFHGq8XsbDJyjmGetXx8C NE8P6eY9i9u37Qv6DxqxkrkRa+UP1MuJSLlNcKXZn/eBDWHCGK0skhd4lXRdk4tIpMGA bAWiQ4km4oRy+AeQPATd/PcWVGpBc1gVQdmy3JlSSxWIbc8qQaHp/VBCyhUcka78TBL8 o/owb9vhzHdIMovYtHlTwZ4Qp+SQSOC9FKcZcceMSFUcWth50skcH6Sed9cpeJ2fvhyF y3iwXP7Cwhyspm02BTbckX7zqAibbPHOQq7H/vbCafGkPSvzZVxIEjBbVwUoih5i/PLY C27g== X-Gm-Message-State: AFqh2krz+yLUp2CJSDdec2qpk8K+829BWaUjGRl7kBHiBT9SziczJ1h8 brPDArDivfpbJnePG/K+DW9Geigkk3M3yJw1Gsf9iA== X-Google-Smtp-Source: AMrXdXuCjJh1DhnSeqZjJt2mEorQUVq6WEpzHulaujU5eZ9DJhXGbNqIdpb0w3oOAgcstdnm2/RsVQATjWwZrcuCfYc= 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-Rspam-User: X-Rspamd-Queue-Id: AAD3340003 X-Rspamd-Server: rspam01 X-Stat-Signature: gmoy7cq7azobywkm8wkxrixow19zqpmr X-HE-Tag: 1672881809-126212 X-HE-Meta: U2FsdGVkX1/QaGrvdrjB9PQT0zXZKN0pIsUeTAClYphAOBVc8PDeKErHBjjaVeJ/ee4E7yd00lVh5XrOGaxKtaNNI5zh91s5Q6tv01sSTI0NiN4DH3RVQ7albukPxGltyu5GGk6XGQds5hVtO5++tMvlbNOKC2vXIfs1gqihaMigc5nisLiwD5ibVaYIRJoYshtv9PZpZkFI2o/QuJCd6xexke/OS7AqxsP13CYSCmyode1GgRRy3AOCH5j0rTatLGTo6u8x3fOtKbaajEeGHQEUCn2pCM6YfDMHGQKA341vnabXLk21IRVJI79RqPlfhecQkJh5oaZrbx1TfxfeDZXjdGxR7MVOh8TbWUhMF/LZhfpkrxdHz43YxTXHYvE6n2oqghgJQ1aauN6XqhzUqeClyKIyE1tJLeuXWzozgdQdeKHKI3CjA2g6o0ykHkkf7HRz2tqD9ga8xy9WOGwYEX8Y47WTgXDdfHflDPihJUZsRzGOBiH/aAZ+VITzmD5AqvkLsi6iYv81jryR/h4Tfe2RxBZy8OoxTkTomo/njDJpLCo1a62ECSSZ7wuDgdshif0yXlLyrbM+KCn+eoX/IkbzFb19MjpkxbKU1C0xmAxQaM/mw+qamg7gm6iADQitGrGYiWL3bUjW8S0eOGafuLb7plxQ+SJydsTpzANXLlhI5bl2jsCw3thNh4I0uGGTtDOyIp7GyYZDVNBeiEkjlb8W7sJB5uImwyRovqUMa6bc3HBJkWzNbyqroMdmg7PDZ8VLCnu7arzPDDrqglb+ge0x33gKK/ZA2ito1Nvd64ke99o/rDkNMFVBpfSqblAz5HwYA1b11Gx7I+NSKleJJzejCRslSszqhzYUC3B+mlCUR7L5zM/DWpli84jvLRYkFXan9IRcwBlr3k3BGe47WcaT9zUGPPqXYKDiQTZzm/FN7XVNDwvjZhb5kZaNZYt1cETPF8bAVtqw4pZB2mg yn9grTWk 2zS9nZSQaTRyYsyML/g53R06lY5qZVkMZyxHHPI1WLQr/Kyjo0Mf/ZnQJfQ== 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, 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