From: "Jan Beulich" Subject: [PATCH v2] x86/memshr: fix preemption in relinquish_shared_pages() Date: Tue, 17 Dec 2013 15:23:19 +0000 Message-ID: <52B07A77020000780010E38A@nat28.tlf.novell.com> References: <52B0224B020000780010E067@nat28.tlf.novell.com> <20131217144423.GE32721@deinos.phlegethon.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part91A27E77.1__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VswUV-00085s-RS for xen-devel@lists.xenproject.org; Tue, 17 Dec 2013 15:23:24 +0000 In-Reply-To: <20131217144423.GE32721@deinos.phlegethon.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Tim Deegan , Andres Lagar-Cavilla List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part91A27E77.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline For one, should hypercall_preempt_check() return false the first time it gets called, it would never have got called again (because count, being checked for equality, didn't get reset to zero). And then, if there were a huge range of unshared pages, with count not getting incremented at all in that case there would also not be any preemption. Fix this by using a biased increment (ratio 1:16 for unshared vs shared pages), and flushing the count to zero in case of a "false" return from hypercall_preempt_check(). Signed-off-by: Jan Beulich --- v2: Adjust continuation detection as per Tim's request. --- b/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1290,15 +1290,21 @@ int relinquish_shared_pages(struct domai set_rc =3D p2m->set_entry(p2m, gfn, _mfn(0), PAGE_ORDER_4K, p2m_invalid, p2m_access_rwx); ASSERT(set_rc !=3D 0); - count++; + count +=3D 0x10; } + else + ++count; =20 - /* Preempt every 2MiB. Arbitrary */ - if ( (count =3D=3D 512) && hypercall_preempt_check() ) + /* Preempt every 2MiB (shared) or 32MiB (unshared) - arbitrary. = */ + if ( count >=3D 0x2000 ) { - p2m->next_shared_gfn_to_relinquish =3D gfn + 1; - rc =3D -EAGAIN; - break; + if ( hypercall_preempt_check() ) + { + p2m->next_shared_gfn_to_relinquish =3D gfn + 1; + rc =3D -EAGAIN; + break; + } + count =3D 0; } } =20 --=__Part91A27E77.1__= Content-Type: text/plain; name="x86-memshr-cleanup-preemption.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-memshr-cleanup-preemption.patch" x86/memshr: fix preemption in relinquish_shared_pages()=0A=0AFor one, = should hypercall_preempt_check() return false the first time=0Ait gets = called, it would never have got called again (because count,=0Abeing = checked for equality, didn't get reset to zero).=0A=0AAnd then, if there = were a huge range of unshared pages, with count not=0Agetting incremented = at all in that case there would also not be any=0Apreemption.=0A=0AFix = this by using a biased increment (ratio 1:16 for unshared vs shared=0Apages= ), and flushing the count to zero in case of a "false" return from=0Ahyperc= all_preempt_check().=0A=0ASigned-off-by: Jan Beulich =0A= ---=0Av2: Adjust continuation detection as per Tim's request.=0A=0A--- = b/xen/arch/x86/mm/mem_sharing.c=0A+++ b/xen/arch/x86/mm/mem_sharing.c=0A@@ = -1290,15 +1290,21 @@ int relinquish_shared_pages(struct domai=0A = set_rc =3D p2m->set_entry(p2m, gfn, _mfn(0), PAGE_ORDER_4K,=0A = p2m_invalid, p2m_access_rwx);=0A = ASSERT(set_rc !=3D 0);=0A- count++;=0A+ count +=3D = 0x10;=0A }=0A+ else=0A+ ++count;=0A =0A- = /* Preempt every 2MiB. Arbitrary */=0A- if ( (count =3D=3D 512) && = hypercall_preempt_check() )=0A+ /* Preempt every 2MiB (shared) or = 32MiB (unshared) - arbitrary. */=0A+ if ( count >=3D 0x2000 )=0A = {=0A- p2m->next_shared_gfn_to_relinquish =3D gfn + 1;=0A- = rc =3D -EAGAIN;=0A- break;=0A+ if ( = hypercall_preempt_check() )=0A+ {=0A+ p2m->next_s= hared_gfn_to_relinquish =3D gfn + 1;=0A+ rc =3D -EAGAIN;=0A+= break;=0A+ }=0A+ count =3D 0;=0A = }=0A }=0A =0A --=__Part91A27E77.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part91A27E77.1__=--