3 ms·
> Do you actually touch it and write to it? calloc itself calls memset in user space. That's what separates it from malloc. Is it so hard to believe a modern
by mortehu 11y ago
> Do you actually touch it and write to it?
calloc itself calls memset in user space. That's what separates it from malloc. Is it so hard to believe a modern computer can memset 20 GB/s?
If I run "dd if=/dev/zero of=/dev/null bs=1M count=10000", I get 21.0 GB/s. Reading from /dev/zero is basically performing a memset to dd's buffer in kernel space. Writing to /dev/null is a no-op, so it's a very similar test.
- masklinn 11y ago> calloc itself calls memset in user space. Have you considered reading my comment past the first phrase? If you don't actually touch the page, the system doesn't need to allocate it, let alone zero it. If you don't touch the page, assuming you're benching on linux you're measuring the cost of mapping a preexisting zeroed COW page, not the cost of actually allocating that memory.
- heinrich5991 11y agoCalling memset in userspace qualifies as touching the page, no?
- mortehu 11y agocalloc is a library function, as opposed to a system call, so it calling memset is no different from the caller doing so. calloc will do the write in "copy on write". Calling memset on every byte in a buffer should qualify as "touching it". This is why I said "in user space".