Skip to contentSkip to conversation

by default don't give all memory to dom0

PATCH In review Siddha, Suresh B 4 participants 11 messages Aug 18, 2005 – Aug 20, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 by default don't give all memory to dom0

On a system where swiotlb is used, by default xen fails to allocate memory for dom0's swiotlb contiguous memory request.

By default, xen needs to reserve some portion of memory to satisfy SWIOTLB and other contguous memory region requests. Following the current swiotlb enabling mechanism, Appended patch reserves 128MB of memory on systems with more than 2GB of RAM.

Ideally shouldn't we enable SWIOTLB in dom0 and this DMA memory reservation in hypervisor by default? Otherwise we will have a problem(even on systems with less than 2GB of RAM) in servicing a driver DMA request to a kmalloc'd buffer which spans more than a page or the various xen_create_contiguous_region() requests.

xen/arch/x86/domain_build.c +17 -2
diff -r 84ee014ebd41 xen/arch/x86/domain_build.c
@@ -34,6 +34,18 @@
         opt_dom0_mem = (unsigned int)(bytes >> 10);
 }
 custom_param("dom0_mem", parse_dom0_mem);
+
+static unsigned int reserve_dmapages = 0;
+static void parse_reserve_dmamem(char *s)
+{
+    unsigned long long bytes = parse_size_and_unit(s);
+    /* If no unit is specified we default to kB units, not bytes. */
+    if ( isdigit(s[strlen(s)-1]) )
+        reserve_dmapages = (unsigned int)bytes >> (PAGE_SHIFT - 10);
+    else
+        reserve_dmapages = (unsigned int)(bytes >> PAGE_SHIFT);
+}
+custom_param("dma_mem", parse_reserve_dmamem);
 
 static unsigned int opt_dom0_shadow = 0;
 boolean_param("dom0_shadow", opt_dom0_shadow);
@@ -137,10 +149,13 @@
 
     printk("*** LOADING DOMAIN 0 ***\n");
 
-    /* By default DOM0 is allocated all available memory. */
     d->max_pages = ~0U;
+    /* By default DOM0 is allocated (all available memory - reserved dma 
+       low memory) */
+    if (!reserve_dmapages && max_page > 0x7ffff)
+	reserve_dmapages = 32 * 1024; /* 128MB */
     if ( (nr_pages = opt_dom0_mem >> (PAGE_SHIFT - 10)) == 0 )
-        nr_pages = avail_domheap_pages() +
+        nr_pages = avail_domheap_pages() - reserve_dmapages +
             ((initrd_len + PAGE_SIZE - 1) >> PAGE_SHIFT) +
             ((image_len  + PAGE_SIZE - 1) >> PAGE_SHIFT);
#1 lore raw

Siddha, Suresh B wrote:
[...]

xen/arch/x86/domain_build.c line 47

Quoted 9 lines
xen/arch/x86/domain_build.c +9 -0
+static void parse_reserve_dmamem(char *s)
+{
+    unsigned long long bytes = parse_size_and_unit(s);
+    /* If no unit is specified we default to kB units, not bytes. */
+    if ( isdigit(s[strlen(s)-1]) )
+        reserve_dmapages = (unsigned int)bytes >> (PAGE_SHIFT - 10);
+    else
+        reserve_dmapages = (unsigned int)(bytes >> PAGE_SHIFT);
+}

Shouldn't the default unit be consistent for all Xen memory parameters?

Signature · 1 line
David Hopwood <[email protected]>
#2 lore raw
Quoted 14 lines · David Hopwood

Siddha, Suresh B wrote:
[...]

xen/arch/x86/domain_build.c line 47

Quoted 9 lines
xen/arch/x86/domain_build.c +9 -0
+static void parse_reserve_dmamem(char *s)
+{
+    unsigned long long bytes = parse_size_and_unit(s);
+    /* If no unit is specified we default to kB units, not bytes. */
+    if ( isdigit(s[strlen(s)-1]) )
+        reserve_dmapages = (unsigned int)bytes >> (PAGE_SHIFT - 10);
+    else
+        reserve_dmapages = (unsigned int)(bytes >> PAGE_SHIFT);
+}

Shouldn't the default unit be consistent for all Xen memory parameters?

I am just following the dom0_mem conventions for which default unit is kB. Am I missing something?

thanks,
suresh

#3 lore raw
Quoted 16 lines · Suresh B
Quoted 14 lines · David Hopwood

Siddha, Suresh B wrote:
[...]

xen/arch/x86/domain_build.c line 47

Quoted 9 lines
xen/arch/x86/domain_build.c +9 -0
+static void parse_reserve_dmamem(char *s)
+{
+    unsigned long long bytes = parse_size_and_unit(s);
+    /* If no unit is specified we default to kB units, not bytes. */
+    if ( isdigit(s[strlen(s)-1]) )
+        reserve_dmapages = (unsigned int)bytes >> (PAGE_SHIFT - 10);
+    else
+        reserve_dmapages = (unsigned int)(bytes >> PAGE_SHIFT);
+}

Shouldn't the default unit be consistent for all Xen memory parameters?

Quoted 2 lines

I am just following the dom0_mem conventions for which default unit is kB. Am I missing something?

If Kbytes is to be the default unit, then that default should probably be encoded in 'parse_size_and_unit', rather than having code like the above convert from bytes to Kbytes in many places.

Signature · 1 line
David Hopwood <[email protected]>
#4 lore raw
Quoted 17 lines · David Hopwood
Quoted 16 lines · Suresh B
Quoted 14 lines · David Hopwood

Siddha, Suresh B wrote:
[...]

xen/arch/x86/domain_build.c line 47

Quoted 9 lines
xen/arch/x86/domain_build.c +9 -0
+static void parse_reserve_dmamem(char *s)
+{
+    unsigned long long bytes = parse_size_and_unit(s);
+    /* If no unit is specified we default to kB units, not bytes. */
+    if ( isdigit(s[strlen(s)-1]) )
+        reserve_dmapages = (unsigned int)bytes >> (PAGE_SHIFT - 10);
+    else
+        reserve_dmapages = (unsigned int)(bytes >> PAGE_SHIFT);
+}

Shouldn't the default unit be consistent for all Xen memory parameters?

Quoted 6 lines
Quoted 2 lines

I am just following the dom0_mem conventions for which default unit is kB. Am I missing something?

If Kbytes is to be the default unit, then that default should probably be encoded in 'parse_size_and_unit', rather than having code like the above convert from bytes to Kbytes in many places.

For "mem=" option, default unit is bytes. I think we should go with the linux style and make the default unit as bytes. If no one has any objections, then I can send a patch for it.

thanks,
suresh

#5 lore raw
Quoted 7 lines · Suresh B
Quoted 3 lines

If Kbytes is to be the default unit, then that default should probably be encoded in 'parse_size_and_unit', rather than having code like the above convert from bytes to Kbytes in many places.

For "mem=" option, default unit is bytes. I think we should go with the linux style and make the default unit as bytes. If no one has any objections, then I can send a patch for it.

Changing it will annoy people who are used to 2.0-style dom0_mem= parameter. There is no good reason to change it: it's documented and, if you want to avoid confusion, just stick a unit symbol on the end.

-- Keir

#6 lore raw

Default memory unit

Quoted 9 lines · Keir Fraser
Quoted 5 lines · Suresh B
Quoted 2 lines

If Kbytes is to be the default unit, then that default should probably be encoded in 'parse_size_and_unit', rather than having code like the above convert from bytes to Kbytes in many places.

For "mem=" option, default unit is bytes. I think we should go with the
linux style and make the default unit as bytes. If no one has any objections, then I can send a patch for it.

Changing it will annoy people who are used to 2.0-style dom0_mem= parameter. There is no good reason to change it: it's documented and, if you want to avoid confusion, just stick a unit symbol on the end.

I disagree that there's no good reason to make the default unit consistent. Currently Xen has a relatively small user community, so the time to change it while annoying the fewest people is now.

Signature · 1 line
David Hopwood <[email protected]>
#7 lore raw
In reply to Keir Fraser
Quoted 9 lines · Keir Fraser
Quoted 6 lines · Suresh B
Quoted 5 lines

If Kbytes is to be the default unit, then that default should probably be
encoded in 'parse_size_and_unit', rather than having code like the above
convert from bytes to Kbytes in many places.

Quoted 8 lines
Quoted 4 lines

For "mem=" option, default unit is bytes. I think we should go with the linux style and make the default unit as bytes. If no one has any objections,
then I can send a patch for it.

Changing it will annoy people who are used to 2.0-style dom0_mem= parameter. There is no good reason to change it: it's documented and, if you want to avoid confusion, just stick a unit symbol on the end.

And with the overnight changeset #6256, you changed the default behavior of "mem=" to kilobytes.

We had to change one or the other to achieve commonality.

thanks,
suresh

#8 lore raw
In reply to Siddha, Suresh B
Quoted 4 lines · Suresh B

By default, xen needs to reserve some portion of memory to satisfy SWIOTLB and other contguous memory region requests. Following the current swiotlb enabling mechanism, Appended patch reserves 128MB of memory on systems with more than 2GB of RAM.

Hmmm... sounds reasonable. I'd rather have one dom0 memory parameter though --- keeping dom0_mem but have +ve value mean 'allocate this amount' and -ve mean 'allocate full memory - this amount'. Otherwise we have two competing parameters specifying basically the same thing...

I don't much like hacky 'policies' that hardcode default reservations in the hypervisor, but I think this one is pretty sensible.

Quoted 5 lines

Ideally shouldn't we enable SWIOTLB in dom0 and this DMA memory reservation in hypervisor by default? Otherwise we will have a problem(even on systems with less than 2GB of RAM) in servicing a driver DMA request to a kmalloc'd buffer which spans more than a page or the various xen_create_contiguous_region() requests.

You get a pretty clear BUG() message out if this happens. It actually tells you to enable 'swiotlb=force'! The number of drivers that actually use multi-page buffers is really small -- we only fixed that case in 2.0 a few weeks ago.

I'd rather not waste 64MB of pre-reserved bounce buffers on small-memory systems that almost certainly don't need bounce buffers.

-- Keir

#9 lore raw
Quoted 4 lines

You get a pretty clear BUG() message out if this happens. It actually tells you to enable 'swiotlb=force'! The number of drivers that actually use multi-page buffers is really small -- we only fixed that case in 2.0 a few weeks ago.

The USB drivers I've worked with tended to use multipage buffers, although only the mass storage driver seemed to use really large numbers of pages.

Cheers,
Mark

Quoted 10 lines

I'd rather not waste 64MB of pre-reserved bounce buffers on small-memory systems that almost certainly don't need bounce buffers.

-- Keir

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#10 lore raw
In reply to Keir Fraser
Quoted 8 lines · Keir Fraser
Quoted 4 lines · Suresh B

By default, xen needs to reserve some portion of memory to satisfy SWIOTLB and other contguous memory region requests. Following the current swiotlb enabling mechanism, Appended patch reserves 128MB of memory on systems with more than 2GB of RAM.

Quoted 7 lines

Hmmm... sounds reasonable. I'd rather have one dom0 memory parameter though --- keeping dom0_mem but have +ve value mean 'allocate this amount' and -ve mean 'allocate full memory - this amount'. Otherwise we have two competing parameters specifying basically the same thing...

I don't much like hacky 'policies' that hardcode default reservations in the hypervisor, but I think this one is pretty sensible.

I see this incorporated in changeset #6257. Thanks.

Quoted 11 lines
Quoted 7 lines

Ideally shouldn't we enable SWIOTLB in dom0 and this DMA memory reservation
in hypervisor by default? Otherwise we will have a problem(even on systems
with less than 2GB of RAM) in servicing a driver DMA request to a kmalloc'd buffer which spans more than a page or the various xen_create_contiguous_region() requests.

You get a pretty clear BUG() message out if this happens. It actually tells you to enable 'swiotlb=force'! The number of drivers that actually use multi-page buffers is really small -- we only fixed that

If we decide not to support(/fix) those drivers, then we should enable swiotlb only if the system has more than 4GB of RAM. Where is the current 2GB magic figure coming from?

Quoted 4 lines

case in 2.0 a few weeks ago.

I'd rather not waste 64MB of pre-reserved bounce buffers on small-memory systems that almost certainly don't need bounce buffers.

We can have a smaller swiotlb window (couple of MB?) on small-memory systems if we want to support the drivers doing dma_map_single to multipage buffers.

thanks,
suresh