Skip to content

Conversation

Ticonderoga2017
Copy link

@Ticonderoga2017 Ticonderoga2017 commented May 29, 2025

根据内核代码进行了部分修改,重点修改测例,对以下方面进行测试:

  • 4K页面分配和释放,2M页面分配和释放,1G页面分配和释放,分配之后读写内存,然后在释放
  • 4K页面,2M页面,1G页面先统一分配,然后统一释放 ,分配之后读写内存,然后在释放
  • 4K页面,2M页面,1G页面交替分配和释放 ,分配之后读写内存,然后在释放
  • 测试4K页面,2M页面,1G页面立即分配和懒分配 ,分配之后读写内存,然后在释放
  • 测试文件在4K页面,2M页面的读写处理
  • 测试4K页面,2M页面,1G页面的线性映射

@Ticonderoga2017 Ticonderoga2017 force-pushed the main branch 2 times, most recently from 325bb1b to 6a3b6a8 Compare May 30, 2025 07:16
@Ticonderoga2017 Ticonderoga2017 force-pushed the main branch 4 times, most recently from a7dd997 to f2fc8e7 Compare June 12, 2025 08:28
Cargo.toml Outdated
starry-core = { path = "./core" }
starry-api = { path = "./api" }

page_table_multiarch = { git = "https://github.com/Mivik/page_table_multiarch.git", rev = "19ededd" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this? We have patched it in this TOML.

api/Cargo.toml Outdated

starry-core.workspace = true

page_table_multiarch.workspace = true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can directly add this dependency, like page_table_multiarch = "0.5"

use axerrno::{LinuxError, LinuxResult};
use axhal::paging::MappingFlags;
use axtask::{TaskExtRef, current};
use linux_raw_sys::general::{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we directly use linux_raw_sys::general::*?


// The check uses bitwise operations to
// verify that exactly one of the two mutually exclusive mapping flags is set
if (map_flags.bits() & (MAP_PRIVATE | MAP_SHARED)).count_ones() != 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use map_flags.contains(MappingFlags::SHARED | MappingFlags::PRIVATE)


let start = memory_addr::align_down_4k(addr);
let end = memory_addr::align_up_4k(addr + length);
let page_size = match (flags & MAP_HUGETLB, flags & MAP_HUGE_MASK << MAP_HUGE_SHIFT) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use if else to let the logic more clear

api/src/ptr.rs Outdated
let page_start = start.align_down_4k();
let page_end = (start + layout.size()).align_up_4k();
aspace.populate_area(page_start, page_end - page_start)?;
aspace.populate_area(page_start, page_end - page_start, PageSize::Size4K)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we will remove the alignment argument because the area has its own alignment.


test ! -d "$AX_ROOT" && echo "Cloning repositories ..." || true
test ! -d "$AX_ROOT" && git clone https://github.com/oscomp/arceos "$AX_ROOT" --depth=1 || true
test ! -d "$AX_ROOT" && git clone https://github.com/Ticonderoga2017/arceos "$AX_ROOT" --depth=1 || true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update it

@Ticonderoga2017 Ticonderoga2017 force-pushed the main branch 4 times, most recently from 0ca0916 to 4fcfcf7 Compare June 13, 2025 08:43
…ocating multiple consecutive 1GB huge pages.

let start = memory_addr::align_down_4k(addr);
let end = memory_addr::align_up_4k(addr + length);
let page_size = if flags & MAP_HUGETLB == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use map_flags? And you can add more flags for MmapFlags type:

struct MmapFlags: u32 {
/// Share changes
const SHARED = MAP_SHARED;
/// Changes private; copy pages on write.
const PRIVATE = MAP_PRIVATE;
/// Map address must be exactly as requested, no matter whether it is available.
const FIXED = MAP_FIXED;
/// Don't use a file.
const ANONYMOUS = MAP_ANONYMOUS;
/// Don't check for reservations.
const NORESERVE = MAP_NORESERVE;
/// Allocation is for a stack.
const STACK = MAP_STACK;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you can use MmapFlags.contains() function and avoid operations over the i32 type.

// TODO: check illegal flags for mmap
// An example is the flags contained none of MAP_PRIVATE, MAP_SHARED, or MAP_SHARED_VALIDATE.
let map_flags = MmapFlags::from_bits_truncate(flags);
if map_flags.contains(MmapFlags::from_bits_truncate(MAP_PRIVATE | MAP_SHARED)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrite it as below:

    if map_flags.contains(MmapFlags::SHARED | MmapFlags::PRIVATE) {
        return Err(LinuxError::EINVAL);
    }

let page_size = if flags & MAP_HUGETLB == 0 {
PageSize::Size4K
} else {
match flags & MAP_HUGE_MASK << MAP_HUGE_SHIFT {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use MAP_HUGE_1GB or MAP_HUGE_256MB from linux_raw_sys::general

let mut aspace = process_data.aspace.lock();
let length = memory_addr::align_up_4k(length);
let start_addr = VirtAddr::from(addr);
let length = memory_addr::align_up_4k(length);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why move it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And you can import align_up and align_up_4k at the global scope.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set use memory_addr::{align_up_4k, align_up}

@Azure-stars
Copy link
Collaborator

And please add the updated commit hash for arceos backbone.
See cd0a53a

@Azure-stars
Copy link
Collaborator

api/Cargo.toml Outdated
ctor_bare = "0.2.1"
flatten_objects = "0.2.3"
num_enum = { version = "0.7", default-features = false }
page_table_multiarch = "0.5"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this dependency because PageSize can be provided by axhal::paging

use memory_addr::{VirtAddr, VirtAddrRange};
use linux_raw_sys::general::*;
use memory_addr::{MemoryAddr, VirtAddr, VirtAddrRange};
use page_table_multiarch::PageSize;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use axhal::paging::PageSize;

let mut aspace = process_data.aspace.lock();
let length = memory_addr::align_up_4k(length);
let start_addr = VirtAddr::from(addr);
let length = memory_addr::align_up_4k(length);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set use memory_addr::{align_up_4k, align_up}


AX_ROOT=.arceos
COMMIT=c747ba8
COMMIT=b55bc93
Copy link
Collaborator

@Azure-stars Azure-stars Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the commit to the latest commit: oscomp/arceos@54d5739

@Ticonderoga2017 Ticonderoga2017 force-pushed the main branch 3 times, most recently from fea706b to 8bd0a8a Compare June 17, 2025 03:00
@Azure-stars Azure-stars merged commit e9125d8 into oscomp:main Jun 17, 2025
25 checks passed
@Azure-stars Azure-stars mentioned this pull request Jun 17, 2025
Mivik pushed a commit to Mivik/starry-next that referenced this pull request Jun 21, 2025
1. Support hugepage mmap.
2. Modify the testcase to avoid panic when allocating multiple consecutive 1GB huge pages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants