1

Is it possible to mmap large amount of address space to /dev/null so all data written to it simply would be discarded?

I need to perform disk/network reads but I don't need readed data (I know, it sounds a little weird) and there is a lot of simultaneous read requests, so I don't want to waste "real" memory for this.

user3489275
  • 401
  • 4
  • 8
  • 1
    Possible duplicate of [mmap with /dev/zero](http://stackoverflow.com/questions/8507945/mmap-with-dev-zero) – DoxyLover Jun 15 '14 at 04:59
  • @DoxyLover no, linked question asks about reading /dev/zero, while this question about writing to it without using HW memory. – user3489275 Jun 15 '14 at 05:19
  • Data written to /dev/null is generally intended for storage in a Signetics 25000 series 9C46XN WOM (See http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0CCsQFjAB&url=http%3A%2F%2Fwww.repeater-builder.com%2Fmolotora%2Fgontor%2F25120-bw.pdf&ei=fTOdU8uvJo_doAT0iYDACg&usg=AFQjCNFPKb6o8A2TZjYaLfpuYyjIWdCx4g&sig2=RBA3f8VPdo2E45GcJfckFw" for details). – Mahonri Moriancumer Jun 15 '14 at 05:58
  • 1
    I don't understand the question. If you don't need the data then why write it anywhere? If you are worried about the memory used by multiple read buffers then just use one buffer. If you don't care about the data what do you care if multiple read sources are continually writing over the buffer area since you aren't going to use it anyway? – Duck Jun 15 '14 at 14:28
  • @Duck using one buffer across all CPU cores doesn't scale as it cause multiple writes from different cores. – user3489275 Jun 16 '14 at 03:35
  • I don't understand why that is a problem. Can you explain? – Duck Jun 16 '14 at 03:57
  • @Duck it causes a lot of cache coherence traffic – user3489275 Jun 16 '14 at 06:23

1 Answers1

1

In case it can help anyone trying to mmap /dev/null: this is actually impossible, and will return error ENODEV (no such device) which means (in this context) that this file cannot be mmaped.

This is because this is a special file for which no mmap operation is available. See http://lxr.free-electrons.com/source/drivers/char/mem.c#L768 for details.

lgeorget
  • 400
  • 4
  • 13