From patchwork Fri Oct 11 23:22:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13833257 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 19DC0D0EE3F for ; Fri, 11 Oct 2024 23:23:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FFA36B00B4; Fri, 11 Oct 2024 19:23:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 087D16B00B6; Fri, 11 Oct 2024 19:23:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1E666B00B7; Fri, 11 Oct 2024 19:23:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C0E5A6B00B4 for ; Fri, 11 Oct 2024 19:23:00 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 88261140248 for ; Fri, 11 Oct 2024 23:22:55 +0000 (UTC) X-FDA: 82662898836.02.F06ED48 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf20.hostedemail.com (Postfix) with ESMTP id 4871F1C0012 for ; Fri, 11 Oct 2024 23:22:55 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=rSmkBLLU; spf=pass (imf20.hostedemail.com: domain of 3UbMJZwsKCB446E8LF8SNHAAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--ackerleytng.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3UbMJZwsKCB446E8LF8SNHAAIIAF8.6IGFCHOR-GGEP46E.ILA@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=1728688794; 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=nJE7PzBze7zAcfbdc8FDy9pk9WnzblcaKcmb3qltDsU=; b=F38ibkjeY07r2CVrj9STxNSVI4JYlUwv/ZeQCAhKUzSMaAcFgwuKl69eS6MWBM9FvWl+Wv HNuQ6LTbTD3yRgQMgnhW97TRIZB/lhqZWxvD8ZJH4egfsraxHm3wA4YFWQEi6hf5znjw9J fC6yIXyHVqKB2lQga25c51oYBJbtlh0= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=rSmkBLLU; spf=pass (imf20.hostedemail.com: domain of 3UbMJZwsKCB446E8LF8SNHAAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--ackerleytng.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3UbMJZwsKCB446E8LF8SNHAAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728688794; a=rsa-sha256; cv=none; b=DrHH75sBUU3fNvuuC8XKWL5r7XpTaRoYdoIhK6oPTldOH/A2/irjqu6BMCwbobPDx0eCky GBFtQBImeYQo7FHhDRVevOJZThhyCk7lkzyfYEBvuvaQO3X6Piyd3mq5oUWkwUOogWmf/r KhVwjraMJxdCgiGNKXQZ4S4mQyuBOs8= Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-71e1ed58e9bso2950707b3a.0 for ; Fri, 11 Oct 2024 16:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728688977; x=1729293777; 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=nJE7PzBze7zAcfbdc8FDy9pk9WnzblcaKcmb3qltDsU=; b=rSmkBLLU+gJvtzk9o6fqB0Qa0evie/G/oJUTwuyTqcvgg5S0ERKeI/8b+sWAqpOgyu 6bDjr5kBikUoCyIyX8xwu1oDddy2a+W3EITuWXYiXwH7x2G4W4L1pPsnFhQHy3DqqqQI fV0uIMr4E58OUj9wlhfPPIwPEOIUbV2Y5Y/Drcm2G7rmPX890BVF2GlLJx0dPFVYA+jg 51lsPB9CuUyw9Rdi7Ov+xGHjJm8NhqlBRdeB858w+sIYX1MpUN2AgKvyXdJwRJDo4fLN DDS3xrEMHWWfDRNEP9hFz/RB9OVlIYy1+Sjk5/Fl2lI+Wbh+uS4yOfVDBxxrtYsx0r64 28SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728688977; x=1729293777; 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=nJE7PzBze7zAcfbdc8FDy9pk9WnzblcaKcmb3qltDsU=; b=It0WVHt9Me943a3ZCR95y/XgZ7jW/61KDugPKEJEjEYtUv1Qb4O8vf9GU/JbJ0wRN0 Kh7RqK9uevqwmpKobx01aiNOxdKYNkH0iGfSwGgPizE0nePKK5pgPMVzZRmQ09KkPXdA /Wf6S2M+61sebRU75ffUvvAHvNwSD611frOka6jV0NX93Pzw02SR5g6b6toakHby6FEP 4SS5sGiG6LtU2kGqtr3m8qcxs2hE/I6L2roI5d8pKadTRETPbnxEhPWMj6tTo8MaicbN xbOUzdLDDwhpeMsPqzOnQZRyi0yq/so3Iu54Wo4bppFpTyQdhKMwsAoK88ps+pCovmXe VG8w== X-Forwarded-Encrypted: i=1; AJvYcCX4RlxFgT2ycPMN/1feQtQeAhFKo4aeLMqIeHGtcPLj2og3QUBFFEi6bAYWP6PEb8ghLVb+sm3LLA==@kvack.org X-Gm-Message-State: AOJu0YxUFP9B139u5Ef51MTF8Wr+0cmJ5BZ+Intizxm7ISwrmjQ1JCtR EYXj7+eUkXiUmqidLKdqYdyTxHFe7U2vStOBaY3s7McExsiXa50IP7nVT40wPM/fa6oPx1+dP2L 7nahLhRc18U5a3D8mpvKROg== X-Google-Smtp-Source: AGHT+IF8BpvRbiiW7MMpoPgSGCVrmxKRcOQNff2W1WyN3coN7ji1l7zEFJG8+MRsUOFufoc4FZXZrVo9qdPjRKOSmQ== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:146:b875:ac13:a9fc]) (user=ackerleytng job=sendgmr) by 2002:a05:6a00:870b:b0:71e:4ec7:aed8 with SMTP id d2e1a72fcca58-71e4ec7afb8mr435b3a.6.1728688977169; Fri, 11 Oct 2024 16:22:57 -0700 (PDT) Date: Fri, 11 Oct 2024 23:22:37 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <3d1946d01f63104de913c0979b5a596e2add1672.1728684491.git.ackerleytng@google.com> Subject: [RFC PATCH 2/3] mm: hugetlb: Refactor vma_has_reserves() to should_use_hstate_resv() From: Ackerley Tng To: muchun.song@linux.dev, peterx@redhat.com, akpm@linux-foundation.org, rientjes@google.com, fvdl@google.com, jthoughton@google.com, david@redhat.com Cc: isaku.yamahata@intel.com, zhiquan1.li@intel.com, fan.du@intel.com, jun.miao@intel.com, tabba@google.com, quic_eberman@quicinc.com, roypat@amazon.co.uk, jgg@nvidia.com, jhubbard@nvidia.com, seanjc@google.com, pbonzini@redhat.com, erdemaktas@google.com, vannapurve@google.com, ackerleytng@google.com, pgonda@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4871F1C0012 X-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v6OcEchc/qUdsi3eetWsSDFgSmKel7iK0XgMBzNiGphpyP2+BnuyeuywUzQc/1/vVuLkQ5nQ4AlX5cu4zSj8aG1qmNRXIfIOC3QbmqG01iO48AaLcLjCuLNWPpvjC5b8rbSr5128Xfrg6bpLEo2Np9l3g+MIeUnGMHecsQjGUx1ySClcjrYBQxnFU9SqbxibSF8S6jRqGEbWqxjAHZOOq+lgZURgh40bWKPP+B7OTkTSYhkVhPqsDItAqZNU9v2SQyF0g5diX07Uixayhlp8Va2lgR/pH6Ne9TKgtVqec7hs1QaMGSgQ9hGsffUnTuw2KjY5dspYmHnvKZfBFilwha4EmEf4Qvmf7j9HVGtz3jxBKogA/lZtE365VhGSwSjGY1nPhnYgePS8jQdFm+bqS9iW1NaYZojLOWoW7amj42+LAXrbLMd+0zLIB8L4XzrUUGa7SFFMoEeQ+d7bDm71g0EbglpnQcRqdHl7zfC+fBUWA6gSUNUShncT6emEVeAyDDqKYFFOHaVqrS/popjkDDiyeaYxtQxqbfBVEtmQ3mQPN9pnmdB6jgzG/1DqTsYxghnuqdkObQOX9sGoF4vbyjcq0UHTH2ULrNPdHtlaOdMc9o158iBz X-Bogosity: Ham, tests=bogofilter, spamicity=0.000007, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: With the addition of the chg parameter, vma_has_reserves() no longer just determines whether the vma has reserves. The comment in the vma->vm_flags & VM_NORESERVE block indicates that this function actually computes whether or not the reserved count should be decremented. This refactoring also takes into account the allocation's request parameter avoid_reserve, which helps to further simplify the calling function alloc_hugetlb_folio(). Signed-off-by: Ackerley Tng --- mm/hugetlb.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) -- 2.47.0.rc1.288.g06298d1525-goog diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 73165c670739..47c421eba112 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1246,9 +1246,19 @@ void clear_vma_resv_huge_pages(struct vm_area_struct *vma) hugetlb_dup_vma_private(vma); } -/* Returns true if the VMA has associated reserve pages */ -static bool vma_has_reserves(struct vm_area_struct *vma, long chg) +/* + * Returns true if this allocation should use (debit) hstate reservations, based on + * + * @vma: VMA config + * @chg: Whether the page requirement can be satisfied using subpool reservations + * @avoid_reserve: Whether allocation was requested to avoid using reservations + */ +static bool should_use_hstate_resv(struct vm_area_struct *vma, long chg, + bool avoid_reserve) { + if (avoid_reserve) + return false; + if (vma->vm_flags & VM_NORESERVE) { /* * This address is already reserved by other process(chg == 0), @@ -3025,7 +3035,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, if (ret) goto out_uncharge_cgroup_reservation; - use_hstate_resv = !avoid_reserve && vma_has_reserves(vma, gbl_chg); + use_hstate_resv = should_use_hstate_resv(vma, gbl_chg, avoid_reserve); spin_lock_irq(&hugetlb_lock); folio = dequeue_hugetlb_folio_vma(h, vma, addr, use_hstate_resv);