What happens if the size of a program is larger than virtual memory? - operating-system

I came across this question recently in a telephonic interview:
What happens if the size of a program is larger than the size of virtual memory?
Will it not be allowed to run or how does the os go about dealing with it?

Yes, it is possible to have program that will run even if total size is bigger than address space.
Programs large than available address space existed for very long time. Common way is to split program into chunks that can fit into address space and than sequentially/on demand load other chunks.
If you have player that can play a file it will play a file. Not sure how it is related to OS...

Yes, you definitely can. Overlaying is the mechanism used. CPU brings in only that part of the code that is to be executed in the main memory and is currently needed. The rest of the code resides in the secondary memory and can then be brought when needed.

Related

How does virtual memory support the use of more memory than is physically installed in a computer?

How an operating system’s use of virtual memory enables the operating system to appear to support the use of more memory than is physically installed in a computer
I'm not sure how to explain this in detail, but im thinking because virtual memory is based on paging, thus a single process can demand more memory than the amount of physical memory stored. Therefore it "appears" to use more memory than the amount of physical memory.
But Im not sure if that explains it :(
Basically, as the name states, the virtual memory doesn't "exists" or is not directly related to physical memory.
The virtual memory of a process is stored on the disk, containing all the information concerning the real process. See virtual memory for some more insights. When a process is scheduled in by the processor, some parts of its memory is brought back into the main memory through memory swapping. The pages that are needed at that moment by the process are in the main memory. And the pages that are not that much used (by any process) are just swapped-out because the main memory can't contain everything at the same time.
Hope I helped :)

If using Pure Demand Paging, how does CPU know where the first instruction is in the executable?

I am reading Chap9 of Operating System Concepts and the concept of pure demand paging is described as follows:
In the extreme case, we can start executing a process with no pages in
memory. When the operating system sets the instruction pointer to the first instruction of the process, which is on a non-memory-resident page, the process
immediately faults for the page....
But if NONE of the pages, particularly the pages containing code, are in memory, how does the OS know where the program counter is in the first place? Is program counter set as part of process creation by inspecting the program image on disk? If so, I would assume the OS knows the format of the binary image and can directly access that info on disk. And it will only make sense if somehow this info is stored in the part of the program image not needed during program execution, if OS decides not to bring the page containing this info into memory.
To summarize, I would like to know:
How is program counter set for a new process if using pure demand paging?
Is any real OS using pure demand paging and what benefit does it have?
How does an executable's binary format (e.g. ELF, PE formats) help the OS do demand paging (OS needs to know where the first page is at least?)

Unusual spikes in CPU utilization in CentOS 6.6 while starting pycharm

my system since last couple of days is behaving strangely. I am a regular user of pycharm software, and it used to work on my system very smoothly with no hiccups at all. But since last couple of days, whenever I start pycharm, my CPU utilization behaves strangly, like in the image: Unusual CPU util
I am confused as when I go to processes or try ps/top in terminal, there are no process which is utilizing cpu more then 1 or 2%. So I am not sure where these resources are getting consumed.
By unusual CPU util I mean, That first CPU1 is getting used 100% for couple or so minutes, then CPU2. Which is, only one cpu's utilization goes to 100% for sometime followed by other's. This goes on for 10 to 20 minutes. then system comes back to normal.
P.S.: I don't think this problem is related to pycharm, as I face similar issues while doing other work also, just that I always face this with pycharm for sure.
POSSIBLE CAUSE: I suspect you have a thrashing problem. The CPU usage of your applications are low because none of them are actually getting much useful work done. All the processing is being taken up by moving memory pages to and from the disk. Your CPU usage probably settles down after a time because your application has entered a state where its memory working set has shrunk to a point where it all can be held in memory at one time.
This has probably happened because one of the apps on your machine is handling a larger data set than before, and so requires more addressable memory. Another possibility is that, for some reason, a lot more apps are running on your machine.
POTENTIAL SOLUTION: There are several ways you can address this. The simplest is to put more RAM on your machine. If this doesn't work or isn't possible, you'll have to figure out which app is the memory hog. You may simply have to work with smaller problems/data-sets or offload some of the apps onto a different box.
MIGRATING CPU LOAD: Operating systems will move tasks (user apps, kernel) around for many different reasons. The reasons can range anywhere from it being just plain random to certain apps having more of their addressable memory in one bank vs another. Given that you are probably doing a lot of thrashing, I'm not surprised that the processor your app is running is randomized over time.

Demand paging---is the physical address changing?

I'm doing an operating systems course at university and need to implement demand paging as a part of the major project. I've got the idea behind it, but just need to confirm some things.
Suppose physical memory is full, and a frame is chosen as victim to be written to disk, so that something else can be put in its place. When that frame is paged back in, and its old spot in the physical memory has been occupied by other things, does it mean I need to allocate another physical frame to put the old data and update the user's page table, so that from the user's point of view, the virtual memory stays the same but the physical memory has changed? Am I understanding the semantics of demand paging correctly? If not, how is it usually done?
Cheers

What do "Dirty" and "Resident" mean in relation to Virtual Memory?

I dropped out of the CS program at my university... So, can someone who has a full understanding of Computer Science please tell me: what is the meaning of Dirty and Resident, as relates to Virtual Memory? And, for bonus points, what the heck is Virtual Memory anyway? I am using the Allocations/VM Tracker tool in Instruments to analyze an iOS app.
*Hint - try to explain as if you were talking to an 8-year old kid or a complete imbecile.
Thanks guys.
"Dirty memory" is memory which has been changed somehow - that's memory which the garbage collector has to look at, and then decide what to do with it. Depending on how you build your data structures, you could cause the garbage collector to mark a lot of memory as dirty, having each garbage collection cycle take longer than required. Keeping this number low means your program will run faster, and will be less likely to experience noticeable garbage collection pauses. For most people, this is not really a concern.
"Resident memory" is memory which is currently loaded into RAM - memory which is actually being used. While your application may require that a lot of different items be tracked in memory, it may only require a small subset be accessible at any point in time. Keeping this number low means your application has lower loading times, plays well with others, and reduces the risk you'll run out of memory and crash as your application is running. This is probably the number you should be paying attention to, most of the time.
"Virtual memory" is the total amount of data that your application is keeping track of at any point in time. This number is different from what is in active use (what's being used is marked as "Resident memory") - the system will keep data that's tracked but not used by your application somewhere other than actual memory. It might, for example, save it to disk.
WWDC 2013 - 410 Fixing Memory Issues Explains this nicely. Well worth a watch since it also explains some of the practical implications of dirty, resident and virtual memory.