> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man9/vnode_pager_setsize.9.md).

# vnode\_pager\_setsize.9

`vnode_pager_setsize` — 通知 VM 系统文件大小的更新

## 名称

`vnode_pager_setsize`

## 概要

```c
#include <sys/param.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>

void
vnode_pager_setsize(struct vnode *vp, vm_ooffset_t nsize)
```

## 描述

`vnode_pager_setsize` 让 VM 系统知道文件大小的变化，并用 `nsize` 更新 `vp` 中 vm 对象的对象大小和 vnode pager 大小。偏移量超过新对象大小的对象映射上的页错误将导致 `SIGBUS`。

如果文件大小缩小，旧 EOF 和新 EOF 之间的页面将从对象队列中移除。如果 `nsize` 参数指定的新 EOF 未对齐到页边界，则从 EOF 开始的部分页区域被清零并标记为无效（如果页面存在驻留）。

如果 vnode `vp` 没有分配 VM 对象，调用此函数的效果是无操作。

如果文件系统为 vnode 分配 vm 对象，则必须使用此函数在文件系统代码内实现截断。

## 锁

vnode 在入口处应以独占方式锁定，在出口处仍保持锁定。

## 参见

[vnode(9)](/man/man9/vnode.9.md)

## 历史

`vnode_pager_setsize` 手册页首次出现在 FreeBSD 14 中。

## 作者

本手册页由 Ka Ho Ng <khng@FreeBSD.org> 编写。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man9/vnode_pager_setsize.9.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
