From patchwork Tue Sep 10 23:43: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: 13799479 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 8A70CEE01F1 for ; Tue, 10 Sep 2024 23:44:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B8328D00D1; Tue, 10 Sep 2024 19:44:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6690F8D0002; Tue, 10 Sep 2024 19:44:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BA748D00D1; Tue, 10 Sep 2024 19:44:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2AA938D0002 for ; Tue, 10 Sep 2024 19:44:46 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A3F3E140358 for ; Tue, 10 Sep 2024 23:44:45 +0000 (UTC) X-FDA: 82550460930.14.49099A0 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf06.hostedemail.com (Postfix) with ESMTP id C3000180002 for ; Tue, 10 Sep 2024 23:44:43 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tbbyyuhC; spf=pass (imf06.hostedemail.com: domain of 36tngZgsKCF879HBOIBVQKDDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--ackerleytng.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=36tngZgsKCF879HBOIBVQKDDLLDIB.9LJIFKRU-JJHS79H.LOD@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=1726011856; 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=A2/Y6gthU1MbFrUehJ3S769Qii4LzOP83N9oJxSMzr4=; b=VdbVKYNABPXAV/Qsr3EpL45DK0lnqhVzM2kr2WejZUye7XuHbO/yifXpcwxe7vPtMyl9zx u7cxhqZat4LCZuzu4GJbPizmMHiGkS/Jzb7hCLmuqatw23uRSkNPDb3NrDWWLV3BdWUqoH oX/SZ09DUixieRxH5GfepLYO89JYz5s= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tbbyyuhC; spf=pass (imf06.hostedemail.com: domain of 36tngZgsKCF879HBOIBVQKDDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--ackerleytng.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=36tngZgsKCF879HBOIBVQKDDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726011856; a=rsa-sha256; cv=none; b=3Q8UAhaoSCFyVHiAY+p2vcM9b0PnCT3bTKYx8PfRMqOEE2kh5bds8qgb7CL5qqw+7oPL6i M1M1HjhKQ13DtuE9oBawcQHY8tQ+pQPqKDLVTOdv+7wRWyYJbqSM8F/TIyVS5x7NJbxiqQ cJr2aCBTY26pwxYBEKZvI02+nxVZdss= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6b47ff8a5c4so205361367b3.2 for ; Tue, 10 Sep 2024 16:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726011883; x=1726616683; 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=A2/Y6gthU1MbFrUehJ3S769Qii4LzOP83N9oJxSMzr4=; b=tbbyyuhCb9o2N5++Ot2dV1psVi0SGogtCUP0IgVvr3Lgen8tV8SLsMv/SsABfoN7Ag qHoN279Da8JT6tg3oI2Po3wcW2jnVAM+Qv4KQcvMu1Y3ZeVh0oZZBT7PWF0UnS7AfU2Q R0Mnvx5uk6lH1eCVYLizEn1NbFQ0Of/qkbiJjtnokPidJy3g4YDXiCfESTnzXG+rgvhT gdosnN2o5Nj4YNVLi59/6Moqh+lI3wcHEXNwIOTnKpE+8loMNJHQUa5pev2wCXvVdG6U TU3lfVdVcxvObfQniRltucBdwquR6kfp2x6psziKLwyASw0qtQs8fs9+k3Y0HNd8SoCj OQfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726011883; x=1726616683; 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=A2/Y6gthU1MbFrUehJ3S769Qii4LzOP83N9oJxSMzr4=; b=QEseundl8IRkiZhzAhypKMl1XVSPCOY3KsJslZQOHjXDG2Q4NKU3smrngCsZ15hcfX hUO3icUWhVNxvbkUlbmEtp0Twa+rN7wHKNzIKhH8oV1fgPDpcB5+FrmE+hKB5BPn25+f 79tuHgJSvLGMFsFwhXx6ur5Gov9VTkSJv0YBLuLjx1iX+aGUKf3ohP4KH4kJN/5BwUUF 31Q6hH9VDfQC7dO2ioADZEN9sAMb/erwXcDd0XO1TJ4qsq33PxTfMpYJdi5+JA5UjTZe j7XGGfMyQBSt9jqbVT+E5lD57ChwNZmd1aIFrHqpVshWbA35b4hTv0hyZcTIxM+hg9mw pYeA== X-Forwarded-Encrypted: i=1; AJvYcCWqISGqMKWEAW4HVk+WoWr4NR6/H3TxPFh4cpBA90b88tZ8xGNkrLkr9xObxpa7xt0+NhGd1A91Ug==@kvack.org X-Gm-Message-State: AOJu0YwrKDwo53jKzTxApHxatKlVWGqtVvr1MAq/3rB7KkPIwskFuH6g qwEbr4l9bZhJBF1q1FMl3C5NqosnNSPPqBDr+e/c9Z6j5WVL3nh7hVKU/FWsx3bRk8kHSzhvodg 8d374FajyRbd8RdilVFXAZQ== X-Google-Smtp-Source: AGHT+IFPoUvOh1q0B66QYZI1YuXyVP47nvXVDhT/pcsOhAfzJk8Td8wo+BQHvkUkT8CnKxYbBRP+4EVLJOXxK7IwcA== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:13f8]) (user=ackerleytng job=sendgmr) by 2002:a05:690c:360c:b0:6db:7b3d:b414 with SMTP id 00721157ae682-6db7b3db573mr3408167b3.0.1726011882893; Tue, 10 Sep 2024 16:44:42 -0700 (PDT) Date: Tue, 10 Sep 2024 23:43:37 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <2e9109761869029bf82555e60d98850ac7888ae5.1726009989.git.ackerleytng@google.com> Subject: [RFC PATCH 06/39] mm: hugetlb: Refactor dequeue_hugetlb_folio_vma() to use mpol From: Ackerley Tng To: tabba@google.com, quic_eberman@quicinc.com, roypat@amazon.co.uk, jgg@nvidia.com, peterx@redhat.com, david@redhat.com, rientjes@google.com, fvdl@google.com, jthoughton@google.com, seanjc@google.com, pbonzini@redhat.com, zhiquan1.li@intel.com, fan.du@intel.com, jun.miao@intel.com, isaku.yamahata@intel.com, muchun.song@linux.dev, mike.kravetz@oracle.com Cc: erdemaktas@google.com, vannapurve@google.com, ackerleytng@google.com, qperret@google.com, jhubbard@nvidia.com, willy@infradead.org, shuah@kernel.org, brauner@kernel.org, bfoster@redhat.com, kent.overstreet@linux.dev, pvorel@suse.cz, rppt@kernel.org, richard.weiyang@gmail.com, anup@brainfault.org, haibo1.xu@intel.com, ajones@ventanamicro.com, vkuznets@redhat.com, maciej.wieczor-retman@intel.com, pgonda@google.com, oliver.upton@linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-fsdevel@kvack.org X-Rspam-User: X-Stat-Signature: nsa9jxzjmqgxfgz4uqs5b1tfyqdc5gqt X-Rspamd-Queue-Id: C3000180002 X-Rspamd-Server: rspam11 X-HE-Tag: 1726011883-99627 X-HE-Meta: U2FsdGVkX1+QztZoNkfgl3wt5XriQjD03mA5dSfRs9qdY6KST6ds0UsqtC+P41cgXUO2L8Oxpc5puuKOYuE/+XzATDJxISoAu+LyjyfBiuY0pN3Nr/5/YruS05b6KfP9LtOOZP00MXHWw6OaKTlzjMSizuVQiJSDkZSjHLHklimaH2HO+Et2oPrVnKXklR7DmwSz/r+zAF+Xj9fSpAqGBmAMOmIOJCgOjQPEQUqWh4d1FCW9crdJlKSMfz3FjTBWcu90BMVh6kEQeW01j+BcmqExVKm/OpHeYT0QlMKNQ2QJ6KM7VS1dsghcZumOJvH3MJwEFnXlxgRvYBdAfqgp1ahXEouqFnhoCZ5bH/He04smb3lIpPPMaxVlngwQHgEjmrO+z2LbuWWgLw0DgkO08WCfFBMfenyZo2z+X5Z5De5PXYNhEuheZC+8cKJC7MIlGxph2q2mwQmIfkRAb5evaQ+EzqNyODVJTOnEBUNXgMvaxrOe8bW3AS8PH/ub12vriwc/sNGTGZsQNNcVKz4PzOW25AbxZFwhHBXAMXp5EggzXNKW8DUF8dkCxzrIm05hvmpqYYbhPm/zfFBar+xSXh0+yfyaR+uuT+aQj/sQ8KAhKluZzJfi7GYgEog5urahBsd8iM0h9mPJCOgyuQ++uvX25svi3WBbim2CMIHGduXGNCk/QhtEIAcXKaiwk14/J2h67D8p0G2iZZd0+Ykp0b2/9P0mX0H1spO3larXtS9CJ7RV83C112YPZU5qruE5L8m9zb6FXfj4lJGWK38JWtCdKVlpRm3yqNE4GfEuYQhC+YeCR4a2wKcEp1TfXngMD6K5hkSyDorXC+FwL3h8NE9E77IscjgYdZwB1X6X7gMl+DXW81pWatUZ7Ss5dRS66RbrhCMyA83CL1LWcF/W0VqzYjR+GEK05mdHYvqKBa6PAjW/atN7OgybSbdJ5Q3dhVcj6SD78YUCFmkD1x3 YwclwxMs xEpC3EKo9U/foZadr9cieeWCv8Rdgu4oiM/YCM4eETi23VEEeaMh4e7YJi+gg+V0EE4QrPdOzzp+egzIPV9wp5wXCFxThqySS5I5sNKUqj4HxMO4h/b2OcgraRaR1b8T/xTsMW4Pch9d68D2kILrxtRAWyeEVCC3cMmvQ3SG2WtFaP6HMNgKKdmUD8ZI9WicLJW//z+Y6QyjM8vI3W4og2VF2LbcRW9KTIasvBcpSSgShnmTrAWZG1qbKPo8duEkpODW50YOngoE95IRrZW1pQpbcBgOqpOSs9LRXWF4ZiWRukb6bPotRsDlBJQvFs4y2Ypv9UH8th3st+lvHWtB9wwv1SGQgEyIpsXIdkFWUGR8ZXFuEHIVBEHow6s8/zFrpFLpKswFXuP66HfndWYPgAWeLU0m3hnVDTHdNrQdqKQ4n2U0alhf6uYdqJdV7Hez/lYFP+c80p94GJRUWvRxbjoS4ALuAXsEWv/agfIz8P9qXkpWkwcsVwubYTdRjFHuFw5ZgMBBrKYjaUw4AS/aiGJD89KM9diixEjzjYagtFtFpAzkioanSPEi4GKGnlxgzWkpXIR292eWqwPA/7hAJn1+0bj7vquK0iDOqlykTrCe8V9SIN/bKK6SYcwvKd60Y6iqx4yPyp0EB1cipL6Mc7ldeMcTR79A+qeSmXduOmLlqu+/frmusnB0utTxFPAyfXEp3 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000202, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Reduce dependence on vma since the use of huge_node() assumes that the mempolicy is stored in a specific place in the inode, accessed via the vma. Signed-off-by: Ackerley Tng --- mm/hugetlb.c | 55 ++++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 2f2bd2444ae2..e341bc0eb49a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1402,44 +1402,33 @@ static unsigned long available_huge_pages(struct hstate *h) return h->free_huge_pages - h->resv_huge_pages; } -static struct folio *dequeue_hugetlb_folio_vma(struct hstate *h, - struct vm_area_struct *vma, - unsigned long address, bool use_hstate_resv) +static struct folio *dequeue_hugetlb_folio(struct hstate *h, + struct mempolicy *mpol, int nid, + nodemask_t *nodemask, + bool use_hstate_resv) { struct folio *folio = NULL; - struct mempolicy *mpol; gfp_t gfp_mask; - nodemask_t *nodemask; - int nid; if (!use_hstate_resv && !available_huge_pages(h)) - goto err; + return NULL; gfp_mask = htlb_alloc_mask(h); - nid = huge_node(vma, address, gfp_mask, &mpol, &nodemask); - if (mpol_is_preferred_many(mpol)) { - folio = dequeue_hugetlb_folio_nodemask(h, gfp_mask, - nid, nodemask); + if (mpol_is_preferred_many(mpol)) + folio = dequeue_hugetlb_folio_nodemask(h, gfp_mask, nid, nodemask); - /* Fallback to all nodes if page==NULL */ - nodemask = NULL; + if (!folio) { + /* Fallback to all nodes if earlier allocation failed */ + folio = dequeue_hugetlb_folio_nodemask(h, gfp_mask, nid, NULL); } - if (!folio) - folio = dequeue_hugetlb_folio_nodemask(h, gfp_mask, - nid, nodemask); - if (folio && use_hstate_resv) { folio_set_hugetlb_restore_reserve(folio); h->resv_huge_pages--; } - mpol_cond_put(mpol); return folio; - -err: - return NULL; } /* @@ -3131,6 +3120,10 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, bool deferred_reserve; gfp_t gfp = htlb_alloc_mask(h) | __GFP_RETRY_MAYFAIL; bool use_hstate_resv; + struct mempolicy *mpol; + nodemask_t *nodemask; + pgoff_t ilx; + int nid; memcg = get_mem_cgroup_from_current(); memcg_charge_ret = mem_cgroup_hugetlb_try_charge(memcg, gfp, nr_pages); @@ -3184,22 +3177,19 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, 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); - if (!folio) { - struct mempolicy *mpol; - nodemask_t *nodemask; - pgoff_t ilx; - int nid; + mpol = get_vma_policy(vma, addr, hstate_vma(vma)->order, &ilx); + nid = policy_node_nodemask(mpol, htlb_alloc_mask(h), ilx, &nodemask); + folio = dequeue_hugetlb_folio(h, mpol, nid, nodemask, use_hstate_resv); + if (!folio) { spin_unlock_irq(&hugetlb_lock); - mpol = get_vma_policy(vma, addr, hstate_vma(vma)->order, &ilx); - nid = policy_node_nodemask(mpol, htlb_alloc_mask(h), ilx, &nodemask); folio = alloc_buddy_hugetlb_folio_from_node(h, mpol, nid, nodemask); - mpol_cond_put(mpol); - - if (!folio) + if (!folio) { + mpol_cond_put(mpol); goto out_uncharge_cgroup; + } + spin_lock_irq(&hugetlb_lock); if (use_hstate_resv) { folio_set_hugetlb_restore_reserve(folio); @@ -3209,6 +3199,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, folio_ref_unfreeze(folio, 1); /* Fall through */ } + mpol_cond_put(mpol); hugetlb_cgroup_commit_charge(idx, pages_per_huge_page(h), h_cg, folio); /* If allocation is not consuming a reservation, also store the