2

When a process is terminated abruptly by the OS (let's assume Linux) through a GPF or SIGKILL or similar, does the OS flush the modified CPU cache lines of the process to main memory? Is there different behavior depending on CPU or OS?

I am evaluating non-volatile memory capabilities and am wondering what state an application has written to memory in case of a crash. In specific whether it is missing the currently modified CPU cache lines or not. I have yet to find an official statement regarding this.

Thanks for any help!

torpedro
  • 494
  • 5
  • 13
  • I'm voting to close this question as off-topic because it belongs on Unix&Linux – guido Mar 22 '16 at 23:20
  • Knowing the intimate details of the more hardware-related aspects can be of vital importance to the *programmer*, so this, I think, is not off-topic here. True, it might be topic in other forums as well. – Alfe Mar 22 '16 at 23:56

1 Answers1

3

Generally speaking, yes. "Crashing" a process will not cause recent memory writes to be lost.

From the point of view of the CPU, raising an exception is used just as often for "normal" events as it is for fatal ones. For instance, accessing an unmapped page of memory does not always cause a crash by way of GPF/SEGV; many operating systems will use this event to implement dynamic memory paging (e.g, reading in pages of a memory-mapped file; allocating physical memory for a zero-fill memory region; copying COW memory pages). Similarly, other CPU exceptions, such as software interrupts or software-emulated instructions, may be interpreted by the operating system and passed back to the process without killing it.

(Also: consider the cases of core dump generation and debuggers. A process that is killed is not always destroyed immediately; the operating system may retain its state in memory for various purposes.)

Most operating systems will either flush the cache on a context switch, or will allow the CPU to write out pages from the cache normally. In either case, recent writes will certainly not be ignored.

  • thanks for your answer, it's very helpful! Can you, by any chance, recommend any good documentation resources, where I could find more information on the topic? maybe I'm missing the correct terms to search for. – torpedro Mar 24 '16 at 13:16