OK6410A Development Board (VIII) 40 linux-5.11 OK6410A buddy alloc and free

Publisher:hxcp18Latest update time:2022-09-06 Source: csdnKeywords:OK6410A Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The third stage is to establish a buddy


Buddy's lifespan

mm_init->mem_init returns - no end point


Buddy managed memory size

The memory managed by buddy is determined by memblock

The portion of memblock.memory that does not include memblock.reserved


memblock can reserve memory through memblock_alloc or memblock_reserve


How to use buddy

alloc

alloc_pages/alloc_page // Returns struct page

get_zeroed_page // Returns the virtual address

__get_free_pages/__get_free_page // Returns the virtual address

get_dma_pages


__get_free_pages

struct page *page = alloc_pages

alloc_pages_node

__alloc_pages_node

__alloc_pages

__alloc_pages_nodemask

struct page * page = get_page_from_freelist

return (unsigned long) page_address(page);


__alloc_pages_nodemask details

__alloc_pages_nodemask

  prepare_alloc_context //1. Prepare parameters

  get_page_from_freelist //2. According to the parameters obtained by prepare_alloc_context, the fast path attempts to allocate memory 

  __alloc_pages_slowpath //3. If the fast path fails to allocate memory, the slow path attempts to allocate memory

For details, please visit https://zhuanlan.zhihu.com/p/258921453

highly recommended


prepare_alloc_context // Set three parameters of get_page_from_freelist function

1. struct alloc_context *ac

ac->migratetype = gfp_migratetype(gfp_mask); // Set the required migration type, related to zone->free_area[order].free_list[migratetype]

2. gfp_t *alloc_mask

*alloc_mask |= __GFP_HARDWALL;

3. unsigned int *alloc_flags

*alloc_flags = current_alloc_flags(gfp_mask, *alloc_flags);


get_page_from_freelist 

for_next_zone_zonelist_nodemask(zone, z, ac->highest_zoneidx, ac->nodemask) { // Traverse the zones according to the priority of ZONE_HIGHMEM ZONE_NORMAL ZONE_DMA

mark = wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK); // Get the current watermark

if (!zone_watermark_fast(zone, order, mark, ac->highest_zoneidx, alloc_flags, gfp_mask)) { 

// Compare with the watermark FLAG set by alloc_pages

// Entering the if function body at this time indicates that the current watermark <= the watermark FLAG set by alloc_pages, indicating that no more physical pages can be allocated

if (alloc_flags & ALLOC_NO_WATERMARKS) goto try_this_zone;

// Indicates the watermark set by alloc_pages FLAG means ignoring the watermark, and directly allocates pages to the try_this_zone label

}

try_this_zone:

page = rmqueue(ac->preferred_zoneref->zone, zone, order, gfp_mask, alloc_flags, ac->migratetype);

if (likely(order == 0)) rmqueue_pcplist(preferred_zone, zone, gfp_flags, migratetype, alloc_flags);

// Check whether the linked list maintained by per_cpu_pages (pcp) can satisfy the memory request

else __rmqueue(zone, order, migratetype, alloc_flags);

// Apply from the partner system, the query list is

// zone->free_area[order].free_list[migratetype]

__rmqueue_smallest(zone, order, migratetype);

area = &(zone->free_area[current_order]);

page = get_page_from_free_area(area, migratetype);

del_page_from_free_list(page, zone, current_order);

}


__alloc_pages_slowpath

Various mechanisms for invoking memory shortage

...relaim

... compact

... oom killer

... kswapd

get_page_from_freelist(gfp_mask, order, alloc_flags, ac);


free

free_pages/free_page

__free_pages/__free_page



free_pages(unsigned long addr, unsigned int order)

__free_pages(virt_to_page((void *)addr), order);

free_the_page(page, order)

__free_pages_ok

free_one_page

__free_one_page

add_to_free_list(page, zone, order, migratetype);


other

The essence of buddy

The buddy system only maintains free blocks, and the allocated blocks do not belong to the buddy system.

After calling free_pages on some blocks, they will be put into the buddy system.

---


Disassembly & Merge

The essence of buddy is to split and merge according to 2^n


Buddy Problems and Solutions


// Is there any virtual memory problem?


1. Physical memory fragmentation problem

Buddy Merge

Timing: free_pages

method:

Threads: None

Compact

Timing: alloc

method:

Threads: 1 thread kcompactd0

2. Insufficient physical memory

Reclaim

Timing: when alloc memory is scarce/cycle/system sleep

method:

Threads: 2 threads kswapd0 oom_reaper

3. Unable to apply for consecutive physical pages

CMA contiguous memory allocator

Timing: when allocating continuous memory

method: 

A section of memory is reserved for the driver to use, but when the driver is not in use, the CMA area can be allocated to the user process for use as anonymous memory or page cache.

When the driver needs to use it, the memory occupied by the process is recycled or migrated to free up the reserved memory previously occupied for use by the driver.

Threads: None


miscellaneous

---

5. If __GFP_DMA is set, pages can only be obtained from the ZONE_DMA memory management area

6. If __GFP_HIGH is not set, get pages from the ZONE_NORMAL ZONE_DMA memory management area in turn

7. If __GFP_HIGH is set, get pages from ZONE_HIGHMEM ZONE_NORMAL ZONE_DMA memory management areas in turn


---


Page frames are unlimited and can store any data

x86 hardware has restrictions on page frames, resulting in the addition of ZONE (ZONE page frame classification)

There is no zone, or there is only one zone : ZONE_NORMAL 16MB - 896MB

1.DMA can only address the first 16MB of RAM : Added ZONE_DMA 0MB - 16MB

2.32bit cannot address all physical memory : Added ZONE_HIGHMEM 896M


What about arm32???

Page frames are unlimited and can store any data

The arm32 hardware has restrictions on page frames, resulting in the addition of ZONE (ZONE page frame classification)

There is no zone, or there is only one zone : ZONE_NORMAL 0MB - 760MB

1.32bit cannot address all physical memory : Added ZONE_HIGHMEM 760MB -  


---


status quo

CONFIG_ZONE_DMA CONFIG_ZONE_DMA32 CONFIG_HIGHMEM is not configured

There are only two zones: ZONE_NORMAL ZONE_MOVABLE


---

For arm32, when do you need to configure CONFIG_HIGHMEM?

200MB does not require CONFIG_HIGHMEM

1GB needs to be configured because the kernel space is only 1G, and the memblock reservation is less than 1G, so it cannot be fully mapped.


---


S3C6410 DMA


6410 has DMA

Source and destination are both available in system bus/peripheral bus (4 cases)

It uses ARM's IP PL080

4 DMAs, 8 channels per DMA


No limit on memory

Keywords:OK6410A Reference address:OK6410A Development Board (VIII) 40 linux-5.11 OK6410A buddy alloc and free

Previous article:OK6410A Development Board (VIII) 41 linux-5.11 OK6410A slab alloc and free
Next article:OK6410A Development Board (VIII) 39 linux-5.11 OK6410A memblock alloc and free

Recommended ReadingLatest update time:2024-11-16 19:48

Design and implementation of three-dimensional rotating LED based on STC11F02E
0 Introduction Three-dimensional rotating LED, also known as POV LED, is an electronic product that uses the persistence of vision effect of the human eye to display graphics, animations and other information. It uses a rotating bracket, and the LEDs arranged on the bracket are controlled by the single-chip microcomp
[Microcontroller]
Design and implementation of three-dimensional rotating LED based on STC11F02E
Tesla releases FSD Beta V11.4.1 update with major architectural improvements
On May 11, Tesla pushed the FSD Beta V11.4.1 update to North American users. This V11.4.1 version has made major architectural improvements. According to Musk, this version can theoretically be released as FSD V12.0, but the real V12 version number needs to be reserved for the fully end-to-end AI version.
[Automotive Electronics]
The November Android phone price-performance ranking is released: Redmi, the king of 1,000 yuan, has been overtaken
     Last night, AnTuTu released the Android phone cost-effectiveness list for November. The former thousand-yuan king Redmi Note 10 Pro was overtaken by Motorola Edge S and ranked second.   According to the list, in the price range of 0-1999 yuan, Motorola Edge S 6+128GB took the first place in cost-effectiveness, wi
[Mobile phone portable]
The November Android phone price-performance ranking is released: Redmi, the king of 1,000 yuan, has been overtaken
Apple sells refurbished iPhone 11/11 Pro/11 Pro Max models overseas
Apple today began offering officially refurbished models of iPhone 11, iPhone 11 Pro and iPhone 11 Pro Max in some overseas countries. This is the first time that these models have been listed on Apple's official website as officially refurbished models.   The discounts on iPhone 11 refurbished models range from $10
[Mobile phone portable]
Apple sells refurbished iPhone 11/11 Pro/11 Pro Max models overseas
High-precision 360° panoramic view robot Stable wide voltage active crystal oscillator YSO110TR, realizing intelligent robot application
With the progress of science and technology, 360° panoramic view technology has gradually become one of the hot spots of robot applications. In the realization of 360° panoramic view application of robots, wide voltage active crystal oscillator YSO110TR plays a vital role, providing stable and reliable support for r
[robot]
Largan's November revenue was NT$5.244 billion, down 21% year-on-year
According to the Economic Daily, the financial report released today by optical lens manufacturer Largan Precision shows that the company's revenue in November was NT$5.244 billion (same unit below), a 2% increase from the previous month, but a 21% decrease from the same period last year. The total consolidated revenu
[Mobile phone portable]
The second-generation Snapdragon 8 empowers OnePlus 11, leading the future performance of Android flagships
The second-generation Snapdragon 8 empowers OnePlus 11, leading the future performance of Android flagships On January 4, OnePlus officially released a new generation of flagship product OnePlus 11. The new OnePlus 11 is equipped with the second-generation Snapdragon 8 mobile platform and is committed to creating a
[Mobile phone portable]
The second-generation Snapdragon 8 empowers OnePlus 11, leading the future performance of Android flagships
OK6410A Development Board (VIII) 86 linux-5.11 OK6410A Linux Debug Overview
Debugging scenarios There are so many debugging methods under Linux. We will choose different debugging methods for different scenarios. Now define the scene as follows 1. Fixed architecture 2. Fixed kernel configuration 3. Fixed releases 4. Fixed kernel version 5. Is there any virtual machine such as qemu?
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号