fd_set implementation is inefficient
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Refactoring
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- c, wasm
- Ambito
- operating-systems
Direzione di ricerca
Iniziare esaminando gli header relativi a select citati nell’issue: __macro_FD_SETSIZE.h, __typedef_fd_set.h, _fd_set.h e sys/select.h di musl. Confrontare la rappresentazione attuale di fd_set con i vincoli POSIX e determinare l’ambito necessario e l’impatto sulla compatibilità. Done deve includere una direzione di implementazione concordata e la relativa validazione del comportamento di select e FD*.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
cloudlibc seems to have made a design choice that POSIX does not require, and what most *NIX implementations don't support. this has led to cloudlibc using a lot more memory supporting scenarios with select() that is better served by poll(). imo this should be revisited by basically deleting the cloudlibc logic entirely.
first, let's start with what POSIX says:
- fd_set type
The <sys/select.h> header shall define the fd_set type as a structure.
The <sys/select.h> header shall define the following symbolic constant, which shall have a value suitable for use in #if preprocessing directives:
FD_SETSIZEMaximum number of file descriptors in an fd_set structure.
The requirement for the fd_set structure to have a member fds_bits has been removed as per The Open Group Base Resolution bwg2001-005. - select()
The behavior of these macros is undefined if the fd argument is less than 0 or greater than or equal to FD_SETSIZE, or if fd is not a valid file descriptor, or if any of the arguments are expressions with side-effects.
let's look at what cloudlibc does:
FD_SETSIZEset to1024- fd_set type
int __fds[FD_SETSIZE];-- an array of integers (fds)
- FD_* macros
- the index into
__fdsis just "the next used fd" - the value in
__fdsis the fd to check
- the index into
- end result:
- scanning the
__fdsarray takes exactly__nfdschecks (good) sizeof(fd_set)is 4100 bytes (bad)- still has a max nfds of
FD_SETSIZE(fine) - any valid fd can be monitored with
select(), not just[0, FD_SETSIZE)(good)
- scanning the
let's look at what musl (and basically every other *NIX library out there) does:
- sys/select.h
FD_SETSIZEset to 1024unsigned long fds_bits[FD_SETSIZE / 8 / sizeof(long)];-- a bitmask of fds- the index into
fds_bitsis the fd to check - the value is a single bit and whether to check the fd
- end result:
- scanning
fds_bitstakes longer, but most architectures have "bit is set" insns to optimize this. an unoptimized implementation would take at least 128 tests (FD_SETSIZE / 8) (meh) sizeof(fd_set)is 128 bytes (good)- still has a max nfds of
FD_SETSIZE(fine) - only valid fd's within
[0, FD_SETSIZE)can be monitored withselect()(fine)
- scanning
so cloudlibc uses 4k of memory instead of 128bytes in order to be slightly faster and to support fds larger than FD_SETSIZE. but no POSIX-compliant project would ever use an fd >= FD_SETSIZE, which means they'd be making assumptions that the underlying code is cloudlibc.
WASI API isn't relevant because it doesn't define fd_set, and this is purely about the select() API which is entirely part of WASI libc.
- Lingua principale
- C
- Stelle
- 1k
- Fork
- 268
- Merge medio
- 1g 3h
- PR unite (30g)
- 20
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di WebAssembly/wasi-libc
-
wasip2: enabling O_APPEND with fcntl reuses the old positional output stream and overwrites the fileAperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 70/100
WebAssembly/wasi-libc#919 ·
I maintainer di solito rispondono entro 1 giorno
-
wasip2/wasip3: reads never see data appended to a file after reaching EOFForse già presa @libsmol l’ha presa 25 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 61/100
WebAssembly/wasi-libc#889 ·
I maintainer di solito rispondono entro 1 giorno
-
Contradicting `SOL_TCP` and `SOL_UDP` definition for p1Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
WebAssembly/wasi-libc#855 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
WebAssembly/wasi-libc#815 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
WebAssembly/wasi-libc#809 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di WebAssembly/wasi-libc
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
389ds/389-ds-base#8152 ·
I maintainer di solito rispondono entro 2 giorni
-
meta:feature-request
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
mpv-player/mpv#18855 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
[FIX]: File Tree in appApertabug help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
isolation2 lockmodes fails on cassert builds: extra AccessShareLock on partition rootForse già presa @tuhaihe l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
apache/cloudberry#2356 ·
I maintainer di solito rispondono entro 2 giorni