From: "Jan Beulich" Subject: [PATCH] slightly consolidate code in free_domheap_pages() Date: Fri, 20 Jun 2014 13:40:09 +0100 Message-ID: <53A447C9020000780001BF5F@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part0D3FF7B9.1__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Wxy71-0000fY-35 for xen-devel@lists.xenproject.org; Fri, 20 Jun 2014 12:40:11 +0000 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: Ian Campbell , 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. --=__Part0D3FF7B9.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 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1724,47 +1724,45 @@ 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 + { + 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); --=__Part0D3FF7B9.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=0A--- a/xen/common/page_alloc.c=0A+++ b/xen/common/p= age_alloc.c=0A@@ -1724,47 +1724,45 @@ 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_list);=0A- = }=0A+ /* NB. May recursively lock from relinquish_memory(). = */=0A+ spin_lock_recursive(&d->page_alloc_lock);=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_de= l2(&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+ = 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 --=__Part0D3FF7B9.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 --=__Part0D3FF7B9.1__=--