Date: Sun, 6 Nov 2011 23:21:19 -0500 From: Arnaud Lacombe <lacombar@gmail.com> To: Kostik Belousov <kostikbel@gmail.com> Cc: "K. Macy" <kmacy@freebsd.org>, Alan Cox <alc@rice.edu>, Andriy Gapon <avg@freebsd.org>, freebsd-current@freebsd.org, Benjamin Kaduk <kaduk@mit.edu>, Penta Upa <bsdboot@gmail.com> Subject: Re: vm_page_t related KBI [Was: Re: panic at vm_page_wire with FreeBSD 9.0 Beta 3] Message-ID: <CACqU3MXH%2ByBnBPNA_FD2G_KPLifzc2h7a5=ErnO=xu_FEmg4TQ@mail.gmail.com> In-Reply-To: <20111105141306.GW50300@deviant.kiev.zoral.com.ua> References: <alpine.GSO.1.10.1111020203230.882@multics.mit.edu> <4EB11C32.80106@FreeBSD.org> <4EB22938.4050803@rice.edu> <20111103132437.GV50300@deviant.kiev.zoral.com.ua> <4EB2D48E.1030102@rice.edu> <20111104100828.GG50300@deviant.kiev.zoral.com.ua> <4EB40015.5040100@rice.edu> <20111104153004.GK50300@deviant.kiev.zoral.com.ua> <4EB4095D.3030303@rice.edu> <20111104160339.GM50300@deviant.kiev.zoral.com.ua> <20111105141306.GW50300@deviant.kiev.zoral.com.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi, On Sat, Nov 5, 2011 at 10:13 AM, Kostik Belousov <kostikbel@gmail.com> wrot= e: > On Fri, Nov 04, 2011 at 06:03:39PM +0200, Kostik Belousov wrote: > > Below is the KBI patch after vm_page_bits_t merge is done. > Again, I did not spent time converting all in-tree consumers > from the (potentially) loadable modules to the new KPI until it > is agreed upon. > > diff --git a/sys/nfsclient/nfs_bio.c b/sys/nfsclient/nfs_bio.c > index 305c189..7264cd1 100644 > --- a/sys/nfsclient/nfs_bio.c > +++ b/sys/nfsclient/nfs_bio.c > @@ -128,7 +128,7 @@ nfs_getpages(struct vop_getpages_args *ap) > =A0 =A0 =A0 =A0 * can only occur at the file EOF. > =A0 =A0 =A0 =A0 */ > =A0 =A0 =A0 =A0VM_OBJECT_LOCK(object); > - =A0 =A0 =A0 if (pages[ap->a_reqpage]->valid !=3D 0) { > + =A0 =A0 =A0 if (vm_page_read_valid(pages[ap->a_reqpage]) !=3D 0) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0for (i =3D 0; i < npages; ++i) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (i !=3D ap->a_reqpage) = { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0vm_page_lo= ck(pages[i]); > @@ -198,16 +198,16 @@ nfs_getpages(struct vop_getpages_args *ap) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * Read operation filled a= n entire page > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */ > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 m->valid =3D VM_PAGE_BITS_A= LL; > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 KASSERT(m->dirty =3D=3D 0, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 vm_page_write_valid(m, VM_P= AGE_BITS_ALL); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 KASSERT(vm_page_read_dirty(= m) =3D=3D 0, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0("nfs_getpages: pa= ge %p is dirty", m)); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} else if (size > toff) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * Read operation filled a= partial page. > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */ > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 m->valid =3D 0; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 vm_page_write_valid(m, 0); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0vm_page_set_valid(m, 0, si= ze - toff); > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 KASSERT(m->dirty =3D=3D 0, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 KASSERT(vm_page_read_dirty(= m) =3D=3D 0, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0("nfs_getpages: pa= ge %p is dirty", m)); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} else { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* > diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c > index 389aea5..2f41e70 100644 > --- a/sys/vm/vm_page.c > +++ b/sys/vm/vm_page.c > @@ -2677,6 +2677,66 @@ vm_page_test_dirty(vm_page_t m) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0vm_page_dirty(m); > =A0} > > +void > +vm_page_lock_func(vm_page_t m, const char *file, int line) > +{ > + > +#if LOCK_DEBUG > 0 || defined(MUTEX_NOINLINE) > + =A0 =A0 =A0 _mtx_lock_flags(vm_page_lockptr(m), 0, file, line); > +#else > + =A0 =A0 =A0 __mtx_lock(vm_page_lockptr(m), 0, file, line); > +#endif > +} > + Why do you re-implement the wheel ? all the point of these assessors is to hide implementation detail. IMO, you should restrict yourself to the documented API from mutex(9), only. Oh, wait, you end-up using LOCK_FILE instead of just __FILE__, but wait LOCK_FILE is either just __FILE__, or NULL, depending on LOCK_DEBUG, but you wouldn't have those function without INVARIANTS.... This whole LOCK_FILE/LOCK_LINE seem completely fracked-up... If you don't want this code in INVARIANTS, but in LOCK_DEBUG, only make it live only in the LOCK_DEBUG case. Btw, let me also question the use of non-inline functions. > +void > +vm_page_unlock_func(vm_page_t m, const char *file, int line) > +{ > + > +#if LOCK_DEBUG > 0 || defined(MUTEX_NOINLINE) > + =A0 =A0 =A0 _mtx_unlock_flags(vm_page_lockptr(m), 0, file, line); > +#else > + =A0 =A0 =A0 __mtx_unlock(vm_page_lockptr(m), curthread, 0, file, line); > +#endif > +} > + > +int > +vm_page_trylock_func(vm_page_t m, const char *file, int line) > +{ > + > + =A0 =A0 =A0 return (_mtx_trylock(vm_page_lockptr(m), 0, file, line)); > +} > + > +void > +vm_page_lock_assert_func(vm_page_t m, int a, const char *file, int line) > +{ > + > +#ifdef INVARIANTS > + =A0 =A0 =A0 _mtx_assert(vm_page_lockptr(m), a, file, line); > +#endif > +} > + same remark on all the above. > +vm_page_bits_t > +vm_page_read_dirty_func(vm_page_t m) > +{ > + > + =A0 =A0 =A0 return (m->dirty); > +} > + > +vm_page_bits_t > +vm_page_read_valid_func(vm_page_t m) > +{ > + > + =A0 =A0 =A0 return (m->valid); > +} > + > +void > +vm_page_write_valid_func(vm_page_t m, vm_page_bits_t v) > +{ > + > + =A0 =A0 =A0 m->valid =3D v; > +} > + > + > =A0int so_zerocp_fullpage =3D 0; > > =A0/* > diff --git a/sys/vm/vm_page.h b/sys/vm/vm_page.h > index 7099b70..4f8f71e 100644 > --- a/sys/vm/vm_page.h > +++ b/sys/vm/vm_page.h > @@ -218,12 +218,50 @@ extern struct vpglocks pa_lock[]; > > =A0#define =A0 =A0 =A0 =A0PA_LOCK_ASSERT(pa, a) =A0 mtx_assert(PA_LOCKPTR= (pa), (a)) > > +#ifdef KLD_MODULE > +#define =A0 =A0 =A0 =A0vm_page_lock(m) =A0 =A0 =A0 =A0 vm_page_lock_func= ((m), LOCK_FILE, LOCK_LINE) > +#define =A0 =A0 =A0 =A0vm_page_unlock(m) =A0 =A0 =A0 vm_page_unlock_func= ((m), LOCK_FILE, LOCK_LINE) > +#define =A0 =A0 =A0 =A0vm_page_trylock(m) =A0 =A0 =A0vm_page_trylock_fun= c((m), LOCK_FILE, LOCK_LINE) > +#ifdef INVARIANTS > +#define =A0 =A0 =A0 =A0vm_page_lock_assert(m, a) =A0 =A0 =A0 \ > + =A0 =A0vm_page_lock_assert_func((m), (a), LOCK_FILE, LOCK_LINE) > +#else > +#define =A0 =A0 =A0 =A0vm_page_lock_assert(m, a) > +#endif > + > +#define =A0 =A0 =A0 =A0vm_page_read_dirty(m) =A0 vm_page_read_dirty_func= ((m)) > +#define =A0 =A0 =A0 =A0vm_page_read_valid(m) =A0 vm_page_read_valid_func= ((m)) > +#define =A0 =A0 =A0 =A0vm_page_write_valid(m, v) =A0 =A0 =A0 vm_page_wri= te_valid_func((m), (v)) > + > +#else =A0/* KLD_MODULE */ > =A0#define =A0 =A0 =A0 =A0vm_page_lockptr(m) =A0 =A0 =A0(PA_LOCKPTR(VM_PA= GE_TO_PHYS((m)))) > =A0#define =A0 =A0 =A0 =A0vm_page_lock(m) =A0 =A0 =A0 =A0 mtx_lock(vm_pag= e_lockptr((m))) > =A0#define =A0 =A0 =A0 =A0vm_page_unlock(m) =A0 =A0 =A0 mtx_unlock(vm_pag= e_lockptr((m))) > =A0#define =A0 =A0 =A0 =A0vm_page_trylock(m) =A0 =A0 =A0mtx_trylock(vm_pa= ge_lockptr((m))) > =A0#define =A0 =A0 =A0 =A0vm_page_lock_assert(m, a) =A0 =A0 =A0 mtx_asser= t(vm_page_lockptr((m)), (a)) > > +static inline vm_page_bits_t > +vm_page_read_dirty(vm_page_t m) > +{ > + > + =A0 =A0 =A0 return (m->dirty); > +} > + > +static inline vm_page_bits_t > +vm_page_read_valid(vm_page_t m) > +{ > + > + =A0 =A0 =A0 return (m->valid); > +} > + > +static inline void > +vm_page_write_valid(vm_page_t m, vm_page_bits_t v) > +{ > + > + =A0 =A0 =A0 m->valid =3D v; > +} > +#endif > + > =A0#define =A0 =A0 =A0 =A0vm_page_queue_free_mtx =A0vm_page_queue_free_lo= ck.data > =A0/* > =A0* These are the flags defined for vm_page. > @@ -403,6 +441,15 @@ void vm_page_cowfault (vm_page_t); > =A0int vm_page_cowsetup(vm_page_t); > =A0void vm_page_cowclear (vm_page_t); > > +void vm_page_lock_func(vm_page_t m, const char *file, int line); > +void vm_page_unlock_func(vm_page_t m, const char *file, int line); > +int vm_page_trylock_func(vm_page_t m, const char *file, int line); > +void vm_page_lock_assert_func(vm_page_t m, int a, const char *file, int = line); > + > +vm_page_bits_t vm_page_read_dirty_func(vm_page_t m); > +vm_page_bits_t vm_page_read_valid_func(vm_page_t m); > +void vm_page_write_valid_func(vm_page_t m, vm_page_bits_t v); > + > =A0#ifdef INVARIANTS > =A0void vm_page_object_lock_assert(vm_page_t m); > =A0#define =A0 =A0 =A0 =A0VM_PAGE_OBJECT_LOCK_ASSERT(m) =A0 vm_page_objec= t_lock_assert(m) >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CACqU3MXH%2ByBnBPNA_FD2G_KPLifzc2h7a5=ErnO=xu_FEmg4TQ>