<table><tr><td style="">jakobkummerow updated this revision to Diff 75616.<br />jakobkummerow retitled this revision from "Linux/cpuinfo.c: bump CPUINFOBUFSIZE for 12+ core CPUs" to "Linux/cpuinfo.c: grow buffer size as needed for 12+ core CPUs".<br />jakobkummerow edited the summary of this revision. <a href="https://phabricator.kde.org/transactions/detail/PHID-XACT-DREV-22g7otfiznbbumb/">(Show Details)</a><br />jakobkummerow added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D27362">View Revision</a></tr></table><br /><div><div><p>OK, here's a version that scales the buffer size as needed.</p></div></div><br /><div><strong>CHANGES TO REVISION SUMMARY</strong><div><div style="white-space: pre-wrap; color: #74777D;"><div style="padding: 8px 0;">...</div>The buffer is currently 32K<span style="padding: 0 2px; color: #333333; background: rgba(251, 175, 175, .7);">B large</span><span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);">iB large, which is not enough on modern hardware (e.g. 12-core/24-thread systems exceed it). This patch lowers the initial size to 8KiB to be as memory-efficient as possible on low-end systems (dual/quadcore systems shouldn't ever need to grow it)</span>, <span style="padding: 0 2px; color: #333333; background: rgba(251, 175, 175, .7);">which is not enough on modern hardware.</span><span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);">and grows the buffer size as needed to accommodate arbitrarily many CPUs (tested on a 72-thread system,</span> <span style="padding: 0 2px; color: #333333; background: rgba(251, 175, 175, .7);">This patch bumps it to 256K</span><span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);">where the buffer grows four times</span>, <span style="padding: 0 2px; color: #333333; background: rgba(251, 175, 175, .7);">in order to accommodate current hardware and be future-proof for a few years</span><span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);">reaching 128KiB final size)</span>.<br />
<br />
<span style="padding: 0 2px; color: #333333; background: rgba(251, 175, 175, .7);">I can provide two specific data points</span><span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);">When the buffer needs to grow, its size is doubled</span>, <span style="padding: 0 2px; color: #333333; background: rgba(251, 175, 175, .7);">measured with `cat /proc/cpuinfo | wc -c`:<br />
- on a 12C24T AMD machine: ~36K<br />
- on a 36C72T Intel machine: ~102K<br />
Extrapolating</span><span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);">so the overall cost of the growth scales linearly with the file size (on average, each byte is copied to a larger buffer at most once). Also, the buffer size is remembered as long as the process runs</span>, <span style="padding: 0 2px; color: #333333; background: rgba(251, 175, 175, .7);">I estimate that the biggest CPUs available today (Ryzen 3990</span><span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);">so the cost of the growth is only incurred once on startup (or if additional CPUs come online</span>, <span style="padding: 0 2px; color: #333333; background: rgba(251, 175, 175, .7);">64C128T) will need ~192K (but I don't have one of those available to test on</span><span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);">which is probably rare</span>).<div style="padding: 8px 0;">...</div></div></div></div><br /><div><strong>CHANGES SINCE LAST UPDATE</strong><div><a href="https://phabricator.kde.org/D27362?vs=75593&id=75616">https://phabricator.kde.org/D27362?vs=75593&id=75616</a></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D27362">https://phabricator.kde.org/D27362</a></div></div><br /><div><strong>AFFECTED FILES</strong><div><div>ksysguardd/Linux/cpuinfo.c</div></div></div><br /><div><strong>To: </strong>jakobkummerow, davidedmundson, ahiemstra<br /><strong>Cc: </strong>ahiemstra, cfeck, plasma-devel, Orage, LeGast00n, The-Feren-OS-Dev, cblack, jraleigh, zachus, fbampaloukas, GB_2, ragreen, ZrenBot, ngraham, alexeymin, himcesjf, lesliezhai, ali-mohamed, jensreuterberg, abetts, sebas, apol, mart<br /></div>