Skip to content

Add stack-measuring functionality #15600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nnethercote opened this issue Jul 11, 2014 · 7 comments
Closed

Add stack-measuring functionality #15600

nnethercote opened this issue Jul 11, 2014 · 7 comments

Comments

@nnethercote
Copy link
Contributor

I've done some memory profiling of Servo (by looking at /proc/<pid>/smaps on Linux) and found that stack sizes can be really large:

  • [stack:28150] 1136 kB
  • [stack:28145] 6144 kB
  • [stack:28144] 2048 kB
  • [stack:28141] 8192 kB
  • [stack:28139] 7944 kB
  • [stack:28136] 5120 kB

These are all |Rss| values. The |Size| values (i.e. address space taken) values were even larger.

It would be nice to have language (well, library) support for measuring these within the Rust code. I don't know how it would be implemented, though.

@alexcrichton
Copy link
Member

If I'm reading those numbers correct, is that indicating that a task is using 8 gigabytes of stack?

Rust tasks currently do not have resizable stacks, and they're allocated through two different means:

  • For native tasks, we pass a stack size to pthread_create.
  • For green tasks, we mmap a chunk of memory with a given size.

Instrumenting the runtime to hook into all task spawn events is also possible, I've toyed around with it for servo with logging events here: https://github.com/stamourv/rust-task-visualizer/blob/master/rtinstrument.rs

Does that help?

@nnethercote
Copy link
Contributor Author

is that indicating that a task is using 8 gigabytes of stack?

No, only 8 MiB.
I can try the visualizer on Monday.

@alexcrichton
Copy link
Member

Feel free to ping me on IRC if you need any help! I'm acrichto.

@nnethercote
Copy link
Contributor Author

(Alex gave me the following instructions on how to do this.)

Yes, this will currently require instrumentation of Servo to work.
You'll probably want to take these course of action:

  1. Acquire rtinstrument.rs 1
  2. Compile into a library and then link to servo
  3. Invoke the instrumentation function 2 around code you wish to instrument
  4. Print the messages to stdout or somewhere to collect them 3
  5. Cat the printed messages into racket somehow to see the visualization.

This may require a newer version of rust than servo has available, so
it may be difficult to use for awhile.

@steveklabnik
Copy link
Member

Seems like this has been resolved.

@nnethercote
Copy link
Contributor Author

It hasn't been resolved. I just measured again with current Servo tip:

Rss:                  12 kB
Rss:                  12 kB
Rss:                8192 kB
Rss:                  48 kB
Rss:                  16 kB
Rss:                  24 kB
Rss:                  48 kB
Rss:                4096 kB
Rss:                  48 kB
Rss:                  44 kB
Rss:                4024 kB
Rss:                  44 kB
Rss:                  12 kB
Rss:                4096 kB
Rss:                  12 kB
Rss:                  24 kB
Rss:                  12 kB
Rss:                8192 kB
Rss:                  28 kB
Rss:                  28 kB
Rss:                  48 kB
Rss:                  28 kB
Rss:                4096 kB
Rss:               12128 kB
Rss:                  12 kB
Rss:                  20 kB
Rss:                  16 kB
Rss:                  16 kB
Rss:                  12 kB
Rss:                   8 kB
Rss:                   8 kB
Rss:                   8 kB
Rss:                   8 kB
Rss:                   8 kB
Rss:                   8 kB
Rss:                   8 kB
Rss:                4724 kB

That's over 48 MiB of stack, which is more than a third of Servo's total Rss.

@nnethercote
Copy link
Contributor Author

Oh, I just learned that if a non-thread-stack mapping is placed adjacent to a thread stack, the two will be merged and /proc//smaps will claim that the merged result is a thread stack. So these big numbers are bogus. Good.

bors added a commit to rust-lang-ci/rust that referenced this issue Nov 13, 2023
…t-in-ra, r=Veykril

fix: ensure `rustfmt` runs when configured with `./`

(Hopefully) resolves rust-lang/rust-analyzer#15595. This change kinda approaches canonicalization—which I am not a fan of—but only in service of making `./`-configured commands run correctly.

Longer-term, I feel like this code should be removed once `rustfmt` supports recursive searches of configuration files or interpolation of values like `${workspace_folder}` lands in rust-analyzer.

## Testing

I cloned `rustc`, setup rust-analyzer as suggested in the [`rustc` dev guide](https://rustc-dev-guide.rust-lang.org/building/suggested.html#configuring-rust-analyzer-for-rustc), saved and formatted files in `src/tools/miri` and `compiler`, and saw `rustfmt` (seemingly) correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants