linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>,
	linux-man@vger.kernel.org
Cc: Pankaj Gupta <pankaj.gupta@ionos.com>,
	Alejandro Colomar <alx.manpages@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Michal Hocko <mhocko@suse.com>,
	Oscar Salvador <osalvador@suse.de>, Jann Horn <jannh@google.com>,
	Mike Rapoport <rppt@kernel.org>,
	Linux API <linux-api@vger.kernel.org>,
	linux-mm@kvack.org
Subject: Re: [PATCH v2] madvise.2: Document MADV_POPULATE_READ and MADV_POPULATE_WRITE
Date: Thu, 19 Aug 2021 20:38:12 +0200	[thread overview]
Message-ID: <ae29a12b-bd15-a927-3c31-5b720b542799@redhat.com> (raw)
In-Reply-To: <abec69cb-6db9-79ab-869e-907da573bfbc@gmail.com>

>>> I don't understand "without actually reading memory"? Do you mean,
>>> "without actually  faulting in the pages"; or something else?
>>
>> "Populate (prefault) page tables readable, faulting in all pages in the
>> range just as if manually reading one byte of each page; however, avoid
>> the actual memory access that would have been performed after handling
>> the fault."
>>
>> Does that make it clearer? (avoiding eventually touching the page at all
>> can be beneficial, especially when dealing with DAX memory where memory
>> access might be expensive)
> 
> That text is much better. But, what's still not clear to me then is the
> dfference between mmap(2) MAP_POPULATE, and MADV_POPULATE_READ and
> MADV_POPULATE_WRITE. What is the differnece, and in what situations
> would one prefer one or the other approach? I think it would be helpful
> if the manual page said something about these details.

Well, MAP_POPULATE

1. Can only be used on new mappings, not on existing mappings and 
especially not on parts of (sparse) memory mappings.

2. Hides actual population errors, simply returning "success"

3. Cannot specify the actual faultin behavior (readable vs. writable). 
Private mappings are always faulted in writable, shared mappings writable.

MADV_POPULATE_WRITE is the way to go to preallocate memory, especially 
hugetlbfs. MADV_POPULATE_READ can be used to just populate the shared 
zero page, or to fault-in file-backed memory without marking everything 
dirty such that it won't have to be written back to disk.

for MADV_POPULATE_READ

"In contrast to MAP_POPULATE, MADV_POPULATE_READ does not hide errors, 
can be applied to (parts of) existing mappings and will always populate 
(prefault) page tables readable. One example use case is prefaulting a 
file mapping, reading all file content from disk; however, pages won't 
be dirtied and consequently won't have to be written back to disk when 
evicting the pages from memory."

Suggestions welcome :)

for MADV_POPULATE_WRITE

"In contrast to MAP_POPULATE, MADV_POPULATE_WRITE does not hide errors, 
can be applied to (parts of) existing mappings and will always populate 
(prefault) page tables writable. One example use case is preallocating 
memory, breaking any CoW (Copy on Write)."

Again, suggestions welcome :)

[...]

>> Much better. Note that there might be more types of mappings that won't
>> work (e.g., initially also secretmem IIRC).
> 
> Ahh nice. Since there's about to be a memfd_secret() manual page,
> I suggest adding also "or secret memory regions created using
> memfd_secret(2)".

Can do, thanks!

[...]

>>
>> Sure, we can add that. But note that MADV_HWPOISON is just one of many
>> ways to HWpoison a page.
> 
> Then maybe something like:
> 
> "(HW poisoned pages can, for example, be created using the
> MADV_HWPOISON flag described elsewhere in this page.)"

Makes sense, I'll reuse the same description at the other place in this 
file where I mention HW poisoned pages.


-- 
Thanks,

David / dhildenb



      reply	other threads:[~2021-08-19 18:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-16  8:19 [PATCH v2] madvise.2: Document MADV_POPULATE_READ and MADV_POPULATE_WRITE David Hildenbrand
2021-08-17 21:42 ` Michael Kerrisk (man-pages)
2021-08-18  8:35   ` David Hildenbrand
2021-08-18 20:58     ` Michael Kerrisk (man-pages)
2021-08-19 18:38       ` David Hildenbrand [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=ae29a12b-bd15-a927-3c31-5b720b542799@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=alx.manpages@gmail.com \
    --cc=jannh@google.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=mtk.manpages@gmail.com \
    --cc=osalvador@suse.de \
    --cc=pankaj.gupta@ionos.com \
    --cc=rppt@kernel.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;
as well as URLs for NNTP newsgroup(s).