From: "Jan Beulich" Subject: [PATCH v2] slightly consolidate code in free_domheap_pages() Date: Tue, 24 Jun 2014 13:36:14 +0100 Message-ID: <53A98CDE020000780001CCD6@mail.emea.novell.com> References: <53A447C9020000780001BF5F@mail.emea.novell.com> <1403604282.25047.3.camel@kazak.uk.xensource.com> <53A96E30020000780001CB9E@mail.emea.novell.com> <1403609242.27984.11.camel@kazak.uk.xensource.com> <53A982E4020000780001CC5A@mail.emea.novell.com> <1403611820.30061.2.camel@kazak.uk.xensource.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part4C7EBBAE.1__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WzPxS-00014j-0Z for xen-devel@lists.xenproject.org; Tue, 24 Jun 2014 12:36:18 +0000 In-Reply-To: <1403611820.30061.2.camel@kazak.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell , xen-devel Cc: Keir Fraser , Ian Jackson , Tim Deegan 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. --=__Part4C7EBBAE.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ... to combine the three scrubbing paths into a single one. Signed-off-by: Jan Beulich --- v2: Add a comment to an ASSERT() deemed unclear/non-obvious otherwise. --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1724,47 +1724,52 @@ void free_domheap_pages(struct page_info =20 spin_unlock_recursive(&d->page_alloc_lock); } - else if ( likely(d !=3D NULL) && likely(d !=3D dom_cow) ) + else { - /* NB. May recursively lock from relinquish_memory(). */ - spin_lock_recursive(&d->page_alloc_lock); + bool_t scrub; =20 - for ( i =3D 0; i < (1 << order); i++ ) + if ( likely(d) && likely(d !=3D dom_cow) ) { - BUG_ON((pg[i].u.inuse.type_info & PGT_count_mask) !=3D 0); - page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list); - } + /* NB. May recursively lock from relinquish_memory(). */ + spin_lock_recursive(&d->page_alloc_lock); =20 - drop_dom_ref =3D !domain_adjust_tot_pages(d, -(1 << order)); - - spin_unlock_recursive(&d->page_alloc_lock); + for ( i =3D 0; i < (1 << order); i++ ) + { + BUG_ON((pg[i].u.inuse.type_info & PGT_count_mask) !=3D = 0); + page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list= ); + } + + drop_dom_ref =3D !domain_adjust_tot_pages(d, -(1 << order)); + + spin_unlock_recursive(&d->page_alloc_lock); + + /* + * Normally we expect a domain to clear pages before freeing = them, + * if it cares about the secrecy of their contents. However, = after + * a domain has died we assume responsibility for erasure. + */ + scrub =3D !!d->is_dying; + } + else + { + /* + * All we need to check is that on dom_cow only order-0 = chunks + * make it here. Due to the if() above, the only two possible + * cases right now are d =3D=3D NULL and d =3D=3D dom_cow. To = protect + * against relaxation of that if() condition without updating = the + * check here, don't check d !=3D dom_cow for now. + */ + ASSERT(!d || !order); + drop_dom_ref =3D 0; + scrub =3D 1; + } =20 - /* - * Normally we expect a domain to clear pages before freeing = them, if=20 - * it cares about the secrecy of their contents. However, after = a=20 - * domain has died we assume responsibility for erasure. - */ - if ( unlikely(d->is_dying) ) + if ( unlikely(scrub) ) for ( i =3D 0; i < (1 << order); i++ ) scrub_one_page(&pg[i]); =20 free_heap_pages(pg, order); } - else if ( unlikely(d =3D=3D dom_cow) ) - { - ASSERT(order =3D=3D 0);=20 - scrub_one_page(pg); - free_heap_pages(pg, 0); - drop_dom_ref =3D 0; - } - else - { - /* Freeing anonymous domain-heap pages. */ - for ( i =3D 0; i < (1 << order); i++ ) - scrub_one_page(&pg[i]); - free_heap_pages(pg, order); - drop_dom_ref =3D 0; - } =20 if ( drop_dom_ref ) put_domain(d); --=__Part4C7EBBAE.1__= Content-Type: text/plain; name="free-domheap-pages-consolidate.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="free-domheap-pages-consolidate.patch" slightly consolidate code in free_domheap_pages()=0A=0A... to combine the = three scrubbing paths into a single one.=0A=0ASigned-off-by: Jan Beulich = =0A---=0Av2: Add a comment to an ASSERT() deemed = unclear/non-obvious otherwise.=0A=0A--- a/xen/common/page_alloc.c=0A+++ = b/xen/common/page_alloc.c=0A@@ -1724,47 +1724,52 @@ void free_domheap_pages= (struct page_info=0A =0A spin_unlock_recursive(&d->page_alloc_lock)= ;=0A }=0A- else if ( likely(d !=3D NULL) && likely(d !=3D dom_cow) = )=0A+ else=0A {=0A- /* NB. May recursively lock from = relinquish_memory(). */=0A- spin_lock_recursive(&d->page_alloc_lock)= ;=0A+ bool_t scrub;=0A =0A- for ( i =3D 0; i < (1 << order); = i++ )=0A+ if ( likely(d) && likely(d !=3D dom_cow) )=0A = {=0A- BUG_ON((pg[i].u.inuse.type_info & PGT_count_mask) !=3D = 0);=0A- page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_li= st);=0A- }=0A+ /* NB. May recursively lock from = relinquish_memory(). */=0A+ spin_lock_recursive(&d->page_alloc_l= ock);=0A =0A- drop_dom_ref =3D !domain_adjust_tot_pages(d, -(1 << = order));=0A-=0A- spin_unlock_recursive(&d->page_alloc_lock);=0A+ = for ( i =3D 0; i < (1 << order); i++ )=0A+ {=0A+ = BUG_ON((pg[i].u.inuse.type_info & PGT_count_mask) !=3D 0);=0A+ = page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);=0A+= }=0A+=0A+ drop_dom_ref =3D !domain_adjust_tot_pages(= d, -(1 << order));=0A+=0A+ spin_unlock_recursive(&d->page_alloc_= lock);=0A+=0A+ /*=0A+ * Normally we expect a domain = to clear pages before freeing them,=0A+ * if it cares about = the secrecy of their contents. However, after=0A+ * a domain = has died we assume responsibility for erasure.=0A+ */=0A+ = scrub =3D !!d->is_dying;=0A+ }=0A+ else=0A+ = {=0A+ /*=0A+ * All we need to check is that on = dom_cow only order-0 chunks=0A+ * make it here. Due to the = if() above, the only two possible=0A+ * cases right now are d = =3D=3D NULL and d =3D=3D dom_cow. To protect=0A+ * against = relaxation of that if() condition without updating the=0A+ * = check here, don't check d !=3D dom_cow for now.=0A+ */=0A+ = ASSERT(!d || !order);=0A+ drop_dom_ref =3D 0;=0A+ = scrub =3D 1;=0A+ }=0A =0A- /*=0A- * Normally we = expect a domain to clear pages before freeing them, if =0A- * it = cares about the secrecy of their contents. However, after a =0A- * = domain has died we assume responsibility for erasure.=0A- */=0A- = if ( unlikely(d->is_dying) )=0A+ if ( unlikely(scrub) )=0A = for ( i =3D 0; i < (1 << order); i++ )=0A = scrub_one_page(&pg[i]);=0A =0A free_heap_pages(pg, order);=0A = }=0A- else if ( unlikely(d =3D=3D dom_cow) )=0A- {=0A- = ASSERT(order =3D=3D 0); =0A- scrub_one_page(pg);=0A- = free_heap_pages(pg, 0);=0A- drop_dom_ref =3D 0;=0A- }=0A- = else=0A- {=0A- /* Freeing anonymous domain-heap pages. */=0A- = for ( i =3D 0; i < (1 << order); i++ )=0A- scrub_one_page(&p= g[i]);=0A- free_heap_pages(pg, order);=0A- drop_dom_ref =3D = 0;=0A- }=0A =0A if ( drop_dom_ref )=0A put_domain(d);=0A --=__Part4C7EBBAE.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 --=__Part4C7EBBAE.1__=--