Linux kernel 6.12 SLOC
22nd November 2024I don't believe SLOC (Source Lines of Code) is a particularly great indicator of complexity or quality (Please, please never use SLOC as a KPI!). But it's a useful "finger in the air" way to get a sense of the size of a project and its composition (which modules and languages contribute the most code).
I ran David Wheeler's sloccount against Linux kernel 6.12 and got the following results.
Interesting takeaways
I'm not a kernel developer (in fact, it's been years since I had to compile my own kernel), so for those familiar with the codebase none of this will be shocking, but I found the following stats quite interesting:
- There are around 26m SLOC.
- Around 70% of the code comes from drivers.
- 98% of the code base is C.
- There's way more Python (61k SLOC) than I expected.
- There's about as much shell code as I would expect (133k SLOC).
Raw output
SLOC Directory SLOC-by-Language (Sorted)
18548831 drivers ansic=18539246,asm=4567,yacc=1679,python=1485,perl=792,lex=771,sh=291
1777035 arch ansic=1503474,asm=259266,perl=12102,sh=1426,awk=762,sed=5
1205419 sound ansic=1205419
1166669 fs ansic=1166669
998041 tools ansic=810638,sh=122122,python=51806,perl=4881,asm=4672,yacc=1707,cpp=1141,lex=991,awk=58,ruby=25
942831 net ansic=942831
795503 include ansic=793056,cpp=2447
319187 kernel ansic=319130,sh=57
180838 lib ansic=180662,perl=123,sh=34,awk=13,asm=6
126769 mm ansic=126769
89850 crypto ansic=89850
77226 security ansic=77226
68266 scripts ansic=32842,perl=18123,sh=5859,python=5757,cpp=2305,yacc=1537,lex=1177,awk=606,asm=37,sed=23
43111 block ansic=43111
28013 samples ansic=25705,sh=2308
15834 io_uring ansic=15834
7343 virt ansic=7343
6875 ipc ansic=6875
4925 Documentation python=2046,perl=1571,sh=943,ansic=237,awk=128
3082 init ansic=3082
948 usr ansic=609,sh=196,perl=131,asm=12
754 certs ansic=674,asm=55,awk=25
221 rust ansic=221
0 LICENSES (none)
0 top_dir (none)
Totals grouped by language (dominant language first):
ansic: 25891503 (98.05%)
asm: 268615 (1.02%)
sh: 133236 (0.50%)
python: 61094 (0.23%)
perl: 37723 (0.14%)
cpp: 5893 (0.02%)
yacc: 4923 (0.02%)
lex: 2939 (0.01%)
awk: 1592 (0.01%)
sed: 28 (0.00%)
ruby: 25 (0.00%)
Total Physical Source Lines of Code (SLOC) = 26,407,571
Development Effort Estimate, Person-Years (Person-Months) = 8,787.09 (105,445.03)
(Basic COCOMO model, Person-Months = 2.4 * (KSLOC**1.05))
Schedule Estimate, Years (Months) = 16.89 (202.62)
(Basic COCOMO model, Months = 2.5 * (person-months**0.38))
Estimated Average Number of Developers (Effort/Schedule) = 520.40
Total Estimated Cost to Develop = $ 1,187,015,808
(average salary = $56,286/year, overhead = 2.40).