POSIX 最初想法是:如果 sticky bit 设置了,进程中的“ text segment” 将会留在 swap 空间中;这样会使得它只需一次硬盘读就可以将其读入内存中。起初, UNIX 使用大小为 512 字节且趋于分散的块;因此需要一定的时间去收集那些分散的“ text segment” 并加载到内存中去。最早期的 UNIX 中没有页面调度,只有页面交换技术;因此要运行一个程序需要全部加载到内存中去;现在我们根据程序的需要加载数据页到内存中。这是不是说 sticky bit 的初始用途已经消失的呢?答案是否定的,根据不同的操作系统有不同的情况。
在 HP-UX 中, sticky bit 依然存在并可以在 HP-UX chmod(2) man page [1] 中查证。什么在用 sticky bit 呢?,通过 HP-UX FAQ [2] 中可以看到在 [The HP-UX Kernel Tuning and Performance Guide] 中有如下描述:
"When applications are located remotely, set the "sticky bit" on the applications binaries, using the chmod +t command. This tells the system to page the text to the local disk. Otherwise, it is "retrieved" across the network. Of course, this would only apply when there is actual paging occurring. More recently, there is a kernel parameter, page_text_to_local, which when set to 1, will tell the kernel to page all NFS executable text pages to local swap space."
在 Solaris 中虽然没有关于 sticky bit 初始用途的说明,但根据 Solaris chmod(2) man page [3] 可以看到如下描述 :"If a regular file is not executable and has S_ISVTX set, the file is assumed to be a swap file. In this case, the system's page cache will not be used to hold the file's data. If the S_ISVTX bit is set on any other file, the results are unspecified."
如果你发现一个文件设置了sticky bit,您就需要查看对应操作系统的chmod命令的man page看看有什么样的影响。另外请注意,如果有影响,OS会限制对root设置sticky bit。例如:在HP-UX,一个恶意的用户可以设置很多sticky bit让系统用完swap空间导致系统崩溃。
以下是不同OS的chmod帮助手册中对sticky bit描述:
表一:不同OS对sticky bit的描述
HP-UX实际上还有一些符号链接文件设置了sticky bit,这将在以后的文章中继续讨论。
[1] 参考 HP-UX chmod 命令帮助手册 : http://docs.hp.com/en/B2355-90693/chmod.2.html
[2] 参考 HP-UX FAQ : http://www.faqs.org/faqs/hp/hpux-faq/
[3] 参考 Solaris chmod 命令帮助手册 : http://docs.sun.com/app/docs/doc/816-5167/chmod-2?a=view
[4] 其它参考资料: www.wikipedia.org
A. http://nixdoc.net/man-pages/Linux/man1/chmod.1.html
B. http://nixdoc.net/man-pages/FreeBSD/man2/chmod.2.html
C. http://nixdoc.net/man-pages/IRIX/man2/standard/chmod.2.html
D. http://www.manpagez.com/man/2/chmod/
E. http://uw714doc.sco.com/en/man/html.2/chmod.2.html