Kernel Stack Distribution via Dynamic Allocation
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
The existing kernel stack allocation method in Linux leads to significant memory wastage and fragmentation due to a fixed default size of 16KB per thread, resulting in excessive memory consumption and allocation failures, especially on systems with limited memory capacity.
Innovation Solution
A kernel stack distribution method that dynamically allocates a contiguous virtual address space using a bitmap to manage thread kernel stacks, allowing for on-demand allocation of storage pages through a page-missing exception mechanism, which maps new storage pages to the target address space when the stack pointer overflows, optimizing memory usage and avoiding fragmentation.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If a fixed default size of 16KB is allocated to each thread's kernel stack, then the reliability and stability of kernel stack operations are improved, but the memory consumption increases significantly and causes waste
Solution Approach 1:
The patent implements dynamic kernel stack allocation where the stack size is not fixed at 16KB but is instead allocated based on actual usage needs. The system uses a memory pool and allocation algorithms to provide stack space dynamically, allowing the stack size to adapt to the actual requirements of each thread rather than reserving a fixed large amount for all threads.
Solution Approach 2:
The patent applies different memory allocation strategies to different threads based on their specific needs. Instead of uniformly allocating 16KB to every thread, the system evaluates each thread's actual stack requirements and allocates appropriately sized stacks, making the memory allocation locally optimized for each thread's characteristics.
2Ease of operation
If a fixed 16KB kernel stack is allocated to each thread, then the ease of operation and simplicity of stack management are improved, but memory fragmentation occurs and allocation failures increase
Solution Approach 1:
The patent segments the kernel stack memory into a memory pool that is divided into smaller allocatable units. Instead of treating the entire 16KB as a single fixed block, the system segments memory into pool pages that can be dynamically allocated and managed, reducing fragmentation while maintaining manageable complexity through structured pool management.
Solution Approach 2:
The patent creates a universal memory pool structure that serves multiple threads and multiple stack allocation requests. This memory pool acts as a multi-functional resource that can be allocated to any thread that needs stack space, eliminating the need for separate fixed allocations for each thread and thereby reducing overall fragmentation.
3Quantity of substance
If the kernel stack size is reduced to match actual usage, then the memory consumption is optimized, but the risk of stack overflow increases
Solution Approach 1:
The patent implements protective mechanisms including guard pages and overflow detection algorithms that are set up beforehand in the dynamically allocated stack. These cushioning measures ensure that even when stack size is reduced to match actual usage, the system can detect and prevent stack overflow conditions before they cause reliability issues.
Solution Approach 2:
The patent incorporates feedback mechanisms that monitor stack usage in real-time. When a thread approaches its allocated stack limit, the system receives feedback about the usage level and can take appropriate actions such as allocating additional stack space or preventing further allocations that would cause overflow, thereby maintaining reliability with optimized sizing.
Data Source
Figure 1a~2
Figure 3~4
Figure 5~6
AI summary
The invention discloses a kernel stack distribution method and device, and relates to the technical field of computers. According to the method and the device for allocating the kernel stack, the memory is allocated according to the required allocation mode. When the stack pointer of the thread overflows the page boundary in the address space, a page-missing exception is generated. A new storage page is distributed to the kernel stack in a page-missing exception processing program, and the new storage page is mapped to a target address space pointed by the kernel stack, so that the memory consumption of the kernel stack of the thread is greatly optimised, and the capability of detecting the kernel stack underflow exception is improved. A virtual address space is divided in advance for a thread kernel stack to use, so that the problem of memory fragmentation is effectively avoided.