linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Oscar Salvador <osalvador@suse.de>
To: Peter Xu <peterx@redhat.com>
Cc: Ackerley Tng <ackerleytng@google.com>,
	muchun.song@linux.dev, akpm@linux-foundation.org,
	rientjes@google.com, fvdl@google.com, jthoughton@google.com,
	david@redhat.com, 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, pgonda@google.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [RFC PATCH 2/3] mm: hugetlb: Refactor vma_has_reserves() to should_use_hstate_resv()
Date: Mon, 11 Nov 2024 10:19:26 +0100	[thread overview]
Message-ID: <ZzHMHuhCAM0vtrzf@localhost.localdomain> (raw)
In-Reply-To: <ZypoDzm2XdfnG1if@x1n>

On Tue, Nov 05, 2024 at 01:46:39PM -0500, Peter Xu wrote:
> I wonder if this patch could be merged with the 3rd, IIUC this can
> fundamentally be seen as a movement of what patch 3 was removed.

I think it makes sense to merge it, yes.

> Furthermore, I do feel like should_use_hstate_resv() could be redundant on
> its own on many things.

...
 
> Then let's look at chg==0 processing all above: what does it say?  I
> suppose it means "we don't need another global reservation".  It means if
> chg==0 we always will use an existing reservation.  From math POV it also
> is true, so it can already be moved out ahead, IIUC, like this:
> 
> static bool should_use_hstate_resv(struct vm_area_struct *vma, long chg,
> 				   bool avoid_reserve)
> {
> 	if (avoid_reserve)
> 		return false;
> 
>         if (chg == 0)
>                 return true;
> 
> 	if (vma->vm_flags & VM_NORESERVE)
>                 return false;
> 
> 	if (vma->vm_flags & VM_MAYSHARE)
>                 return false;
> 
> 	if (is_vma_resv_set(vma, HPAGE_RESV_OWNER))
>                 return false;
> 
> 	return false;             <--------------------- [1]
> }
> 
> Move on.  If I read it right, above [1] is exactly for avoid_reserve==1
> case, where it basically says "it's !NORESERVE, private, and it's not the
> vma resv owner, either fork() or CoW".  If my reading is correct, it means
> after your patch 2, [1] should never be reachable at all.. I would hope
> adding a panic() right above would be ok.
> 
> And irrelevant of whether my understanding is correct.. math-wise above is
> also already the same as:
> 
> static bool should_use_hstate_resv(struct vm_area_struct *vma, long chg,
> 				   bool avoid_reserve)
> {
> 	if (avoid_reserve)
> 		return false;
> 
>         if (chg == 0)
>                 return true;
> 
> 	return false;
> }

I have been looking into this because hugetlb reservations always make
me uneasy, but I think you are right.

CoW and fork both set avoid_reserve to 1,

 copy_hugetlb_range
  ...
  alloc_hugetlb_folio(dst_vma, addr, 1)

 hugetlb_wp
  outside_reserve = 1
  alloc_hugetlb_folio(..., outside_reserve)

So I think you are right and this can be simplified.

I would not add a panic though, maybe some kind of warning (VM_DEBUG?).


-- 
Oscar Salvador
SUSE Labs


  reply	other threads:[~2024-11-11  9:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-11 23:22 [RFC PATCH 0/3] Reduce dependence on vmas deep in hugetlb allocation code Ackerley Tng
2024-10-11 23:22 ` [RFC PATCH 1/3] mm: hugetlb: Simplify logic in dequeue_hugetlb_folio_vma() Ackerley Tng
2024-10-30 14:31   ` Sean Christopherson
2024-11-05 17:10   ` Peter Xu
2024-11-06 10:13   ` Oscar Salvador
2024-10-11 23:22 ` [RFC PATCH 2/3] mm: hugetlb: Refactor vma_has_reserves() to should_use_hstate_resv() Ackerley Tng
2024-11-05 18:46   ` Peter Xu
2024-11-11  9:19     ` Oscar Salvador [this message]
2024-10-11 23:22 ` [RFC PATCH 3/3] mm: hugetlb: Remove unnecessary check for avoid_reserve Ackerley Tng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZzHMHuhCAM0vtrzf@localhost.localdomain \
    --to=osalvador@suse.de \
    --cc=ackerleytng@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=erdemaktas@google.com \
    --cc=fan.du@intel.com \
    --cc=fvdl@google.com \
    --cc=isaku.yamahata@intel.com \
    --cc=jgg@nvidia.com \
    --cc=jhubbard@nvidia.com \
    --cc=jthoughton@google.com \
    --cc=jun.miao@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=pgonda@google.com \
    --cc=quic_eberman@quicinc.com \
    --cc=rientjes@google.com \
    --cc=roypat@amazon.co.uk \
    --cc=seanjc@google.com \
    --cc=tabba@google.com \
    --cc=vannapurve@google.com \
    --cc=zhiquan1.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox