slab_page归还Buddy引发的问题

这里我判断slab_page满足归还Buddy的条件后,调用free_slab_page函数。

该函数具体实现如下:


直接调用free_in_buddy归还:

运行后,在加载完内核之后就kernel panic了。

[ DEBUG ] (src/net/net_core.rs:66) DHCP try round: 0
[ DEBUG ] (/home/jomo/.cargo/registry/src/rsproxy.cn-8f6827c7555bfaf8/smoltcp-0.11.0/src/socket/dhcpv4.rs:615) DHCP send DISCOVER to 255.255.255.255: Repr { message_type: Discover, transaction_id: 246017557, secs: 0, client_hardware_address: Address([82, 84, 0, 18, 52, 86]), client_ip: Address([0, 0, 0, 0]), your_ip: Address([0, 0, 0, 0]), server_ip: Address([0, 0, 0, 0]), router: None, subnet_mask: None, relay_agent_ip: Address([0, 0, 0, 0]), broadcast: false, requested_ip: None, client_identifier: Some(Address([82, 84, 0, 18, 52, 86])), server_identifier: None, parameter_request_list: Some([1, 3, 6]), dns_servers: None, max_size: Some(1918), lease_duration: None, renew_duration: None, rebind_duration: None, additional_options: }
[ DEBUG ] (/home/jomo/.cargo/registry/src/rsproxy.cn-8f6827c7555bfaf8/smoltcp-0.11.0/src/socket/dhcpv4.rs:352) DHCP recv Offer from 10.0.2.2: Repr { message_type: Offer, transaction_id: 246017557, secs: 0, client_hardware_address: Address([82, 84, 0, 18, 52, 86]), client_ip: Address([0, 0, 0, 0]), your_ip: Address([10, 0, 2, 15]), server_ip: Address([10, 0, 2, 2]), router: Some(Address([10, 0, 2, 2])), subnet_mask: Some(Address([255, 255, 255, 0])), relay_agent_ip: Address([0, 0, 0, 0]), broadcast: false, requested_ip: None, client_identifier: None, server_identifier: Some(Address([10, 0, 2, 2])), parameter_request_list: None, dns_servers: Some([Address([10, 0, 2, 3])]), max_size: None, lease_duration: Some(86400), renew_duration: None, rebind_duration: None, additional_options: }
[ DEBUG ] (/home/jomo/.cargo/registry/src/rsproxy.cn-8f6827c7555bfaf8/smoltcp-0.11.0/src/socket/dhcpv4.rs:643) DHCP send request to 255.255.255.255: Repr { message_type: Request, transaction_id: 2810779945, secs: 0, client_hardware_address: Address([82, 84, 0, 18, 52, 86]), client_ip: Address([0, 0, 0, 0]), your_ip: Address([0, 0, 0, 0]), server_ip: Address([0, 0, 0, 0]), router: None, subnet_mask: None, relay_agent_ip: Address([0, 0, 0, 0]), broadcast: false, requested_ip: Some(Address([10, 0, 2, 15])), client_identifier: Some(Address([82, 84, 0, 18, 52, 86])), server_identifier: Some(Address([10, 0, 2, 2])), parameter_request_list: Some([1, 3, 6]), dns_servers: None, max_size: Some(1918), lease_duration: None, renew_duration: None, rebind_duration: None, additional_options: }
[ DEBUG ] (/home/jomo/.cargo/registry/src/rsproxy.cn-8f6827c7555bfaf8/smoltcp-0.11.0/src/socket/dhcpv4.rs:352) DHCP recv Ack from 10.0.2.2: Repr { message_type: Ack, transaction_id: 2810779945, secs: 0, client_hardware_address: Address([82, 84, 0, 18, 52, 86]), client_ip: Address([0, 0, 0, 0]), your_ip: Address([10, 0, 2, 15]), server_ip: Address([10, 0, 2, 2]), router: Some(Address([10, 0, 2, 2])), subnet_mask: Some(Address([255, 255, 255, 0])), relay_agent_ip: Address([0, 0, 0, 0]), broadcast: false, requested_ip: None, client_identifier: None, server_identifier: Some(Address([10, 0, 2, 2])), parameter_request_list: None, dns_servers: Some([Address([10, 0, 2, 3])]), max_size: None, lease_duration: Some(86400), renew_duration: None, rebind_duration: None, additional_options: }
[ INFO ] (src/net/net_core.rs:94) Successfully allocated ip by Dhcpv4! Ip:10.0.2.15/24
[ DEBUG ] (src/init/initial_kthread.rs:47) initial kernel thread done.
e[41m[ ERROR ] e[0m(src/lib.rs:115) Kernel Panic Occurred.

请问可能是什么原因引起的呢?

怕不是这里的内存还在使用,你就把他释放了。
或者是释放的页面数量不对。
以及你看free_in_buddy的实现,ptr应当是4K对齐的

还真是,没有对齐4K,原因是没有从slab_page的起始地址开始释放

1 个赞