linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Nicholas Piggin <npiggin@gmail.com>
To: linux-mm@kvack.org, Yu Xu <xuyu@linux.alibaba.com>
Cc: akpm@linux-foundation.org
Subject: Re: [PATCH] mm/vmalloc: allocate small pages for area->pages
Date: Thu, 09 Dec 2021 20:59:12 +1000	[thread overview]
Message-ID: <1639046632.ijbttgtfmt.astroid@bobo.none> (raw)
In-Reply-To: <50ea6251-fbde-10d9-c37c-3198aa9e2d82@linux.alibaba.com>

Excerpts from Yu Xu's message of December 9, 2021 7:27 pm:
> On 12/9/21 4:23 PM, Nicholas Piggin wrote:
>> Excerpts from Xu Yu's message of December 7, 2021 7:46 pm:
>>> The area->pages stores the struct pages allocated for vmalloc mappings.
>>> The allocated memory can be hugepage if arch has HAVE_ARCH_HUGE_VMALLOC
>>> set, while area->pages itself does not have to be hugepage backed.
>>>
>>> Suppose that we want to vmalloc 1026M of memory, then area->pages is
>>> 2052K in size, which is large than PMD_SIZE when the pagesize is 4K.
>>> Currently, 4096K will be allocated for area->pages, wherein 2044K is
>>> wasted.
>>>
>>> This introduces __vmalloc_node_no_huge, and makes area->pages backed by
>>> small pages, because I think to allocate hugepage for area->pages is
>>> unnecessary and vulnerable to abuse.
>> 
>> Any vmalloc allocation will be subject to internal fragmentation like
>> this. What makes this one special? Is there a way to improve it for
>> all with some heuristic?
> 
> As described in the commit log, I think vmalloc memory (*data*) can be
> hugepage, while the area->pages (*meta*) is unnecessary.

Right. I accept some vmalloc allocations aren't performance critical
for accesses, and some allocations will have more fragmentation waste
from huge vmalloc, and that area->pages fits both under some
circumstances.

But 1) other vmalloc allocations might too. And 2) sure you can waste
50% of the 0.2% space overhead that area->pages requires so it another
0.2% in the absolute worst case that you're vmallocing just over a gig
of memory.

The question is does this case actually matter that much. And would we
be better served looking at actual wastage numbers across all allocs
and whether it's worth worrying about or if a general heuristic could
be used.

> There should be heuristic ways, just like THP settings (always, madvise,
> never). But such heuristic ways are mainly for data allocation, and I'm
> not sure it's worth it to bring such logic in.
> 
>> 
>> There would be an argument for a size-optimised vmalloc vs a space
>> optimised one. An accounting strucutre like this doesn't matter
>> much for speed. A vfs hash table does. Is it worth doing though? How
> 
> To be honest, I wrote the patch when studying your patchset. No real
> issue.
> 
>> much do you gain in practice?
> 
> Therefore, no actual gain in practice.
> 
> 
> Perhaps I should add an RFC tag in the patch. However, I saw that
> Andrew Morton has added this patch to the -mm tree.
> 
> I wonder if we need to reconsider this patch.

I like your thinking and that you're looking to optimise memory usage.

I'm mainly concerned that the more API options we provide, the harder it 
makes things for callers and the more chance there is that they will get
it wrong. Heuristics aren't a magic fix either (they can go wrong too),
so getting an idea of how much waste we could avoid would be a good
start.

Thanks,
Nick


      reply	other threads:[~2021-12-09 10:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-07  9:46 Xu Yu
2021-12-09  8:23 ` Nicholas Piggin
2021-12-09  9:27   ` Yu Xu
2021-12-09 10:59     ` Nicholas Piggin [this message]

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=1639046632.ijbttgtfmt.astroid@bobo.none \
    --to=npiggin@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=xuyu@linux.alibaba.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