plbrault / youre-the-os

A game where you are a computer's OS and you have to manage processes, memory and I/O events.
https://plbrault.github.io/youre-the-os/
GNU General Public License v3.0
1.81k stars 69 forks source link

[Feature Request] Prevent OOM #69

Closed BeiyanYunyi closed 1 year ago

BeiyanYunyi commented 1 year ago

Hello, I'm writing an "automatic" version of this game: let the program play itself.

But it seems like that the amount of processes will keep increasing, leading to the "Out of Memory" problem: both RAM and swap space are filled with pages, making any page swapping impossible and causing user ragequits.

In real OS, the system kills some processes to prevent this, so I think the "OOM" problem is unintended and should be fixed.

I have a dirty solution:

# /src/game_objects/pages_manager.py
    def is_oom(self):
        for ram_slot in self._ram_slots:
            if not ram_slot.has_page:
                return False
        for swap_slot in self._swap_slots:
            if not swap_slot.has_page:
                return False
        return True

# /src/game_objects/process.py

    def update(self, current_time, events):
    # ...
        if not self.has_ended:
    # ...
            if self._has_cpu and self._page_manager.is_oom():
                self._terminate_gracefully()

If you think it's a good idea, I can open a Pull Request.


EDIT: My solution will cause a UI bug in the "automatic" version.

plbrault commented 1 year ago

Thank you for bringing this to my attention. The actual intended behaviour is that it should not be mathematically possible to run into an OOM problem, but I seem to have made a mistake while reworking the max numbers of processes and pages in v1.1.0. I will fix this shortly.

I do however like your idea of introducing the OOM problem as part of the game, but it should be handled by the player rather than done automatically since managing processes and memory is the point of the game. This raises the question of what consequence killing a process should have on the game as it should certainly contribute to anger the user ;)