[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221021134836.1fe0e8c8310eb247ce7acafb@linux-foundation.org>
Date: Fri, 21 Oct 2022 13:48:36 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: Rik van Riel <riel@...riel.com>
Cc: linux-kernel@...r.kernel.org, linux-mm@...ck.org,
kernel-team@...a.com, Mike Kravetz <mike.kravetz@...cle.com>,
David Hildenbrand <david@...hat.com>
Subject: Re: [PATCH] mm,madvise,hugetlb: fix unexpected data loss with
MADV_DONTNEED on hugetlbfs
On Fri, 21 Oct 2022 15:45:46 -0400 Rik van Riel <riel@...riel.com> wrote:
> A common use case for hugetlbfs is for the application to create
> memory pools backed by huge pages, which then get handed over to
> some malloc library (eg. jemalloc) for further management.
>
> That malloc library may be doing MADV_DONTNEED calls on memory
> that is no longer needed, expecting those calls to happen on
> PAGE_SIZE boundaries.
>
> However, currently the MADV_DONTNEED code rounds up any such
> requests to HPAGE_PMD_SIZE boundaries.
Well that's obnoxious.
> This leads to undesired
> outcomes when jemalloc expects a 4kB MADV_DONTNEED, but 2MB of
> memory get zeroed out, instead.
>
> Use of pre-built shared libraries means that user code does not
> always know the page size of every memory arena in use.
>
> Avoid unexpected data loss with MADV_DONTNEED by rounding up
> only to PAGE_SIZE (in do_madvise), and rounding down to huge
> page granularity.
>
> That way programs will only get as much memory zeroed out as
> they requested.
If we merge this, we're inviting people to develop and test code on the 6.2
kernel only to ship it and then find that it misbehaves on 6.1 and
earlier.
So I think we should backport this.
> While we're here, refactor madvise_dontneed_free_valid_vma
> a little so mlocked hugetlb VMAs need MADV_DONTNEED_LOCKED.
And if we do backport it, "while we're here" changes are unwelcome!
Powered by blists - more mailing lists