Skip to contentSkip to conversation

libxc: checkpoint compression

PATCH Superseded [email protected] 3 participants 12 messages Nov 3, 2011 – Nov 8, 2011 Arm/actions semi architecture

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 libxc: checkpoint compression

This patch series adds checkpoint compression functionality, while running under Remus.

Tested under xen-4.2-unstable/pvops dom0 (x86_64) #ubuntu-10.04.

A simple benchmark: SpecJBB (Java Benchmark)
- 4 minute Remus run, with PV domU (2.6.32 xenolinux kernel), 1G memory and 2 VCPUs
- Data sent without compression: ~70GB.
- Data sent with compression: ~8GB.

Changes since last version:
1. use posix_memalign only on linux platforms and switch to normal malloc for the rest. stubdom compiles successfully.

Shriram

#1 lore raw

PATCH v5 1/1 tools/libxc: Remus Checkpoint Compression

# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1320348671 25200
# Node ID d27072263a483fbf66456722fbd84967fe606602 # Parent 4b0907c6a08c348962bd976c2976257b412408be tools/libxc: Remus Checkpoint Compression

Instead of sending dirty pages of guest memory as-is, use a simple compression algorithm that sends a RLE-encoded XOR of the page against its last sent copy. A small LRU cache is used to hold recently dirtied pages. Pagetable pages are sent as-is, as they are canonicalized at sender side and uncanonicalized at receiver.

tools/libxc/Makefile +1 -1
diff -r 4b0907c6a08c -r d27072263a48 tools/libxc/Makefile
@@ -42,7 +42,7 @@
 GUEST_SRCS-y :=
 GUEST_SRCS-y += xg_private.c xc_suspend.c
 GUEST_SRCS-$(CONFIG_MIGRATE) += xc_domain_restore.c xc_domain_save.c
-GUEST_SRCS-$(CONFIG_MIGRATE) += xc_offline_page.c
+GUEST_SRCS-$(CONFIG_MIGRATE) += xc_offline_page.c xc_compression.c
 GUEST_SRCS-$(CONFIG_HVM) += xc_hvm_build.c
 
 vpath %.c ../../xen/common/libelf
tools/libxc/xc_compression.c new file +567 -0

567 lines not on this page · raw message

tools/libxc/xc_domain_restore.c +72 -1

133 lines not on this page · raw message

tools/libxc/xc_domain_save.c +210 -8

302 lines not on this page · raw message

tools/libxc/xenctrl.h +60 -0

64 lines not on this page · raw message

tools/libxc/xenguest.h +1 -0
diff -r 4b0907c6a08c -r d27072263a48 tools/libxc/xenguest.h
@@ -27,6 +27,7 @@
 #define XCFLAGS_DEBUG     2
 #define XCFLAGS_HVM       4
 #define XCFLAGS_STDVGA    8
+#define XCFLAGS_CHECKPOINT_COMPRESS    16
 #define X86_64_B_SIZE   64 
 #define X86_32_B_SIZE   32
 
tools/libxc/xg_save_restore.h +119 -1

138 lines not on this page · raw message

#2 lore raw

PATCH v5 1/1 remus: command line switch to enable/disable checkpoint compression

In reply to [email protected]

# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1320348758 25200
# Node ID b6ed8e28ae3fb14aeb978fdf626b682ed24957ba
# Parent d27072263a483fbf66456722fbd84967fe606602
remus: command line switch to enable/disable checkpoint compression

Add a command line switch to remus script that allows the user to enable or disable checkpoint compression in the libxc code.

tools/python/xen/lowlevel/checkpoint/checkpoint.c +4 -3
diff -r d27072263a48 -r b6ed8e28ae3f tools/python/xen/lowlevel/checkpoint/checkpoint.c
@@ -104,13 +104,14 @@
   PyObject* postcopy_cb = NULL;
   PyObject* checkpoint_cb = NULL;
   unsigned int interval = 0;
+  unsigned int flags = 0;
 
   int fd;
   struct save_callbacks callbacks;
   int rc;
 
-  if (!PyArg_ParseTuple(args, "O|OOOI", &iofile, &suspend_cb, &postcopy_cb,
-                       &checkpoint_cb, &interval))
+  if (!PyArg_ParseTuple(args, "O|OOOII", &iofile, &suspend_cb, &postcopy_cb,
+			&checkpoint_cb, &interval, &flags))
     return NULL;
 
   self->interval = interval;
@@ -160,7 +161,7 @@
   callbacks.data = self;
 
   self->threadstate = PyEval_SaveThread();
-  rc = checkpoint_start(&self->cps, fd, &callbacks);
+  rc = checkpoint_start(&self->cps, fd, &callbacks, flags);
   PyEval_RestoreThread(self->threadstate);
 
   if (rc < 0) {
tools/python/xen/lowlevel/checkpoint/checkpoint.h +3 -1
diff -r d27072263a48 -r b6ed8e28ae3f tools/python/xen/lowlevel/checkpoint/checkpoint.h
@@ -40,13 +40,15 @@
     timer_t timer;
 } checkpoint_state;
 
+#define CHECKPOINT_FLAGS_COMPRESSION 1
 char* checkpoint_error(checkpoint_state* s);
 
 void checkpoint_init(checkpoint_state* s);
 int checkpoint_open(checkpoint_state* s, unsigned int domid);
 void checkpoint_close(checkpoint_state* s);
 int checkpoint_start(checkpoint_state* s, int fd,
-                    struct save_callbacks* callbacks);
+		     struct save_callbacks* callbacks,
+		     unsigned int remus_flags);
 int checkpoint_suspend(checkpoint_state* s);
 int checkpoint_resume(checkpoint_state* s);
 int checkpoint_postflush(checkpoint_state* s);
tools/python/xen/lowlevel/checkpoint/libcheckpoint.c +4 -1
diff -r d27072263a48 -r b6ed8e28ae3f tools/python/xen/lowlevel/checkpoint/libcheckpoint.c
@@ -170,7 +170,8 @@
 }
 
 int checkpoint_start(checkpoint_state* s, int fd,
-                    struct save_callbacks* callbacks)
+		     struct save_callbacks* callbacks,
+		     unsigned int remus_flags)
 {
     int hvm, rc;
     int flags = XCFLAGS_LIVE;
@@ -188,6 +189,8 @@
        if (switch_qemu_logdirty(s, 1))
            return -1;
     }
+    if (remus_flags & CHECKPOINT_FLAGS_COMPRESSION)
+      flags |= XCFLAGS_CHECKPOINT_COMPRESS;
 
     callbacks->switch_qemu_logdirty = noop_switch_logdirty;
 
tools/python/xen/remus/save.py +5 -2
diff -r d27072263a48 -r b6ed8e28ae3f tools/python/xen/remus/save.py
@@ -133,7 +133,7 @@
 
 class Saver(object):
     def __init__(self, domid, fd, suspendcb=None, resumecb=None,
-                 checkpointcb=None, interval=0):
+                 checkpointcb=None, interval=0, flags=0):
         """Create a Saver object for taking guest checkpoints.
         domid:        name, number or UUID of a running domain
         fd:           a stream to which checkpoint data will be written.
@@ -141,12 +141,14 @@
         resumecb:     callback invoked before guest resumes
         checkpointcb: callback invoked when a checkpoint is complete. Return
                       True to take another checkpoint, or False to stop.
+        flags:        Remus flags to be passed to xc_domain_save
         """
         self.fd = fd
         self.suspendcb = suspendcb
         self.resumecb = resumecb
         self.checkpointcb = checkpointcb
         self.interval = interval
+        self.flags = flags
 
         self.vm = vm.VM(domid)
 
@@ -164,7 +166,8 @@
             try:
                 self.checkpointer.open(self.vm.domid)
                 self.checkpointer.start(self.fd, self.suspendcb, self.resumecb,
-                                        self.checkpointcb, self.interval)
+                                        self.checkpointcb, self.interval,
+                                        self.flags)
             except xen.lowlevel.checkpoint.error, e:
                 raise CheckpointError(e)
         finally:
tools/remus/remus +9 -1
diff -r d27072263a48 -r b6ed8e28ae3f tools/remus/remus
@@ -16,6 +16,9 @@
 class CfgException(Exception): pass
 
 class Cfg(object):
+
+    REMUS_FLAGS_COMPRESSION = 1
+
     def __init__(self):
         # must be set
         self.domid = 0
@@ -25,6 +28,7 @@
         self.port = XendOptions.instance().get_xend_relocation_port()
         self.interval = 200
         self.netbuffer = True
+        self.flags = self.REMUS_FLAGS_COMPRESSION
         self.timer = False
 
         parser = optparse.OptionParser()
@@ -38,6 +42,8 @@
                           help='replicate to /dev/null (no disk checkpoints, only memory & net buffering)')
         parser.add_option('', '--no-net', dest='nonet', action='store_true',
                           help='run without net buffering (benchmark option)')
+        parser.add_option('', '--no-compression', dest='nocompress', action='store_true',
+                          help='run without checkpoint compression')
         parser.add_option('', '--timer', dest='timer', action='store_true',
                           help='force pause at checkpoint interval (experimental)')
         self.parser = parser
@@ -56,6 +62,8 @@
             self.nullremus = True
         if opts.nonet:
             self.netbuffer = False
+        if opts.nocompress:
+            self.flags &= ~self.REMUS_FLAGS_COMPRESSION
         if opts.timer:
             self.timer = True
 
@@ -190,7 +198,7 @@
     rc = 0
 
     checkpointer = save.Saver(cfg.domid, fd, postsuspend, preresume, commit,
-                              interval)
+                              interval, cfg.flags)
 
     try:
         checkpointer.start()
#3 lore raw
In reply to [email protected]

[email protected] writes ("[PATCH 0 of 2 V5] libxc: checkpoint compression"):

Quoted 2 lines

This patch series adds checkpoint compression functionality, while running under Remus.

...

Quoted 3 lines

Changes since last version:
1. use posix_memalign only on linux platforms and switch to normal malloc for the rest. stubdom compiles successfully.

Looking at this in more detail, I don't understand why you're using posix_memalign rather than just malloc, anyway. If it's necessary to use posix_memalign on Linux, why is it OK to use malloc on other platforms ?

Also this #ifdef is quite ugly.

Ian.

#4 lore raw

Why posix_memalign?

The compression code involves a lot of memcpys at 4K granularity (dirty pages
copied from domU's memory to internal cache/page buffers etc). I would like to
keep these memcpys page aligned for purposes of speed. The source pages (from domU) are already aligned. The destination pages allocated by the compression code need to be page aligned.

correct me if I am wrong:
mallocing a huge buffer for this purpose is not optimal. malloc aligns
allocations
on 16byte (or 8byte) granularity but if a 4K region straddles across two
physical
memory frames, then the memcpy is going to be suboptimal. OTOH, memalign ensures that we are dealing with just 2 memory frames as opposed to 3 (possible) frames in malloc.

A simple 8Mb memcpy test shows an average of 500us overhead for malloc based allocation compared to posix_memalign based allocation. While this might seem low, the checkpoints are being taken at high frequency (every 20ms for instance).

It is not okay to use malloc on other platforms. I simply dont have access to other
platforms to test their equivalent versions. Short of using something like qemu_memalign function.

I am open to suggestions :)

shriram

Quoted 10 lines · Ian Jackson

[email protected] writes ("[PATCH 0 of 2 V5] libxc: checkpoint compression"):

Quoted 2 lines

This patch series adds checkpoint compression functionality, while running under Remus.

...

Quoted 2 lines

Changes since last version:
1. use posix_memalign only on linux platforms and switch to normal

malloc for

Quoted 1 line

the rest. stubdom compiles successfully.

Quoted 10 lines

Looking at this in more detail, I don't understand why you're using posix_memalign rather than just malloc, anyway. If it's necessary to use posix_memalign on Linux, why is it OK to use malloc on other platforms ?

Also this #ifdef is quite ugly.

Ian.

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

#5 lore raw
Quoted 24 lines · Shriram Rajagopalan

Why posix_memalign?

The compression code involves a lot of memcpys at 4K granularity (dirty pages
copied from domU's memory to internal cache/page buffers etc). I would like to
keep these memcpys page aligned for purposes of speed. The source pages (from domU) are already aligned. The destination pages allocated by the compression code need to be page aligned.

correct me if I am wrong:
mallocing a huge buffer for this purpose is not optimal. malloc aligns
allocations
on 16byte (or 8byte) granularity but if a 4K region straddles across two
physical
memory frames, then the memcpy is going to be suboptimal. OTOH, memalign ensures that we are dealing with just 2 memory frames as opposed to 3 (possible) frames in malloc.

A simple 8Mb memcpy test shows an average of 500us overhead for malloc based allocation compared to posix_memalign based allocation. While this might seem low, the checkpoints are being taken at high frequency (every 20ms for instance).

Quoted 10 lines

It is not okay to use malloc on other platforms. I simply dont have access to other
platforms to test their equivalent versions. Short of using something like qemu_memalign function.

I am open to suggestions :)

shriram

Ping.

Quoted 17 lines · Ian Jackson
Quoted 16 lines

[email protected] writes ("[PATCH 0 of 2 V5] libxc: checkpoint compression"):

Quoted 2 lines

This patch series adds checkpoint compression functionality, while running under Remus.

...

Quoted 2 lines

Changes since last version:
1. use posix_memalign only on linux platforms and switch to normal

malloc for

Quoted 1 line

the rest. stubdom compiles successfully.

Looking at this in more detail, I don't understand why you're using posix_memalign rather than just malloc, anyway. If it's necessary to use posix_memalign on Linux, why is it OK to use malloc on other platforms ?

Quoted 6 lines
Quoted 5 lines

Also this #ifdef is quite ugly.

Ian.

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

#6 lore raw
Quoted 33 lines · Shriram Rajagopalan

On Fri, Nov 4, 2011 at 12:21 PM, Shriram Rajagopalan <[email protected]> wrote:
Why posix_memalign?

The compression code involves a lot of memcpys at 4K granularity (dirty pages
copied from domU's memory to internal cache/page buffers etc). I would like to
keep these memcpys page aligned for purposes of speed. The source pages
(from domU) are already aligned. The destination pages allocated by the
compression code need to be page aligned.

correct me if I am wrong:
mallocing a huge buffer for this purpose is not optimal.
malloc aligns allocations
on 16byte (or 8byte) granularity but if a 4K region straddles
across two physical
memory frames, then the memcpy is going to be suboptimal. OTOH, memalign
ensures that we are dealing with just 2 memory frames as opposed
to 3 (possible) frames in malloc.

A simple 8Mb memcpy test shows an average of 500us overhead for malloc
based allocation compared to posix_memalign based allocation. While this
might seem low, the checkpoints are being taken at high frequency
(every 20ms for instance).

Quoted 7 lines

It is not okay to use malloc on other platforms. I simply dont have access to other
platforms to test their equivalent versions. Short of using something
like qemu_memalign function.

I am open to suggestions :)

This is due to minios (aka stubdoms) not having posix_memalign, right?

minios (or rather newlib) does appear to have memalign though, which if true would also work, right? You could potentially also implement posix_memalign in terms of memalign on minios and avoid the ifdef.

Ian.

Quoted 38 lines

shriram

Ping.

On Fri, Nov 4, 2011 at 5:14 AM, Ian Jackson <[email protected]> wrote:
[email protected] writes ("[PATCH 0 of 2 V5] libxc:
checkpoint compression"):
> This patch series adds checkpoint compression functionality, while
> running under Remus.

...
> Changes since last version:
> 1. use posix_memalign only on linux platforms and switch to normal malloc for
> the rest. stubdom compiles successfully.

Looking at this in more detail, I don't understand why you're using
posix_memalign rather than just malloc, anyway. If it's necessary to
use posix_memalign on Linux, why is it OK to use malloc on other
platforms ?

Also this #ifdef is quite ugly.

Ian.

#7 lore raw
Quoted 40 lines · Ian Campbell
Quoted 39 lines · Shriram Rajagopalan

On Fri, Nov 4, 2011 at 12:21 PM, Shriram Rajagopalan <[email protected]> wrote:
Why posix_memalign?

The compression code involves a lot of memcpys at 4K granularity (dirty pages
copied from domU's memory to internal cache/page buffers etc). I would like to
keep these memcpys page aligned for purposes of speed. The source pages
(from domU) are already aligned. The destination pages allocated by the
compression code need to be page aligned.

correct me if I am wrong:
mallocing a huge buffer for this purpose is not optimal.
malloc aligns allocations
on 16byte (or 8byte) granularity but if a 4K region straddles
across two physical
memory frames, then the memcpy is going to be suboptimal. OTOH, memalign
ensures that we are dealing with just 2 memory frames as opposed
to 3 (possible) frames in malloc.

A simple 8Mb memcpy test shows an average of 500us overhead for malloc
based allocation compared to posix_memalign based allocation. While this
might seem low, the checkpoints are being taken at high frequency
(every 20ms for instance).

It is not okay to use malloc on other platforms. I simply dont have access to other
platforms to test their equivalent versions. Short of using something
like qemu_memalign function.

Quoted 9 lines
Quoted 1 line

I am open to suggestions :)

This is due to minios (aka stubdoms) not having posix_memalign, right?

minios (or rather newlib) does appear to have memalign though, which if true would also work, right? You could potentially also implement posix_memalign in terms of memalign on minios and avoid the ifdef.

Sounds good. In that case, can I just post a patch to minios, implementing posix_memalign and will you then directly take the previous version V4 of this
patch series (the one without #ifdefs) ?

thanks
shriram

Ian.

Quoted 32 lines
Quoted 32 lines

shriram

Ping.

On Fri, Nov 4, 2011 at 5:14 AM, Ian Jackson <[email protected]> wrote:
[email protected] writes ("[PATCH 0 of 2 V5] libxc:
checkpoint compression"):
> This patch series adds checkpoint compression functionality, while
> running under Remus.

...
> Changes since last version:
> 1. use posix_memalign only on linux platforms and switch to normal malloc for
> the rest. stubdom compiles successfully.

Looking at this in more detail, I don't understand why you're using
posix_memalign rather than just malloc, anyway. If it's necessary to
use posix_memalign on Linux, why is it OK to use malloc on other
platforms ?

Quoted 10 lines
Quoted 7 lines

Also this #ifdef is quite ugly.

Ian.

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

#8 lore raw
Quoted 68 lines · Shriram Rajagopalan

On Tue, Nov 8, 2011 at 9:02 AM, Ian Campbell <[email protected]> wrote:
On Tue, 2011-11-08 at 16:51 +0000, Shriram Rajagopalan wrote:
> On Fri, Nov 4, 2011 at 12:21 PM, Shriram Rajagopalan > <[email protected]> wrote:
> Why posix_memalign?
>
> The compression code involves a lot of memcpys at 4K
> granularity (dirty pages
> copied from domU's memory to internal cache/page
buffers etc).
> I would like to
> keep these memcpys page aligned for purposes of
speed. The
> source pages
> (from domU) are already aligned. The destination
pages
> allocated by the
> compression code need to be page aligned.
>
> correct me if I am wrong:
> mallocing a huge buffer for this purpose is not
optimal.
> malloc aligns allocations
> on 16byte (or 8byte) granularity but if a 4K region
straddles
> across two physical
> memory frames, then the memcpy is going to be
suboptimal.
> OTOH, memalign
> ensures that we are dealing with just 2 memory
frames as
> opposed
> to 3 (possible) frames in malloc.
>
> A simple 8Mb memcpy test shows an average of 500us
overhead
> for malloc
> based allocation compared to posix_memalign based
allocation.
> While this
> might seem low, the checkpoints are being taken at
high
> frequency
> (every 20ms for instance).
>
> It is not okay to use malloc on other platforms. I
simply dont
> have access to other
> platforms to test their equivalent versions. Short
of using
> something
> like qemu_memalign function.
>
> I am open to suggestions :)

This is due to minios (aka stubdoms) not having posix_memalign, right?

minios (or rather newlib) does appear to have memalign though, which if
true would also work, right? You could potentially also implement
posix_memalign in terms of memalign on minios and avoid the ifdef.

Quoted 3 lines

Sounds good. In that case, can I just post a patch to minios, implementing posix_memalign and will you then directly take the previous version V4 of this patch series (the one without #ifdefs) ?

Well, *I* won't be taking any version of the patch but that sounds like a sane plan to me, assuming V4 builds after your minios patch.

Quoted 56 lines

thanks
shriram

Ian.

>
> shriram
>
>
>
> Ping.
>
>
> On Fri, Nov 4, 2011 at 5:14 AM, Ian Jackson
> <[email protected]> wrote:
> [email protected] writes ("[PATCH 0 of 2
V5] libxc:
> checkpoint compression"):
> > This patch series adds checkpoint
compression
> functionality, while
> > running under Remus.
>
> ...
> > Changes since last version:
> > 1. use posix_memalign only on linux
platforms and
> switch to normal malloc for
> > the rest. stubdom compiles
successfully.
>
>
> Looking at this in more detail, I don't
understand why
> you're using
> posix_memalign rather than just malloc,
anyway. If
> it's necessary to
> use posix_memalign on Linux, why is it OK to
use
> malloc on other
> platforms ?
>
> Also this #ifdef is quite ugly.
>
> Ian.
>
>
>
>

#9 lore raw
Quoted 69 lines · Ian Campbell
Quoted 68 lines · Shriram Rajagopalan

On Tue, Nov 8, 2011 at 9:02 AM, Ian Campbell <[email protected]> wrote:
On Tue, 2011-11-08 at 16:51 +0000, Shriram Rajagopalan wrote:
> On Fri, Nov 4, 2011 at 12:21 PM, Shriram Rajagopalan > <[email protected]> wrote:
> Why posix_memalign?
>
> The compression code involves a lot of memcpys at 4K
> granularity (dirty pages
> copied from domU's memory to internal cache/page
buffers etc).
> I would like to
> keep these memcpys page aligned for purposes of
speed. The
> source pages
> (from domU) are already aligned. The destination
pages
> allocated by the
> compression code need to be page aligned.
>
> correct me if I am wrong:
> mallocing a huge buffer for this purpose is not
optimal.
> malloc aligns allocations
> on 16byte (or 8byte) granularity but if a 4K region
straddles
> across two physical
> memory frames, then the memcpy is going to be
suboptimal.
> OTOH, memalign
> ensures that we are dealing with just 2 memory
frames as
> opposed
> to 3 (possible) frames in malloc.
>
> A simple 8Mb memcpy test shows an average of 500us
overhead
> for malloc
> based allocation compared to posix_memalign based
allocation.
> While this
> might seem low, the checkpoints are being taken at
high
> frequency
> (every 20ms for instance).
>
> It is not okay to use malloc on other platforms. I
simply dont
> have access to other
> platforms to test their equivalent versions. Short
of using
> something
> like qemu_memalign function.
>
> I am open to suggestions :)

This is due to minios (aka stubdoms) not having posix_memalign, right?

minios (or rather newlib) does appear to have memalign though, which if
true would also work, right? You could potentially also implement
posix_memalign in terms of memalign on minios and avoid the ifdef.

Quoted 8 lines
Quoted 3 lines

Sounds good. In that case, can I just post a patch to minios, implementing posix_memalign and will you then directly take the previous version V4 of this patch series (the one without #ifdefs) ?

Well, *I* won't be taking any version of the patch but that sounds like a sane plan to me, assuming V4 builds after your minios patch.

oops. sorry.. I was referring to IanJ.

Quoted 48 lines
Quoted 48 lines

thanks
shriram

Ian.

>
> shriram
>
>
>
> Ping.
>
>
> On Fri, Nov 4, 2011 at 5:14 AM, Ian Jackson
> <[email protected]> wrote:
> [email protected] writes ("[PATCH 0 of 2
V5] libxc:
> checkpoint compression"):
> > This patch series adds checkpoint
compression
> functionality, while
> > running under Remus.
>
> ...
> > Changes since last version:
> > 1. use posix_memalign only on linux
platforms and
> switch to normal malloc for
> > the rest. stubdom compiles
successfully.
>
>
> Looking at this in more detail, I don't
understand why
> you're using
> posix_memalign rather than just malloc,
anyway. If
> it's necessary to
> use posix_memalign on Linux, why is it OK to
use
> malloc on other
> platforms ?
>
> Also this #ifdef is quite ugly.
>
> Ian.

Quoted 11 lines
Quoted 8 lines
        >
        >
        >
        >

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

#10 lore raw
Quoted 75 lines · Shriram Rajagopalan
Quoted 73 lines · Ian Campbell
Quoted 71 lines · Shriram Rajagopalan

On Tue, Nov 8, 2011 at 9:02 AM, Ian Campbell <[email protected]> wrote:
On Tue, 2011-11-08 at 16:51 +0000, Shriram Rajagopalan wrote:
> On Fri, Nov 4, 2011 at 12:21 PM, Shriram Rajagopalan > <[email protected]> wrote:
> Why posix_memalign?
>
> The compression code involves a lot of memcpys at 4K
> granularity (dirty pages
> copied from domU's memory to internal cache/page
buffers etc).
> I would like to
> keep these memcpys page aligned for purposes of
speed. The
> source pages
> (from domU) are already aligned. The destination
pages
> allocated by the
> compression code need to be page aligned.
>
> correct me if I am wrong:
> mallocing a huge buffer for this purpose is not
optimal.
> malloc aligns allocations
> on 16byte (or 8byte) granularity but if a 4K region
straddles
> across two physical
> memory frames, then the memcpy is going to be
suboptimal.
> OTOH, memalign
> ensures that we are dealing with just 2 memory
frames as
> opposed
> to 3 (possible) frames in malloc.
>
> A simple 8Mb memcpy test shows an average of 500us
overhead
> for malloc
> based allocation compared to posix_memalign based
allocation.
> While this
> might seem low, the checkpoints are being taken at
high
> frequency
> (every 20ms for instance).
>
> It is not okay to use malloc on other platforms. I
simply dont
> have access to other
> platforms to test their equivalent versions. Short
of using
> something
> like qemu_memalign function.
>
> I am open to suggestions :)

This is due to minios (aka stubdoms) not having posix_memalign, right?

minios (or rather newlib) does appear to have memalign though, which if
true would also work, right? You could potentially also implement
posix_memalign in terms of memalign on minios and avoid the ifdef.

Sounds good. In that case, can I just post a patch to minios, implementing posix_memalign and will you then directly take the previous version V4 of this patch series (the one without #ifdefs) ?

Quoted 7 lines
Quoted 4 lines

Well, *I* won't be taking any version of the patch but that sounds like a sane plan to me, assuming V4 builds after your minios patch.

oops. sorry.. I was referring to IanJ.

Just realized i forgot to state why I had to the __linux__.

a. minios lacks posix_memalign
b. I looked up online. solaris has no posix_memalign. I am not sure about netbsd.
c. in tools/libxc/
xc_solaris.c uses memalign
xc_netbsd.c uses valloc
xc_minios.c uses memalign
xc_linux_osdep.c uses posix_memalign!

further posix_memalign manpage states that *"*posix_memalign() verifies that *alignment* matches the requirements detailed above.
memalign**() may not check that the *boundary* argument is correct."

fortified by newlib-1.16.0's comments in mallocr.c (newlib-1.16.0/newlib/libc/stdlib/)
"The alignment argument must be a power of two. This property is not checked by memalign, so misuse may result in random runtime errors."

Judging by all this mess, I thought i was better off doing a #ifdef __linux__ and
resorting to simple malloc for the other platforms.

One alternative would be to add the xc_memalign function alone, that was removed
by c/s 22520.

-void *xc_memalign(size_t alignment, size_t size) -{
-#if defined(_POSIX_C_SOURCE) && !defined(__sun__)

-    int ret;
-    void *ptr;
-    ret = posix_memalign(&ptr, alignment, size);
-    if (ret != 0)

- return NULL;
- return ptr;
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
- return valloc(size);
-#else
- return memalign(alignment, size);
-#endif
-}
-

shriram

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines

thanks
shriram

Ian.

>
> shriram
>
>
>
> Ping.
>
>
> On Fri, Nov 4, 2011 at 5:14 AM, Ian Jackson
> <[email protected]> wrote:
> [email protected] writes ("[PATCH 0 of 2
V5] libxc:
> checkpoint compression"):
> > This patch series adds checkpoint
compression
> functionality, while
> > running under Remus.
>
> ...
> > Changes since last version:
> > 1. use posix_memalign only on linux
platforms and
> switch to normal malloc for
> > the rest. stubdom compiles
successfully.
>
>
> Looking at this in more detail, I don't
understand why
> you're using
> posix_memalign rather than just malloc,
anyway. If
> it's necessary to
> use posix_memalign on Linux, why is it OK to
use
> malloc on other
> platforms ?
>
> Also this #ifdef is quite ugly.
>
> Ian.
>
>
>

Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
        >

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

#11 lore raw
Quoted 2 lines · Shriram Rajagopalan

One alternative would be to add the xc_memalign function alone, that was removed by c/s 22520.

22520 is 22520:6df91a11dcb0 "libxc: remove comment obsoleted by addition of hypercall bounce buffer." here. Did you mean 22312:9fad5e5e2fc1 (remember the cset number is not globally unique/stable, only the longer node hash is)

I think putting xc_memalign back would be fine, better than the other options we've discussed even.

I'd be tempted to do it as separate functions tools/libxc/xc_{minios,netbsd,linux}.c rather than using #ifdef though.

(For my money you can ignore Solaris, it's been unmaintained for long enough that I bet it doesn't even build now and there's no one we can ask to even build test it).

Quoted 93 lines
(quoted diff) +0 -16
-void *xc_memalign(size_t alignment, size_t size)
-{
-#if defined(_POSIX_C_SOURCE) && !defined(__sun__)
-    int ret;
-    void *ptr;
-    ret = posix_memalign(&ptr, alignment, size);
-    if (ret != 0)
-        return NULL;
-    return ptr;
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-    return valloc(size);
-#else
-    return memalign(alignment, size);
-#endif
-}
-

shriram

>
> thanks
> shriram
>
>
> Ian.
>
> >
> > shriram
> >
> >
> >
> > Ping.
> >
> >
> > On Fri, Nov 4, 2011 at 5:14 AM,
Ian Jackson
> > <[email protected]> wrote:
> > [email protected] writes
("[PATCH 0 of 2
> V5] libxc:
> > checkpoint compression"):
> > > This patch series adds
checkpoint
> compression
> > functionality, while
> > > running under Remus.
> >
> > ...
> > > Changes since last
version:
> > > 1. use posix_memalign
only on linux
> platforms and
> > switch to normal malloc
for
> > > the rest. stubdom
compiles
> successfully.
> >
> >
> > Looking at this in more
detail, I don't
> understand why
> > you're using
> > posix_memalign rather than
just malloc,
> anyway. If
> > it's necessary to
> > use posix_memalign on
Linux, why is it OK to
> use
> > malloc on other
> > platforms ?
> >
> > Also this #ifdef is quite
ugly.
> >
> > Ian.
> >
> >
> >
> >
>
>
>
>