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 BCFEEC3ABDA for ; Wed, 14 May 2025 23:44:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 95B5C6B00D8; Wed, 14 May 2025 19:43:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E3686B00D9; Wed, 14 May 2025 19:43:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7368D6B00DA; Wed, 14 May 2025 19:43:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 52A776B00D8 for ; Wed, 14 May 2025 19:43:25 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 79BEBC11C0 for ; Wed, 14 May 2025 23:43:26 +0000 (UTC) X-FDA: 83443142412.24.DA9E3D4 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf23.hostedemail.com (Postfix) with ESMTP id ABF1F140002 for ; Wed, 14 May 2025 23:43:24 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=uaXraZxu; spf=pass (imf23.hostedemail.com: domain of 3myolaAsKCMwsu2w93wGB5yy66y3w.u64305CF-442Dsu2.69y@flex--ackerleytng.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3myolaAsKCMwsu2w93wGB5yy66y3w.u64305CF-442Dsu2.69y@flex--ackerleytng.bounces.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=1747266204; 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=E26Tl2T4mfZ/m1IX0grkZCH7fXFwkgs13AgMIoZPWuo=; b=sXUHapB5DyezKnNbAeuNdLPQ8WuYKoYQ2lqF4u/MAfCQa0ggticKge4+CN5RAR3F/UHDgr JOJu0izvoYi9wXttbOKPd6++p+rGdlsbd9e3/iRe9N6qVFbrzVZwNfdxeQJp0CRSVNIPSY Lxm7h3sYBNWd1hQjTEepAhkE7bUVgj0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=uaXraZxu; spf=pass (imf23.hostedemail.com: domain of 3myolaAsKCMwsu2w93wGB5yy66y3w.u64305CF-442Dsu2.69y@flex--ackerleytng.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3myolaAsKCMwsu2w93wGB5yy66y3w.u64305CF-442Dsu2.69y@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1747266204; a=rsa-sha256; cv=none; b=uTKr1/Iylmmv7MSo6BnFh7eCYpBoVkDl3CJZx8gzH+fNNDgP5a+kLpGPJsodrw1wpddH7q oxiX8cqoHEu7Vyj9ojwAOgIwgOBGwvoPWl3gX1P8BC+dLlwTLdEZplI4TuOqSOHkG0UgCN zhyDhEmJ0PXCrs8Dreoy4usXQ4jxYxc= Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b0ae9e87fe2so1139368a12.0 for ; Wed, 14 May 2025 16:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1747266203; x=1747871003; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=E26Tl2T4mfZ/m1IX0grkZCH7fXFwkgs13AgMIoZPWuo=; b=uaXraZxuo1DT4b5J7J8QbFBUvSWLtRY43bUuc2F7J+3ThO1/ZFwdceH9DuJzIfuxYH g2hjZKdg1+N7uXeajvhXKJ8eOoRTyGJuqOMkrfXTAiCMyrNj/MmMnIuM9bsymhoTW0vs Yy3bdrCzyQepO7nC7tLbgY5YKCI9N4rNtr8E/UXXoytdXavpGUoYfL7XAe450JABPZxB nSwHId2akSp+k7slwSgMPl6RvXwMBeZ9NpVaiHIvvYWBZjqsAoGsR0GXRVOTooM+70YP P2Bm2Zv3cZiwAB1s3g7k9CWe+iXKbI+O892NAMOsFZC/8rsLsgO6gAm16QLSGoifIYDC VF4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747266203; x=1747871003; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=E26Tl2T4mfZ/m1IX0grkZCH7fXFwkgs13AgMIoZPWuo=; b=YQfk3BVGSXEaCmreYxvcyX+7Pl2mGxKxWu/NrvnSY6GNWgY2b8jDfZkcTKYOkwhkOO YKm6uvL2DHGaz8uf8fN27uwyjTSZJbS46a7sMcPcevCQiim+1K0y6qLqVANZm1TUpHDa cr/qH2/4ivgqDGLVqRc2dAfPSEei0q554CjY+sA05MHitb1ODX0qvgGwKzuMDAJ260bj wkzIXlo2AdgBLza6j3Uk6U5XI+0gruuol7idw0Amhoa7EIbgYywV/TvCArkYVwFGj24Y FqhmOTR1m8Lfa1j8bFChzEGG7nRLU4nROaLeWKNeljagrjtcLqD3TVPJ5Oq6wVfAcUAl 46FQ== X-Forwarded-Encrypted: i=1; AJvYcCVwLf6sTcBZ+Jd9zqIk8PMreLPe+Bhe+VfDzoMN64A+PoYZ1yE0nTOOjzOgdtQnYS/xLXhdOr1TeA==@kvack.org X-Gm-Message-State: AOJu0YyRpuK19V5wIV8SA6YvSRTNcd0H/nRY+HKlgtU3Ksp7JwMKd+P/ RkHqi9WqSh5Da5j9Ljq/n1210qTu+4aAsmOJeeERnVr2+t9WiGg43eLCapSfYDoMAjwiEFrpuq6 z0cweCMDu7Vc/EnfTBZHW1h64Ew== X-Google-Smtp-Source: AGHT+IGGAEb3QlUf/WhLCRTxvufYT1iGlYd55goOcpCx/3NfQyHKKzpB2yIq1YSNBW8KeC+O0YA7TSeUeA6QlfAJtA== X-Received: from pjbpb18.prod.google.com ([2002:a17:90b:3c12:b0:2f5:63a:4513]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2d84:b0:2fc:aaf:74d3 with SMTP id 98e67ed59e1d1-30e4daca157mr2160148a91.4.1747266203512; Wed, 14 May 2025 16:43:23 -0700 (PDT) Date: Wed, 14 May 2025 16:41:56 -0700 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.49.0.1045.g170613ef41-goog Message-ID: Subject: [RFC PATCH v2 17/51] mm: hugetlb: Cleanup interpretation of gbl_chg in alloc_hugetlb_folio() From: Ackerley Tng To: kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-fsdevel@vger.kernel.org Cc: ackerleytng@google.com, aik@amd.com, ajones@ventanamicro.com, akpm@linux-foundation.org, amoorthy@google.com, anthony.yznaga@oracle.com, anup@brainfault.org, aou@eecs.berkeley.edu, bfoster@redhat.com, binbin.wu@linux.intel.com, brauner@kernel.org, catalin.marinas@arm.com, chao.p.peng@intel.com, chenhuacai@kernel.org, dave.hansen@intel.com, david@redhat.com, dmatlack@google.com, dwmw@amazon.co.uk, erdemaktas@google.com, fan.du@intel.com, fvdl@google.com, graf@amazon.com, haibo1.xu@intel.com, hch@infradead.org, hughd@google.com, ira.weiny@intel.com, isaku.yamahata@intel.com, jack@suse.cz, james.morse@arm.com, jarkko@kernel.org, jgg@ziepe.ca, jgowans@amazon.com, jhubbard@nvidia.com, jroedel@suse.de, jthoughton@google.com, jun.miao@intel.com, kai.huang@intel.com, keirf@google.com, kent.overstreet@linux.dev, kirill.shutemov@intel.com, liam.merwick@oracle.com, maciej.wieczor-retman@intel.com, mail@maciej.szmigiero.name, maz@kernel.org, mic@digikod.net, michael.roth@amd.com, mpe@ellerman.id.au, muchun.song@linux.dev, nikunj@amd.com, nsaenz@amazon.es, oliver.upton@linux.dev, palmer@dabbelt.com, pankaj.gupta@amd.com, paul.walmsley@sifive.com, pbonzini@redhat.com, pdurrant@amazon.co.uk, peterx@redhat.com, pgonda@google.com, pvorel@suse.cz, qperret@google.com, quic_cvanscha@quicinc.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, quic_svaddagi@quicinc.com, quic_tsoni@quicinc.com, richard.weiyang@gmail.com, rick.p.edgecombe@intel.com, rientjes@google.com, roypat@amazon.co.uk, rppt@kernel.org, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, steven.sistare@oracle.com, suzuki.poulose@arm.com, tabba@google.com, thomas.lendacky@amd.com, usama.arif@bytedance.com, vannapurve@google.com, vbabka@suse.cz, viro@zeniv.linux.org.uk, vkuznets@redhat.com, wei.w.wang@intel.com, will@kernel.org, willy@infradead.org, xiaoyao.li@intel.com, yan.y.zhao@intel.com, yilun.xu@intel.com, yuzenghui@huawei.com, zhiquan1.li@intel.com Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: wrfa8ffqa9c3jn7p39et749xo1o5amfe X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: ABF1F140002 X-HE-Tag: 1747266204-119843 X-HE-Meta: U2FsdGVkX1+FFFcCxstqAneLe6bdIeOs5n8Cc8nk7tGzEgbRzYyvMYrpedkkA8di/Ool6lWuT2qKHr2Ofd5V6gVha7c2lk/ynsCne9PV0J8ISO7YLzPMxI6yB/z3dhcCPkswb1F1Imar4ArGXvIxZvb1c5d2BQz6FvYWHpbvd9HV6C+khea4T9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y/xV82REI/sBKTMpg8Blb6EV7t2k8REuQWApZsoRhnkZK542ExbGaSEgVl/AjlIRVQaDhhnYo0wmV8/OpTHboWncGoLRK9m3YG8JcEeDGzg0GnPpfZlUKAv5dFF5dIvvxWOqbloKoxtja7QetnwYmWUhkvruQdpEiSx+3FyDqTh6Ap7cx6ZhyeEG02ULPqbNF7Or8qriuQToKyzVs7S77jWknKZZJdVhB6NlSfa7ATeLdy23STs6mj7ZU+YaN6LbLBwcJ+V5srKd7F8Yh12hQakauXfBs4ZER2HG8iYifTaqcniZ8Dga53rere781asdT6+6EZj3mH6qfGM7wZfyW9RPWRAFwnxxR4YjfjOOwsRdYQEu6KNxcS653mELzkjZzd+0tXzW3/djdc3+jE5Vy1tXQNH8g2KKG/11tlb5AIjgZLfFhBTPdUKN20EHnx4xcgyE= 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: List-Subscribe: List-Unsubscribe: The comment before dequeuing a folio explains that if gbl_chg == 0, a reservation exists for the allocation. In addition, if a vma reservation exists, there's no need to get a reservation from the subpool, and gbl_chg was set to 0. This patch replaces both of that with code: subpool_reservation_exists defaults to false, and if a vma reservation does not exist, a reservation is sought from the subpool. Then, the existence of a reservation, whether in the vma or subpool, is summarized into reservation_exists, which is then used to determine whether to dequeue a folio. Signed-off-by: Ackerley Tng Change-Id: I52130a0bf9f33e07d320a446cdb3ebfddd9de658 --- mm/hugetlb.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index b843e869496f..597f2b9f62b5 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2999,8 +2999,10 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, { struct hugepage_subpool *spool = subpool_vma(vma); struct hstate *h = hstate_vma(vma); + bool subpool_reservation_exists; + bool reservation_exists; struct folio *folio; - long retval, gbl_chg; + long retval; map_chg_state map_chg; int ret, idx; struct hugetlb_cgroup *h_cg = NULL; @@ -3036,17 +3038,16 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, * that the allocation will not exceed the subpool limit. * Or if it can get one from the pool reservation directly. */ + subpool_reservation_exists = false; if (map_chg) { - gbl_chg = hugepage_subpool_get_pages(spool, 1); - if (gbl_chg < 0) + int npages_req = hugepage_subpool_get_pages(spool, 1); + + if (npages_req < 0) goto out_end_reservation; - } else { - /* - * If we have the vma reservation ready, no need for extra - * global reservation. - */ - gbl_chg = 0; + + subpool_reservation_exists = npages_req == 0; } + reservation_exists = !map_chg || subpool_reservation_exists; /* * If this allocation is not consuming a per-vma reservation, @@ -3065,13 +3066,8 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, spin_lock_irq(&hugetlb_lock); - /* - * gbl_chg == 0 indicates a reservation exists for the allocation - so - * try dequeuing a page. If there are available_huge_pages(), try using - * them! - */ folio = NULL; - if (!gbl_chg || available_huge_pages(h)) + if (reservation_exists || available_huge_pages(h)) folio = dequeue_hugetlb_folio(h, vma, addr); if (!folio) { @@ -3089,7 +3085,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, * Either dequeued or buddy-allocated folio needs to add special * mark to the folio when it consumes a global reservation. */ - if (!gbl_chg) { + if (reservation_exists) { folio_set_hugetlb_restore_reserve(folio); h->resv_huge_pages--; } -- 2.49.0.1045.g170613ef41-goog