linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC] mm: Add MADV_NONZERO to skip redundant zeroing in MADV_DONTNEED
@ 2025-06-04  1:01 Ayaan Mirza Baig
  2025-06-04  1:49 ` Harry Yoo
  0 siblings, 1 reply; 3+ messages in thread
From: Ayaan Mirza Baig @ 2025-06-04  1:01 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, david

Hi Andrew,

I've been looking at MADV_DONTNEED and noticed we always zero pages, 
even when
it might not be necessary for cases like:

- Media buffers (video/audio processing)
- Temporary compute workloads
- Pre-zeroed memory pools

This causes measurable overhead - in some synthetic tests I'm seeing 
~40% extra
latency from the zeroing. I'm thinking of adding a MADV_NONZERO flag 
that would
let us skip the zeroing when:

1. It's explicitly requested (MADV_DONTNEED|MADV_NONZERO)
2. We're confident it's safe (VM_IO, VM_HUGETLB, etc)
3. The user has explicitly marked the region as non-sensitive

Before I go deeper on patches, I wanted to check:
- Does this sound reasonable?
- Any obvious security holes I'm missing?
- Would you prefer a new flag or a separate advice type?

Early prototype numbers look promising, but I want to make sure I'm not 
missing
something fundamental. If the concept seems viable, I'll work up proper 
benchmarks
and formal patches.

Thanks for your time!
- Ayaan Mirza Baig


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC] mm: Add MADV_NONZERO to skip redundant zeroing in MADV_DONTNEED
  2025-06-04  1:01 [RFC] mm: Add MADV_NONZERO to skip redundant zeroing in MADV_DONTNEED Ayaan Mirza Baig
@ 2025-06-04  1:49 ` Harry Yoo
  2025-06-04 11:27   ` David Hildenbrand
  0 siblings, 1 reply; 3+ messages in thread
From: Harry Yoo @ 2025-06-04  1:49 UTC (permalink / raw)
  To: Ayaan Mirza Baig; +Cc: akpm, linux-mm, david

On Wed, Jun 04, 2025 at 06:31:59AM +0530, Ayaan Mirza Baig wrote:
> Hi Andrew,
> 
> I've been looking at MADV_DONTNEED and noticed we always zero pages, even
> when
> it might not be necessary for cases like:
> 
> - Media buffers (video/audio processing)
> - Temporary compute workloads
> - Pre-zeroed memory pools

Hi Ayaan,

I don't think this "skipping zeroing" is limited to MADV_DONTNEED at all?

We don't zero pages during zapping (unless init_on_free is enabled),
but zero pages when madvise(MADV_DONTNEED)'d area is accessed again
(for anonymous mappings), because that's how faulting anonymous mappings
works.

And if you're suggesting that you want to skip zeroing (on some conditions)
when faulting an anonymous mapping, we can't do that because applications
rely on the guarantee that such pages are zeroed.

Or am I missing something?

> This causes measurable overhead - in some synthetic tests I'm seeing ~40%
> extra
> latency from the zeroing. I'm thinking of adding a MADV_NONZERO flag that
> would
> let us skip the zeroing when:
> 
> 1. It's explicitly requested (MADV_DONTNEED|MADV_NONZERO)
> 2. We're confident it's safe (VM_IO, VM_HUGETLB, etc)
> 3. The user has explicitly marked the region as non-sensitive
> 
> Before I go deeper on patches, I wanted to check:
> - Does this sound reasonable?
> - Any obvious security holes I'm missing?
> - Would you prefer a new flag or a separate advice type?
> 
> Early prototype numbers look promising, but I want to make sure I'm not
> missing
> something fundamental. If the concept seems viable, I'll work up proper
> benchmarks
> and formal patches.

...and I'm wondering what does the informal patches do?

-- 
Cheers,
Harry / Hyeonggon


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC] mm: Add MADV_NONZERO to skip redundant zeroing in MADV_DONTNEED
  2025-06-04  1:49 ` Harry Yoo
@ 2025-06-04 11:27   ` David Hildenbrand
  0 siblings, 0 replies; 3+ messages in thread
From: David Hildenbrand @ 2025-06-04 11:27 UTC (permalink / raw)
  To: Harry Yoo, Ayaan Mirza Baig; +Cc: akpm, linux-mm

On 04.06.25 03:49, Harry Yoo wrote:
> On Wed, Jun 04, 2025 at 06:31:59AM +0530, Ayaan Mirza Baig wrote:
>> Hi Andrew,
>>
>> I've been looking at MADV_DONTNEED and noticed we always zero pages, even
>> when
>> it might not be necessary for cases like:
>>
>> - Media buffers (video/audio processing)
>> - Temporary compute workloads
>> - Pre-zeroed memory pools
> 
> Hi Ayaan,
> 
> I don't think this "skipping zeroing" is limited to MADV_DONTNEED at all?
> 
> We don't zero pages during zapping (unless init_on_free is enabled),
> but zero pages when madvise(MADV_DONTNEED)'d area is accessed again
> (for anonymous mappings), because that's how faulting anonymous mappings
> works.
> 
> And if you're suggesting that you want to skip zeroing (on some conditions)
> when faulting an anonymous mapping, we can't do that because applications
> rely on the guarantee that such pages are zeroed.

Yeah, no way we're adding something like that.

What we discussed last years at plumbers IIRC in Rik's session was 
having a per-process cache of zapped pages. Essentially, during 
MADV_DONTNEED we could move the pages to that cache, and on re-access 
(if the process opted in) we could grab one of these pages from the 
per-process cache without zeroing them out. On memory pressure we would 
flush the cache.

There are some challenges (e.g., how to keep these pages 
migratable/swappable etc).

-- 
Cheers,

David / dhildenb



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-04 11:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-04  1:01 [RFC] mm: Add MADV_NONZERO to skip redundant zeroing in MADV_DONTNEED Ayaan Mirza Baig
2025-06-04  1:49 ` Harry Yoo
2025-06-04 11:27   ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox