[Toybox] New toy: vmstat

Elie De Brauwer eliedebrauwer at gmail.com
Mon Apr 9 23:49:07 PDT 2012


On 04/10/2012 07:56 AM, Rob Landley wrote:
> On 04/09/2012 06:39 AM, Elie De Brauwer wrote:
>> Hello all,
>>
>> In attachment you can find a no-nonsense vmstat implementation. Meaning
>> most of the special things (which I personally never bothered to use)
>> are dropped. (vmstat -d however is still under consideration, please
>> shout if you're waiting for a vmstat -d or any other options).
>
> Yay!  Applied.
>
> You're reading multiple things into toybuf and apparently relying on the
> existing prezeroed nature of toybuf to provide your null terminator, but
> if the second thing you read in is shorter than your first and the file
> you're reading in doesn't end with a null you'll have extra leftover
> garbage from the previous file.
>
> I'm not sure the fdlength() check and error_exit() buy you anything more
> than just read(sizeof(toybuf)-1) would?  If you miss some data at the
> end, most likely it'll still work and the current sizes on my box are
> all ~1.5k vs 4k buffer size. (It is theorentically possible a number
> could get truncated at EOF and thus be viewed as the wrong value, but
> even on systems with terabytes of memory I don't see the numbers growing
> enough to bring us to 3k, and I believe new fields get added at the
> _end_ of the file for backwards compatability reasons...)

Just to sleep better at night I'd fix the null termination, consider it 
a bug on my side rather than done on purpose. Vmstat uses a 64k buffer 
to read the data. I actually just wanted a clean way to inform people 
that there is some issue with buffering without the need to start 
dynamically allocating memory, if this ever appears it'll be years from 
now with cpu entries/interrupts a-la-plenty in /proc/stat. For this 
using an if (read(sizeof(toybuf)-1) == sizeof(toybuf)-1) error_exit() 
seems more suited than the current fdlength() solution is.

Is anybody interested in other vmstat options ? Mainly thinking vmstat -d ?

gr
E.



-- 
Elie De Brauwer


 1334040547.0


More information about the Toybox mailing list