Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <BR0PR04MB2431146F098F0C453BE18386CEF24E2@BR0PR04MB243114.eurprd04.prod.outlook.com>
Date: Mon, 30 Nov 2026 16:52:45 +0000
From: Stanislav Meduna <Stanislav.Meduna@...com>
To: Rich Felker <dalias@...c.org>, Axel LORENTE <axel.lorente@...com>,
	"musl@...ts.openwall.com" <musl@...ts.openwall.com>
Subject: Re: Priority inheritance for malloc internal locks

Hello Rich,

> But really, it's generally not realtime-safe to call random libc
> functions that might need locking from a context with realtime
> priority needs. Even if malloc had the right PI locks for it,
> allocation is inherently something that might need to evict other
> pages and wait on locks in kernelspace, and I'm not sure if the kernel
> does anything here to avoid priority inversion; my experience with it
> is that it's really bad at stuff in this area. You really want to have
> things preallocated for realtime, or when that's not possible, request
> allocation asynchronously from another task rather than having it
> directly in a hot realtime path.

just to comment on this part: At least the PREEMPT_RT-compiled kernels go a long way to use PI locks inside the kernel nowadays. While I am not sure that getting memory pages from the kernel in general has bound latency (it most probably indeed does not), it is possible to get the memory from the kernel, lock it with mlockall, and never return it to the kernel. glibc has mallopt(M_TRIM_THRESHOLD, -1) for this, and M_MMAP_MAX to avoid going to mmap() for allocating large memory. I don't know what if anything musl has.

In other words, to my knowledge, with glibc, it is possible to have the memory allocations interact with just the userspace. With this, I think that it is reasonable to expect that the userspace behaves deterministically, which in turn requires using FUTEX_LOCK_PI. If the trips to the kernel cannot be avoided at this time, then it is probably indeed a can of worms...

Thanks

Stano


General

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.