linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Dolgov <9erthalion6@gmail.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-mm@kvack.org
Subject: Re: [QUESTION] Resizing shared mapping without clashing with others
Date: Mon, 2 Dec 2024 15:54:14 +0100	[thread overview]
Message-ID: <toavllwkvwguqf2jcexreomj5xxr3s3uxpoff6yc7cgsq3t6ge@emupyzdbrltf> (raw)
In-Reply-To: <Z0zNoxn-qkHYh6Pq@casper.infradead.org>

> On Sun, Dec 01, 2024 at 08:57:07PM GMT, Matthew Wilcox wrote:
> > Right, mapping with the larger size than needed is one option we're
> > considering. But there are few arguments against that:
> >
> > * Folks are wary of unnecessary large shared mappings, since in the past
> >   there were issues with OOM killer making unfavorable to postgres
> >   decisions because of that. It might have changed over time, but to
> >   confirm that will require some investigation.
> >
> > * It can cause memory accounting problems. E.g. if we use hugetlb inside
> >   a cgroup with reservation limits set (something like
> >   hugetlb.2MB.rsvd.limit_in_bytes), then such mmap() will be counted
> >   against the limit, even though the memory wasn't allocated -- meaning
> >   that we claim some resource without using it.
>
> If it does turn out to be a problem, you can use a similar trick to how
> ld.so maps binaries:
>
> mmap(NULL, 2055640, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f221a758000
> mmap(0x7f221a780000, 1462272, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7f221a780000
> mmap(0x7f221a8e5000, 352256, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x18d000) = 0x7f221a8e5000
> mmap(0x7f221a93b000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e2000) = 0x7f221a93b000
> mmap(0x7f221a941000, 52696, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f221a941000
>
> Although you wouldn't want to do consecutive mmaps, you'd want to use
> mremap() with MREMAP_FIXED -- not to change new_address, but to expand
> length over the initial reserving-space mapping.

Hm, I don't follow how would that help? From what I understand the
suggestion is to have an initial mapping to "reserve" the space, right?
But this initial mapping would also be a subject of reservation limits,
mentioned above. I was originally experimenting with that, "reserving"
some mapping space with PROT_NONE, then slicing off chunks of it for
real usage -- but in case of hugetlb and a cgroup it was accounting
against the reservation limits for huge pages.


  reply	other threads:[~2024-12-02 14:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-30 16:24 Dmitry Dolgov
2024-12-01 11:55 ` Matthew Wilcox
2024-12-01 18:44   ` Dmitry Dolgov
2024-12-01 20:57     ` Matthew Wilcox
2024-12-02 14:54       ` Dmitry Dolgov [this message]
2024-12-02 11:07 ` David Hildenbrand
2024-12-02 15:04   ` Dmitry Dolgov
2024-12-02 15:40     ` David Hildenbrand
2024-12-02 16:14       ` Dmitry Dolgov

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=toavllwkvwguqf2jcexreomj5xxr3s3uxpoff6yc7cgsq3t6ge@emupyzdbrltf \
    --to=9erthalion6@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.org \
    /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