我正在尝试使用 kmalloc 在 Linux 内核中分配内存。我的结构设计如下:
struct st_fetch_point {
struct sk_buff *end_pkt ;
struct sk_buff *start_pkt ;
struct sk_buff *current_pkt ;
struct st_fetch_point *next_fortp ;
struct st_fetch_point *next_consec ;
};
我创建了一个 st_fetch_point 类型的新结构,并尝试以以下方式分配内存并为成员指针赋值:
struct st_fetch_point *first_fetch_point;
first_fetch_point = kmalloc((sizeof(struct st_fetch_point)), GFP_ATOMIC);
if (!first_fetch_point)
return -ENOMEM;
skb = tcp_send_head(meta_sk);
first_fetch_point->start_pkt = skb;
first_fetch_point->current_pkt = skb;
first_fetch_point->end_pkt = NULL;
first_fetch_point->next_fortp = NULL;
first_fetch_point->next_consec = NULL;
但是每次执行 kmalloc() 行时,内核似乎都在冻结。我正在开发 ubuntu 14.04 并且确实在修复中。我检查了 syslog 和 kernlog 文件,没有发现任何与冻结有关的异常消息。这是 kmalloc() 分配方法的任何问题吗?