-4

I'm developping a C++ based System under Windows 7. I deal with a bunch of processes that are deployed on separate CPU's and that communicate with each other. As communication is time critical (actually I deal with a real time system, i understand that Win7 is not the most suitable OS for my purpose..) I need it to be as fast as possible. I read up about IPC under Win7 (Pipes, MemMappedFiles, Sockets). The fastest method seems to be Memory mapped Files (Fastest IPC method on Windows 7). However, I disslike the idea that the Win7 swapper runs im background copying data back and forth from RAM to HD. In addition virtual memory manager needs to calculate physical memory addresses whenever I access a virtual memory address.

My approach: I would like to allocate a couple of MB's in RAM and write to/read from them directly by using their physical address. In addition I would like to remove that chuck of RAM memory from Win7 memory management. Is this possible? This should be the fastest way of sharing data between processes on separate CPU's, right? I understand that that way I don't allow Win7 to use any caching algorithms but as all my processes are deployed on separate CPU's and thus can't access the cache memory of one another this doesn't bother me, right?

Any comments (also very general ones) are greatly appreciated as I'm still in the phase of designing my system and looking for input!

Community
  • 1
  • 1
Johannes
  • 9
  • 2
  • 1
    Some questions out of curiosity: Did you consider the Linux kernel? It can (and has been) configured for use in real-time environments, so it's proven. Also, why try to bypass the OS's mechanisms? You're asking for more trouble than it's worth. If your'e in an RTOS environment, let the OS itself take care of keeping up with the constraints. Get it to work *first*, and *then* worry about performance. It seems you don't have anything yet, so it's too early for you to think about how to make you don't yet have "faster". – code_dredd Dec 28 '15 at 18:41
  • I'd happily use Linux, but I'm tied to Win7 unfortunately. As explained above: I m thinking about bypassing Win7 features in order to gain performance. I have never done this, that's why I'm leaving it to discussion. – Johannes Dec 28 '15 at 18:48
  • Start out simple with plain shared memory. Then profile. If you notice poor performance *coming from page faults*, investigate in techniques to keep your pages in physical memory (the simplest being just disabling the swap file). If you notice poor performance *coming from thrashed TLB* investigate in techniques to access physical memory without the MMU overhead (which I'm not even sure it's possible on x86 in protected mode). All this of course after you already tried to keep the working set at minimum. – Matteo Italia Dec 28 '15 at 18:52
  • 1
    Unwarranted assumptions aren't a good basis for a question. The Windows 7 "swapper" does _not_ copy data back and forth to HDD just willy-nilly. Nor does the virtual memory manager calculate physical addresses. – MSalters Dec 28 '15 at 18:53
  • Sure it's possible, you'd just have to write a kernel mode component for your application. Strikes me as the wrong solution to the wrong problem though. – Flexo Dec 28 '15 at 18:54

2 Answers2

4

In my opinion you're starting off on the wrong foot. Real time does not mean as fast as possible. It means you need to meet specific performance criteria.

To choose meaningfully you need to know what speed you really need.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
1

What you are trying to do is not possible at all. First, it is not possible for protected-mode applications to access physical RAM - any memory access is replaced by virtual memory access by the CPU, unless it is running in non-protected mode. And the only way to run your code in non-protected (real) mode is to run it as kernel of operating system, because the rest is put into protected mode.

Now, considering you succeed in creating a real-mode application (daunting task, btw!) At this point, you do not have memory mapped file any more - as this mapping is performed by OS exactly using virtual memory.

I also believe your worries are misconstrued. OS is actually good at determining what goes to swap and what not, and the chances of your actively used memory mapped region going to swap are slim to none under any normal circumstances.

Last but not the least, I am not sure you really understand what you are doing here.

SergeyA
  • 61,605
  • 5
  • 78
  • 137