From mboxrd@z Thu Jan 1 00:00:00 1970 From: Konrad Rzeszutek Wilk Subject: Re: Load increase after memory upgrade (part2) Date: Wed, 13 Jun 2012 12:55:29 -0400 Message-ID: <20120613165529.GA10986@phenom.dumpdata.com> References: <20120511194138.GA30099@phenom.dumpdata.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline In-Reply-To: <20120511194138.GA30099@phenom.dumpdata.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: Carsten Schiers Cc: Konrad Rzeszutek Wilk , xen-devel , Jan Beulich , Sander Eikelenboom List-Id: xen-devel@lists.xenproject.org On Fri, May 11, 2012 at 03:41:38PM -0400, Konrad Rzeszutek Wilk wrote: > On Fri, May 11, 2012 at 11:39:08AM +0200, Carsten Schiers wrote: > > Hi Konrad, > > = > > =A0 > > don't want to be pushy, as I have no real issue. I simply use the Xenif= ied kernel or take the double load. = > > = > > But I think this mistery is still open. My last status was that the lat= est patch you produced resulted in a BUG, = > = > Yes, that is right. Thank you for reminding me. > > = > > so we still have not checked whether our theory is correct. > = > No we haven't. And I should be have no trouble reproducing this. I can ju= st write > a tiny module that allocates vmalloc_32(). Done. Found some bugs.. and here is anew version. Can you please try it out? It has the #define DEBUG 1 set so it should print a lot of stuff when the DVB module loads. If it crashes please send me the full log. Thanks. >>From 5afb4ab1fb3d2b059fe1a6db93ab65cb76f43b8a Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Thu, 31 May 2012 14:21:04 -0400 Subject: [PATCH] xen/vmalloc_32: Use xen_exchange_.. when GFP flags are DMA. [v3] Signed-off-by: Konrad Rzeszutek Wilk --- arch/x86/xen/mmu.c | 187 +++++++++++++++++++++++++++++++++++++++++++++= ++- include/xen/xen-ops.h | 2 + mm/vmalloc.c | 18 +++++- 3 files changed, 202 insertions(+), 5 deletions(-) diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c index 3a73785..960d206 100644 --- a/arch/x86/xen/mmu.c +++ b/arch/x86/xen/mmu.c @@ -47,6 +47,7 @@ #include #include #include +#include = #include = @@ -2051,6 +2052,7 @@ void __init xen_init_mmu_ops(void) /* Protected by xen_reservation_lock. */ #define MAX_CONTIG_ORDER 9 /* 2MB */ static unsigned long discontig_frames[1< 0x%lx (mfn)\n", __func__,pfns_in[i= ], mfns_out[i]); + } +#endif BUG_ON(!success && ((exchange.nr_exchanged !=3D 0) || (rc =3D=3D 0))); BUG_ON(success && (rc !=3D 0)); = @@ -2231,8 +2322,8 @@ void xen_destroy_contiguous_region(unsigned long vsta= rt, unsigned int order) xen_zap_pfn_range(vstart, order, NULL, out_frames); = /* 3. Do the exchange for non-contiguous MFNs. */ - success =3D xen_exchange_memory(1, order, &in_frame, 1UL << order, - 0, out_frames, 0); + success =3D xen_exchange_memory(1, order, &in_frame, + 1UL << order, 0, out_frames, 0); = /* 4. Map new pages in place of old pages. */ if (success) @@ -2244,6 +2335,94 @@ void xen_destroy_contiguous_region(unsigned long vst= art, unsigned int order) } EXPORT_SYMBOL_GPL(xen_destroy_contiguous_region); = +int xen_limit_pages_to_max_mfn(struct page *pages, unsigned int order, + unsigned int address_bits) +{ + unsigned long *in_frames =3D discontig_frames, *out_frames =3D limited_fr= ames; + unsigned long flags; + struct page *page; + int success; + int i, n =3D 0; + unsigned long _limit_map; + unsigned long *limit_map; + + if (xen_feature(XENFEAT_auto_translated_physmap)) + return 0; + + if (unlikely(order > MAX_CONTIG_ORDER)) + return -ENOMEM; + + if (BITS_PER_LONG >> order) { + limit_map =3D kzalloc(BITS_TO_LONGS(1U << order) * + sizeof(*limit_map), GFP_KERNEL); + if (unlikely(!limit_map)) + return -ENOMEM; + } else + limit_map =3D &_limit_map; + + /* 0. Construct our per page bitmap lookup. */ + + if (address_bits && (address_bits < PAGE_SHIFT)) + return -EINVAL; + + if (order) + bitmap_zero(limit_map, 1U << order); + else + __set_bit(0, limit_map); + + /* 1. Clear the pages */ + for (i =3D 0; i < (1ULL << order); i++) { + void *vaddr; + page =3D &pages[i]; + + vaddr =3D page_address(page); +#ifdef DEBUG + printk(KERN_INFO "%s: page: %p vaddr: %p 0x%lx(mfn) 0x%lx(pfn)\n", __fun= c__, page, vaddr, virt_to_mfn(vaddr), mfn_to_pfn(virt_to_mfn(vaddr))); +#endif + if (address_bits) { + if (!(virt_to_mfn(vaddr) >> (address_bits - PAGE_SHIFT))) + continue; + __set_bit(i, limit_map); + } + if (!PageHighMem(page)) + memset(vaddr, 0, PAGE_SIZE); + else { + memset(kmap(page), 0, PAGE_SIZE); + kunmap(page); + ++n; + } + } + /* Check to see if we actually have to do any work. */ + if (bitmap_empty(limit_map, 1U << order)) { + if (limit_map !=3D &_limit_map) + kfree(limit_map); + return 0; + } + if (n) + kmap_flush_unused(); + + spin_lock_irqsave(&xen_reservation_lock, flags); + + /* 2. Zap current PTEs. */ + n =3D xen_zap_page_range(pages, order, in_frames, NULL /*out_frames */, l= imit_map); + + /* 3. Do the exchange for non-contiguous MFNs. */ + success =3D xen_exchange_memory(n, 0 /* this is always called per page */= , in_frames, + n, 0, out_frames, address_bits); + + /* 4. Map new pages in place of old pages. */ + if (success) + xen_remap_exchanged_pages(pages, order, out_frames, 0, limit_map); + else + xen_remap_exchanged_pages(pages, order, NULL, *in_frames, limit_map); + + spin_unlock_irqrestore(&xen_reservation_lock, flags); + if (limit_map !=3D &_limit_map) + kfree(limit_map); + + return success ? 0 : -ENOMEM; +} +EXPORT_SYMBOL_GPL(xen_limit_pages_to_max_mfn); #ifdef CONFIG_XEN_PVHVM static void xen_hvm_exit_mmap(struct mm_struct *mm) { diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h index 6a198e4..2f8709f 100644 --- a/include/xen/xen-ops.h +++ b/include/xen/xen-ops.h @@ -29,4 +29,6 @@ int xen_remap_domain_mfn_range(struct vm_area_struct *vma, unsigned long mfn, int nr, pgprot_t prot, unsigned domid); = +int xen_limit_pages_to_max_mfn(struct page *pages, unsigned int order, + unsigned int address_bits); #endif /* INCLUDE_XEN_OPS_H */ diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 2aad499..194af07 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -31,6 +31,8 @@ #include #include = +#include +#include /*** Page table manipulation functions ***/ = static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long= end) @@ -1576,7 +1578,11 @@ static void *__vmalloc_area_node(struct vm_struct *a= rea, gfp_t gfp_mask, struct page **pages; unsigned int nr_pages, array_size, i; gfp_t nested_gfp =3D (gfp_mask & GFP_RECLAIM_MASK) | __GFP_ZERO; - + gfp_t dma_mask =3D gfp_mask & (__GFP_DMA | __GFP_DMA32); + if (xen_pv_domain()) { + if (dma_mask =3D=3D (__GFP_DMA | __GFP_DMA32)) + gfp_mask &=3D ~(__GFP_DMA | __GFP_DMA32); + } nr_pages =3D (area->size - PAGE_SIZE) >> PAGE_SHIFT; array_size =3D (nr_pages * sizeof(struct page *)); = @@ -1612,6 +1618,16 @@ static void *__vmalloc_area_node(struct vm_struct *a= rea, gfp_t gfp_mask, goto fail; } area->pages[i] =3D page; + if (xen_pv_domain()) { + if (dma_mask) { + if (xen_limit_pages_to_max_mfn(page, 0, 32)) { + area->nr_pages =3D i + 1; + goto fail; + } + if (gfp_mask & __GFP_ZERO) + clear_highpage(page); + } + } } = if (map_vm_area(area, prot, &pages)) -- = 1.7.7.6