kvm_read() vs ioctl performance
barney_cordoba at yahoo.com
Sat Mar 22 05:58:18 PDT 2008
--- Julian Elischer <julian at elischer.org> wrote:
> Barney Cordoba wrote:
> > --- Julian Elischer <julian at elischer.org> wrote:
> >> Barney Cordoba wrote:
> >>> --- Julian Elischer <julian at elischer.org> wrote:
> >>>> Barney Cordoba wrote:
> >>>>> I have an app which reads stats from the
> >>>>> periodically, and there can be a lot of
> >>>> iterations,
> >>>>> sometimes 20,000 or more. I'm thinking of
> >>>> converting
> >>>>> from an ioctl method to kvm_read(). KVM is
> >>>> certainly
> >>>>> simpler, but its not clear what overhead is
> >>>> involved,
> >>>>> since kvm_read() likely has to call the kernel
> >>>> also.
> >>>>> Does anyone have a handle on the difference in
> >>>>> overhead, assuming that the ioctl call is to a
> >>>> module
> >>>>> which does nothing more than copy the data and
> >>>> return?
> >>>> tried a shared memory page?
> >>> No, but I built a test and kvm_read is 70 times
> >>> faster, in
> >>> case anyone is interested.
> >> cool..
> >> the only downside is that we are trying to get
> >> from kvm direct
> >> access. (which is why a shared page might give
> >> same result with a
> >> stable API which is not libkvm... BTW on an SMP
> >> machine you have
> >> no way to ensure that your stats are coherent if
> >> use libkvm.
> > The app is portable, and I'd prefer not to have
> > different methods for LINUX and FreeBSD. When you
> > "coherent", what exactly do you mean?
> there is no synchronisation between your app and the
> I dont know what sized structure you are reading but
> how do you know
> that the device isn't half way through writing it?
> A mmapped page would be more portable,
> for example done in the way that a video frame
> buffer is done.
> All systems support that sort of semantic the same.
> Then you can use memory semaphores to make sure that
> the stuff is
> consistent, because you can write back.
Is this a page of memory, or some other "page"
concept? As I mentioned, there are n structures, and
there could be 20K or more of them. The structures are
72 bytes. Its also read-only, and not dreadfully
important that the stats are exactly tied to a precise
moment in time.
Its similar to netstat. The stats are continuously
being written. When we need to sync them, we can issue
a "snapshot" ioctl that locks and copies the current
stats to a static variable and then the variables are
Never miss a thing. Make Yahoo your home page.
More information about the freebsd-current