Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4338454
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:05:02+00:00 2026-05-21T11:05:02+00:00

I am writing code for a real-time program running in an embedded Linux system.

  • 0

I am writing code for a real-time program running in an embedded Linux system. As it is critical that we don’t stall unpredictably on page faults, I would like to prefault in the stack so that the region that we use is guaranteed to be covered by a mlockall() call.

For the main thread this is simple enough; simply do a few big alloca()s and make sure to do a write every few pages. This works because at program startup, the stack limit is much larger than the amount we need; we end up allocating exactly how much we prefault in.

However, for pthread stacks, will they be allocated using MAP_GROWSDOWN as well? If so, what’s the best way to prefault them in, considering that:

  1. We don’t know how much of the (known) stack size is consumed by libc startup
  2. We don’t want to allocate more memory to the stack than is necessary

I’m aware that I can use pthread_attr_setstack to pass in a manually-allocated stack, but this complicates cleaning up after the thread, and so I’d prefer to avoid this if possible.

As such, what’s the best way to perform this prefaulting? It would be sufficient if there was an easy way to find out the lower bound of the stack (just above the guard page); at this point I could simply write to every page from there to the current stack pointer.

Note that portability is not a concern; we’d be happy to have a solution that works only under x86-32 and Linux.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:05:02+00:00Added an answer on May 21, 2026 at 11:05 am

    If you use pthread_attr_setstacksize you can still have automatic allocation with a known size.

    glibc nptl leaves guard pages between the stacks, so you could also set a SEGV handler and simply scribble until you fault and then longjmp out of the loop. That’d be ugly!

    Edit: A really nonportable way would be to open /proc/self/maps to find your stacks!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When writing code do you consciously program defensively to ensure high program quality and
I'm writing code that looks similar to this: public IEnumerable<T> Unfold<T>(this T seed) {
I'm writing code on the master page, and I need to know which child
I find myself writing code that looks like this a lot: set<int> affected_items; while
I am writing an iphone (IOS 4) program that capture live video from the
After writing code to populate textboxes from an object, such as: txtFirstName.Text = customer.FirstName;
When I am writing code in Python, I often need to remove items from
I frequently find myself writing code like this: List<int> list = new List<int> {
I'm writing code like this, doing a little quick and dirty timing: var sw
I'm writing code to do Xml serialization. With below function. public static string SerializeToXml(object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.