Skip to content

Conversation

@CodaFi
Copy link

@CodaFi CodaFi commented Aug 13, 2020

The ModuleManager's use of FileEntry nodes as the keys for its map of
loaded modules is less than ideal. Uniqueness for FileEntry nodes is
maintained by FileManager, which in turn uses inode numbers on hosts
that support that. When coupled with the module cache's proclivity for
turning over and deleting stale PCMs, this means entries for different
module files can wind up reusing the same underlying inode. When this
happens, subsequent accesses to the Modules map will disagree on the
ModuleFile associated with a given file.

It's fine to use the file management utilities to guarantee the presence
of module data, but we need a better source of key material that is
invariant with respect to these OS-level details. Using file paths alone
is a similarly frought solution because the ASTWriter performs a custom
canonicalization step (that is not equivalent to path canonicalization)
that renders keys from loaded AST cores useless for looking up cached
entries.

To mitigate the effects of inode reuse, increase the entropy of the key
material by incorporating the modtime and size. This ultimately
decreases the likelihood that a PCM that is swapped on disk will confuse
the cache, but it does not eliminate the possibility of collisions.

rdar://48443680

@CodaFi CodaFi requested a review from DougGregor August 13, 2020 23:56
@CodaFi
Copy link
Author

CodaFi commented Aug 13, 2020

@swift-ci test

@CodaFi CodaFi force-pushed the i-node-what-you-did-last-summer branch from 50a22c0 to 826f98b Compare August 15, 2020 22:55
@CodaFi
Copy link
Author

CodaFi commented Aug 15, 2020

@swift-ci test

@hyp
Copy link

hyp commented Aug 17, 2020

@CodaFi Swift/master branch only accepts LLDB changes. Please merge your PR into apple/stable/20200108 instead , and also cherry-pick it to apple/stable/20200714.

@CodaFi CodaFi force-pushed the i-node-what-you-did-last-summer branch from 826f98b to 033e3c3 Compare August 18, 2020 05:18
@CodaFi
Copy link
Author

CodaFi commented Aug 18, 2020

@hyp I'll bear that in mind. Using this to kick off one last set of tests.

@swift-ci test

@CodaFi
Copy link
Author

CodaFi commented Aug 18, 2020

@swift-ci test macOS

@CodaFi CodaFi force-pushed the i-node-what-you-did-last-summer branch 5 times, most recently from 966bb8c to 7439c0a Compare August 18, 2020 17:14
@CodaFi CodaFi changed the title Use File Names Instead of inodes As Loaded Module Keys Increase the Entropy of ModuleManager Map Keys Aug 18, 2020
@CodaFi
Copy link
Author

CodaFi commented Aug 18, 2020

@swift-ci test

@CodaFi CodaFi force-pushed the i-node-what-you-did-last-summer branch 2 times, most recently from fbdf248 to 09556af Compare August 18, 2020 18:06
@CodaFi
Copy link
Author

CodaFi commented Aug 18, 2020

@swift-ci test

@CodaFi CodaFi force-pushed the i-node-what-you-did-last-summer branch from 09556af to 603e9bb Compare August 19, 2020 02:35
@CodaFi CodaFi changed the base branch from swift/master to apple/stable/20200108 August 19, 2020 02:38
@CodaFi CodaFi closed this Aug 19, 2020
@CodaFi CodaFi force-pushed the i-node-what-you-did-last-summer branch from 603e9bb to 3e16fc3 Compare August 19, 2020 02:45
The ModuleManager's use of FileEntry nodes as the keys for its map of
loaded modules is less than ideal. Uniqueness for FileEntry nodes is
maintained by FileManager, which in turn uses inode numbers on hosts
that support that. When coupled with the module cache's proclivity for
turning over and deleting stale PCMs, this means entries for different
module files can wind up reusing the same underlying inode. When this
happens, subsequent accesses to the Modules map will disagree on the
ModuleFile associated with a given file.

It's fine to use the file management utilities to guarantee the presence
of module data, but we need a better source of key material that is
invariant with respect to these OS-level details. Using file paths alone
is a similarly frought solution because the ASTWriter performs a custom
canonicalization step (that is not equivalent to path canonicalization)
that renders keys from loaded AST cores useless for looking up cached
entries.

To mitigate the effects of inode reuse, increase the entropy of the key
material by incorporating the modtime and size. This ultimately
decreases the likelihood that a PCM that is swapped on disk will confuse
the cache, but it does not eliminate the possibility of collisions.

rdar://48443680
@CodaFi CodaFi reopened this Aug 19, 2020
@CodaFi
Copy link
Author

CodaFi commented Aug 19, 2020

@swift-ci test

@CodaFi
Copy link
Author

CodaFi commented Aug 19, 2020

@CodaFi CodaFi merged commit 11452e6 into swiftlang:apple/stable/20200108 Aug 19, 2020
@CodaFi CodaFi deleted the i-node-what-you-did-last-summer branch August 19, 2020 16:05
CodaFi added a commit to CodaFi/swift-package-manager that referenced this pull request Aug 19, 2020
After swiftlang/llvm-project#1651, we should see no remaining issues from
this test.
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

Successfully merging this pull request may close these issues.

3 participants