Fork, Memory, Copy-on-Write -- Horribly Slow?
Subject : Fork, Memory, Copy-on-Write -- Horribly Slow?
From: Seth Willits <email@hidden >
Date: Tue, 23 Sep 2008 14:50:19 -0700
Delivered-to: email@hidden
Delivered-to: email@hidden
For some reason, it seems that copy-on-write is atrociously slow after
a fork, and I'm curious as to why this is.
Here's a pretty simple test. The last bit will take more than 10
minutes on my Mac Pro. Insane!
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
uint32_t size = 1024 * 1024 * 512;
uint8_t * buffer1 = malloc(size);
uint32_t i;
for (i = 0; i < size; i++) { buffer1[i] = 3; }
pid_t pid = fork();
if (pid != 0) {
waitpid(pid, NULL, 0);
} else {
// Very very fast
uint8_t * buffer2 = malloc(size);
memcpy(buffer2, buffer1, size);
NSLog(@"Child memcpy done");
sleep(3);
// Very VERY ***VERY*** sloth-on-a-snail's-back-in-molasses-
at-0.00001-degrees-Kelvin slow
NSLog(@"Child starting reassignments to b1");
for (i = 0; i < size; i += 1024 * 4) {
buffer1[i] = i;
}
NSLog(@"Child done reassignments to b1");
sleep(3);
}
[pool drain];
return 0;
}
Any ideas?
--
Seth Willits
_______________________________________________
Do not post admin requests to the list. They will be ignored.
PerfOptimization-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/perfoptimization-dev/email@hidden
This email sent to email@hidden
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.