1

Everybody knows the problem of virtual memory fragmentation in a system. How can we improve the fragmentation problem from the kernel driver perspective in 32-bit kernel?

Since we can't control the application behavior. There are issues where 600 MB virtual memory available but still Out of memory occur.

Any suggestions highly appreciated.

Rahul Khandelwal
  • 149
  • 1
  • 12
  • 1
    "How can we improve the fragmentation problem from the kernel driver perspective in 32-bit kernel?" - A kernel **driver** can do nothing with the fragmentation. Memory management is performed by the kernel core only. – Tsyvarev Sep 12 '19 at 20:20
  • 1
    In the kernel **driver** we don’t use more memory than needed. In cases when you need more, allocate separate pages (`get_free_page()`) or virtual memory (`vmalloc()`). – 0andriy Sep 12 '19 at 20:22
  • 1
    @Tsyvarev, not fully true. See my comment. – 0andriy Sep 12 '19 at 20:23
  • @0andriy: I mean that driver cannot help to an **application** to get more memory. Of course, the driver can control its own needs. – Tsyvarev Sep 12 '19 at 22:13
  • Tsyvarev, My question is related to Virtual memory not physical memory. For Physical memory, we have many ways for handle fragmentation. We have per process VM space, if VM of that particular process is fragmented then is there any way to fix this? – Rahul Khandelwal Sep 13 '19 at 07:25
  • Granularity is page size. MMU allows to collect free pages in one bunch (`vmalloc()`). What exactly do you mean under *fragmentation*? – 0andriy Sep 13 '19 at 08:17
  • Understand this way. In a typical 32bit Linux system, The application can have 3GB per process CPU VM userspace. If the app does not use the virtual memory wisely, it may end up in out of memory and the app will crash. OOM will happen in 2 cases: 1. If no memory available or 2. If memory is fragmented and no big size buffer available. You can understand like display frame buffer or GPU Texture. Let's say if 700 MB VM available but the max buffer size available is 40 MB and app wants 50 MB then also it will get OOM. Can we do something here? – Rahul Khandelwal Sep 13 '19 at 08:55
  • 2
    Virtual memory for user space programs is allocated by `malloc` function in the **user space** lib. Only this function may handle the fragmentation issues. So, both the *kernel* core and a *kernel* dirver are out of the game here. Not sure why do you ask about them... By the way, I have found [that answer](https://stackoverflow.com/a/52018251/3440745) to the question on similar topic. Does it correlate with your question? – Tsyvarev Sep 13 '19 at 10:49
  • 1
    @Tsyvarev, not always. User may use `mmap()` as big apps usually do, and manage pages themselves. – 0andriy Sep 13 '19 at 18:57
  • Let's go into the depth of mmap or malloc. These are userspace APIs. I am thinking about the actual VM allocation for that process from the kernel side. Please correct me if I am wrong somewhere. – Rahul Khandelwal Sep 17 '19 at 16:21
  • When user call malloc or mmap. Things are not in the user's hand. Things are handled by the kernel. I don't think user app has enough capabilities to fix fragmentation. – Rahul Khandelwal Sep 17 '19 at 16:26

0 Answers0