内存管理API之kunmap_high

void kunmap_high(struct page *page)一般和kmap_high一起搭配使用,用于unmap highmem page into memory
其源码分析如下:
/**
 * kunmap_high - unmap a highmem page into memory
 * @page: &struct page to unmap
 *
 * If ARCH_NEEDS_KMAP_HIGH_GET is not defined then this may be called
 * only from user context.
 */
void kunmap_high(struct page *page)
{
	unsigned long vaddr;
	unsigned long nr;
	unsigned long flags;
	int need_wakeup;
	#根据page得到color,后面会跟你这个color得到一个等待队列
	unsigned int color = get_pkmap_color(page);
	wait_queue_head_t *pkmap_map_wait;
	#一般和unlock_kmap_any 配合使用
	lock_kmap_any(flags);
	#得到这个page的虚拟地址
	vaddr = (unsigned long)page_address(page);
	BUG_ON(!vaddr);
	#根据这个page的虚拟地址得到这个page在pkmap_count 中的index
	nr = PKMAP_NR(vaddr);

	/*
	 * A count must never go down to zero
	 * without a TLB flush!
	 */
	need_wakeup = 0;
	#看这个page 对应的pkmap_count 是否为零,为零的话就是bug,从注释看对应的pkmap_count是在TLB flush中才会为零的
	switch (--pkmap_count[nr]) {
	case 0:
		BUG();
	case 1:
		/*
		 * Avoid an unnecessary wake_up() function call.
		 * The common case is pkmap_count[] == 1, but
		 * no waiters.
		 * The tasks queued in the wait-queue are guarded
		 * by both the lock in the wait-queue-head and by
		 * the kmap_lock.  As the kmap_lock is held here,
		 * no need for the wait-queue-head's lock.  Simply
		 * test if the queue is empty.
		 */
		 #正常情况下,根据color得到一个等待队列
		pkmap_map_wait = get_pkmap_wait_queue_head(color);
		#检查这个队列是否需要wakeup
		need_wakeup = waitqueue_active(pkmap_map_wait);
	}
	unlock_kmap_any(flags);

	/* do wake-up, if needed, race-free outside of the spin lock */
	#如果需要wakeup的话,则通过wake_up 来唤醒这个等待队列
	if (need_wakeup)
		wake_up(pkmap_map_wait);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`skb_release` 函数是 Linux 内核中用来释放 `skb` 数据结构(网络数据包缓冲区)的函数。它的定义在文件 `net/core/skbuff.c` 中。 下面是 `skb_release` 函数的代码及注释: ```c void skb_release(struct sk_buff *skb) { struct nf_hook_state state; unsigned int i; /* Call the packet destroy function for nf_hooks */ if (unlikely(nf_hooks_needed(skb))) nf_hook_state_init(&state, NFPROTO_UNSPEC, NF_HOOK_INVALID, NULL, skb, NULL, dev_net(skb->dev), 0); for (i = 0; i < NFPROTO_NUMPROTO; i++) nf_hook(NFPROTO(i), NF_INET_PRE_ROUTING, &state, skb, skb->dev, NULL, skb_dst(skb)->dev, NULL, skb->protocol); /* Call the destructor for each extension header. */ for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { if (skb_shinfo(skb)->frags[i].page) kmap_atomic(skb_shinfo(skb)->frags[i].page); if (skb_shinfo(skb)->destructor[i]) skb_shinfo(skb)->destructor[i](skb); if (skb_shinfo(skb)->frags[i].page) kunmap_atomic(skb_shinfo(skb)->frags[i].page); } if (skb_shinfo(skb)->frag_list) kfree_skb_list(skb_shinfo(skb)->frag_list); /* Release the skb itself */ kmem_cache_free(skbuff_head_cache, skb); } ``` 该函数的作用是释放 `skb` 数据结构,它的主要步骤包括: 1. 如果 `skb` 上注册了网络钩子(`nf_hook`),则依次调用每个网络钩子的销毁函数(`nf_hook` 函数的第 4 个参数)。 2. 对于 `skb` 中的每个扩展头,调用其析构函数(`destructor`)进行清理,以释放扩展头占用的内存。 3. 如果 `skb` 中存在分段数据(`frag_list`),则释放分段数据占用的内存。 4. 最后,释放 `skb` 本身占用的内存。 需要注意的是,该函数只是释放 `skb` 数据结构本身占用的内存,但并不会释放 `skb` 引用的其他内存(例如数据包的内容、关联的网络设备等)。这些内存的释放由其他函数负责。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值