Skip to content
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

An in-memory RNG that shares its file descriptor. #14351

Merged
merged 2 commits into from Jan 5, 2017

Conversation

@asajeffrey
Copy link
Member

asajeffrey commented Nov 23, 2016

This PR implements an in-memory random number generator that only uses an OS RNG for (re)seeding. The OS RNG is shared, so there's only one file descriptor for /dev/urandom being used.

The PR also implements a tidy check that we don't accidentally introduce an RNG. Rather annoyingly, there are a lot of transitive dependencies on rand, notably hash maps in std.

This PR makes it possible to use uuids for identifiers such as pipeline and frame ids.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes do not require tests because it's fixing a resource issue

This change is Reviewable

@highfive
Copy link

highfive commented Nov 23, 2016

Heads up! This PR modifies the following files:

  • @bholley: components/style/Cargo.toml
  • @wafflespeanut: python/tidy/servo_tidy/tidy.py
  • @KiChjang: components/script/lib.rs, components/script/Cargo.toml, components/script/dom/crypto.rs, components/script/dom/htmlformelement.rs, components/script/dom/dedicatedworkerglobalscope.rs, components/script/dom/serviceworkerglobalscope.rs
  • @fitzgen: components/script/lib.rs, components/script/Cargo.toml, components/script/dom/crypto.rs, components/script/dom/htmlformelement.rs, components/script/dom/dedicatedworkerglobalscope.rs, components/script/dom/serviceworkerglobalscope.rs
  • @emilio: components/style/Cargo.toml
@highfive
Copy link

highfive commented Nov 23, 2016

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify style and script code, but no tests are modified. Please consider adding a test!
@asajeffrey
Copy link
Member Author

asajeffrey commented Nov 23, 2016

cc @ConnorGBrewster @larsbergstrom @nox

@asajeffrey
Copy link
Member Author

asajeffrey commented Nov 23, 2016

@avadacatavra this replaces the RNG in crypto. We should double-check that we are okay with that.

@emilio
Copy link
Member

emilio commented Nov 23, 2016

FWIW, rayon uses rand but only for XorShiftRng, so probably we should be able to filter this in a better way?

@asajeffrey
Copy link
Member Author

asajeffrey commented Nov 23, 2016

We don't scan dependency source, so it's difficult to see how we can do much better than a whitelist.

@nox
Copy link
Member

nox commented Nov 24, 2016

That's quite a lot of code. I would rather we use the Fnv one explicitly when we see failures due to file limits with a RNG-related stack, than use a custom hasher.

@asajeffrey
Copy link
Member Author

asajeffrey commented Nov 24, 2016

@nox: yes, we can use Fnv for hash maps, but that doesn't help for uuids or other cases where we need an RNG, not a hash function.

Most of the code here is just cut-and-paste from rand, in particular there's no new RNG algorithms, it just reuses existing ones. The only new bit is sharing an OsRng (and hence sharing an fd) rather than creating a new one for each thread.

@bors-servo
Copy link
Contributor

bors-servo commented Nov 28, 2016

The latest upstream changes (presumably #14381) made this pull request unmergeable. Please resolve the merge conflicts.

@asajeffrey asajeffrey force-pushed the asajeffrey:servo-rand-share-fds branch from ae888f8 to 5f79e29 Nov 28, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Nov 29, 2016

The latest upstream changes (presumably #14292) made this pull request unmergeable. Please resolve the merge conflicts.

@asajeffrey asajeffrey force-pushed the asajeffrey:servo-rand-share-fds branch from 5f79e29 to a25da00 Dec 3, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Dec 7, 2016

The latest upstream changes (presumably #14473) made this pull request unmergeable. Please resolve the merge conflicts.

@asajeffrey asajeffrey force-pushed the asajeffrey:servo-rand-share-fds branch from a25da00 to 91ce41f Dec 8, 2016
@asajeffrey asajeffrey mentioned this pull request Dec 13, 2016
4 of 5 tasks complete
@bors-servo
Copy link
Contributor

bors-servo commented Dec 15, 2016

The latest upstream changes (presumably #14592) made this pull request unmergeable. Please resolve the merge conflicts.

@asajeffrey asajeffrey force-pushed the asajeffrey:servo-rand-share-fds branch 2 times, most recently from dc05dda to 1026d4d Dec 15, 2016
@asajeffrey
Copy link
Member Author

asajeffrey commented Dec 15, 2016

Rebased.

@bors-servo
Copy link
Contributor

bors-servo commented Dec 21, 2016

The latest upstream changes (presumably #14652) made this pull request unmergeable. Please resolve the merge conflicts.

@asajeffrey asajeffrey force-pushed the asajeffrey:servo-rand-share-fds branch from 1026d4d to f2248e4 Dec 23, 2016
@asajeffrey
Copy link
Member Author

asajeffrey commented Dec 23, 2016

Rebased. @emilio or @nox: any chance of a review?

@bors-servo
Copy link
Contributor

bors-servo commented Dec 24, 2016

The latest upstream changes (presumably #14687) made this pull request unmergeable. Please resolve the merge conflicts.

@emilio
Copy link
Member

emilio commented Dec 25, 2016

This is fine for me when rebased, but maybe @nox has still concerns.

@@ -81,6 +81,24 @@
" accessible to\n// web pages."
]

WHITELISTED_DEPENDENCIES = {

This comment has been minimized.

@wafflespeanut

wafflespeanut Jan 5, 2017

Member

We should really be moving this to the config file, but that shouldn't be a concern for this PR. I'll take care of it in an easy issue 😄

@asajeffrey
Copy link
Member Author

asajeffrey commented Jan 5, 2017

IRC conversation with @nox: http://logs.glob.uno/?c=mozilla%23servo&s=5+Jan+2017&e=5+Jan+2017#c587629

TL;DR he r+s once it's split into two commits, and WHITELISTED_DEPENDENCIES is renamed.

@asajeffrey asajeffrey force-pushed the asajeffrey:servo-rand-share-fds branch from f2248e4 to 70ffe1f Jan 5, 2017
@asajeffrey asajeffrey force-pushed the asajeffrey:servo-rand-share-fds branch from 70ffe1f to e3a8e3b Jan 5, 2017
@asajeffrey
Copy link
Member Author

asajeffrey commented Jan 5, 2017

@bors-servo r=emilio

@bors-servo
Copy link
Contributor

bors-servo commented Jan 5, 2017

📌 Commit e3a8e3b has been approved by emilio

@bors-servo
Copy link
Contributor

bors-servo commented Jan 5, 2017

Testing commit e3a8e3b with merge 36ddf76...

bors-servo added a commit that referenced this pull request Jan 5, 2017
An in-memory RNG that shares its file descriptor.

<!-- Please describe your changes on the following line: -->

This PR implements an in-memory random number generator that only uses an OS RNG for (re)seeding. The OS RNG is shared, so there's only one file descriptor for `/dev/urandom` being used.

The PR also implements a tidy check that we don't accidentally introduce an RNG. Rather annoyingly, there are a lot of transitive dependencies on `rand`, notably hash maps in `std`.

This PR makes it possible to use uuids for identifiers such as pipeline and frame ids.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes do not require tests because it's fixing a resource issue

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14351)
<!-- Reviewable:end -->
@bors-servo bors-servo merged commit e3a8e3b into servo:master Jan 5, 2017
2 of 3 checks passed
2 of 3 checks passed
continuous-integration/travis-ci/pr The Travis CI build failed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
homu Test successful
Details
@dhardy

This comment has been minimized.

Copy link

dhardy commented on 7ace30f Jan 14, 2018

@asajeffrey can you tell me what the motivation for this is?

I'm working on improving rand, and I'd like to know if there is a deficiency. It may be that OsRng can use multiple file descriptors, but if so we should fix it internally.

This comment has been minimized.

Copy link
Member

jdm replied Jan 14, 2018

The motivation was the frequency with which Service would run out of file descriptors during tests. I don't recall seeing that problem since making this change

This comment has been minimized.

Copy link
Member

jdm replied Jan 14, 2018

Servo, not Service.

This comment has been minimized.

Copy link
Member Author

asajeffrey replied Jan 14, 2018

@dhardy, sharing the OS RNG among threads, to avoid running out of FDs, but only using the shared RNG for reseeding, to avoid lock contention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

8 participants
You can’t perform that action at this time.