Skip to content

Avoid writing to shm a network that will be erased immediately - #6980

Open
AndyGrant wants to merge 2 commits into
official-stockfish:masterfrom
AndyGrant:AGE/shm-unused-dummy-write
Open

Avoid writing to shm a network that will be erased immediately#6980
AndyGrant wants to merge 2 commits into
official-stockfish:masterfrom
AndyGrant:AGE/shm-unused-dummy-write

Conversation

@AndyGrant

Copy link
Copy Markdown
Contributor

Fairly simple. The default constructor was prompting us to write a network to shm, which we then immediately remove, as we write a new one. The first is written with a content hash of 0, as it is not initialized.

Some logging, showing what was happening, in master:

$ ./stockfish
Stockfish dev-20260711-9a8dd81d by the Stockfish developers (see AUTHORS file)
[shm 289864] request: content_hash=0 disc=7357739359258373277 -> /sf_495f228c7f1a5827 (sizeof(T)=111263808)
[shm 289864] open: creating /sf_495f228c7f1a5827 (111263864 bytes)
[shm 289864] open: created /sf_495f228c7f1a5827 OK, ref_count=1
[shm 289864] request: /sf_495f228c7f1a5827 -> backend=SharedMemory
[shm 289864] close: /sf_495f228c7f1a5827 ref_count=0 remove_region=1
[shm 289864] request: content_hash=6559306200065483470 disc=7357739359258373277 -> /sf_e5671f518743128b (sizeof(T)=111263808)
[shm 289864] open: creating /sf_e5671f518743128b (111263864 bytes)
[shm 289864] open: created /sf_e5671f518743128b OK, ref_count=1
[shm 289864] request: /sf_e5671f518743128b -> backend=SharedMemory

It is possible this was done intentionally. I don't currently see or understand the reason, however. This extra write is not of great consequence, although it means doubling shm sizes if explicitly sizing it to handling Stockfish.

If you happened to spawn a bunch of engines at once, I did run into cases where this file was left lingering. i.e, during a running state, both files were present. That should be resolved though already, with #6979

Bench 2466447

No functional change

cc @anematode

Comment thread src/numa.h Outdated
@Disservin

Copy link
Copy Markdown
Member

oh for some reason that got changed in my recent ascii fixes and this now reverts the behavior back to what we had before

@anematode

Copy link
Copy Markdown
Member

🥴

@anematode

Copy link
Copy Markdown
Member

Need to fix IWYU, althoguh kind of a bizarre trigger. I guess std::make_unique<T>() needs T to be fully declared while everything else only needs a fwd decl

@AndyGrant

Copy link
Copy Markdown
Contributor Author
search.h should add these lines:
namespace Stockfish { namespace Eval { namespace NNUE { class Network; } } }

search.h should remove these lines:
- #include "nnue/network.h"  // lines 36-36

Some style decision to make about that forward-decl.

@anematode

anematode commented Jul 16, 2026

Copy link
Copy Markdown
Member

It'll speed up compilation, so I think it's worth

also you can do

namespace Stockfish::Eval::NNUE { class Network; }

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