Linux FS

Mango milk 2021-02-23 16:09:51
linux fs


File descriptor (file descrition)
Number of file handles (file handle)

Each process has an open file table (fdtable). Each item in the table is struct file type , Contains some attributes of the open file, such as offset , Read write access mode, etc , This is a real file handle .

The file descriptor is an integer . representative fdtable Index location in ( Subscript ), Point to specific struct file( File handle ).

File descriptor (fd)

stay linux When you open a file in the system, you get the file descriptor , It's a very small positive integer . Each process is in PCB(Process Control Block) A file descriptor table is kept in , The file descriptor is the index of this table , Each table entry has a pointer to an open file .

Maximum file descriptor limit cat /proc/sys/fs/nr_open

Set the maximum file descriptor
vi /etc/security/limits.conf

  • soft nofile 999999
  • hard nofile 999999

ulimit -a View file descriptors

View the file descriptor of a process

Terminal process 1800640, Open the 15 File , Occupied 5 File descriptors
Even if a file is opened , There may also be no file descriptors , Like the current working directory , Memory mapped files and executable text files

View the current number of open files
lsof -P -n |wc -l

Statistical sorting
lsof -P -n |awk '{print $2}'| sort -n | uniq -c | sort -nr |head -10

Count the number of files opened by a process
lsof -p pid |wc -l

Number of file handles

Set the maximum number of handles
vi /etc/sysctl.conf

fs.file-max = 10240

The default value of this parameter is related to the memory size , You can use the formula :file-max ≈ Memory size (KB)/ 10

cat /proc/sys/fs/file-max View the maximum number of open file handles

cat /proc/sys/fs/file-nr see Handle is currently used Allocated unused handle Maximum number of handles

Where will file handles be allocated

open System call to open file (path_openat Kernel functions )

Open a directory (dentry_open function )

Shared memory attach (do_shmat function )

socket Socket (sock_alloc_file function )

The Conduit (create_pipe_files function )

epoll/inotify/signalfd Anonymity, etc inode file system (anon_inode_getfile function )

Reference source :
https://juejin.im/entry/5b56f...
https://blog.csdn.net/u013256...
https://blog.csdn.net/qq_2935...

版权声明
本文为[Mango milk ]所创,转载请带上原文链接,感谢
https://javamana.com/2021/02/20210223160805615q.html

  1. Deep understanding of Web protocol (3): http 2
  2. Tencent IEG open source AI SDK: automatic testing of chicken eating and MoBa games
  3. Mysql Command
  4. Docker dockerfile create image
  5. Redis Cluster
  6. 死磕Spring之IoC篇 - 文章导读
  7. Deep understanding of Web protocol (3): http 2
  8. JavaScript BOM operation
  9. JavaScript BOM operation
  10. 死磕Spring之IoC篇 - 文章导读
  11. k8s node 操作与维护
  12. k8s 证书更新
  13. 【Java面试题第三期】JVM中哪些地方会出现内存溢出?出现的原因是什么?
  14. HashMap连环问你能答出几道?
  15. k8s-cronjob
  16. k8s-cert
  17. 头条面试官:说说Kafka的消费者提交方式,怎么实现的
  18. 什么是HTTPS以及如何实施HTTPS?
  19. Spring: an introduction to IOC
  20. Spring: an introduction to IOC
  21. Operation and maintenance of k8s node
  22. K8s certificate update
  23. vue使用sdk进行七牛上传
  24. k8s-dns
  25. JavaScript 邮箱验证 - 正则验证
  26. k8s-dashboard
  27. HashMap连环问你能答出几道?
  28. Where does memory overflow occur in the JVM? What are the reasons for this?
  29. How many questions can you answer?
  30. k8s-cronjob
  31. spring注解--Transactional
  32. k8s-cert
  33. Will the Spring Festival holiday be extended to February 27 in 2021? Here comes the response
  34. Headline Interviewer: talk about Kafka's consumer submission method, how to achieve it
  35. 【k8s集群】搭建步骤
  36. k8s-kubeadm
  37. k8s-etcd
  38. What is HTTPS and how to implement it?
  39. Java中使用HashMap改进查找性能
  40. maven发布jar包运行时找不到类问题
  41. J2EE
  42. Vue uses SDK to upload seven cows
  43. k8s-dns
  44. JavaScript mailbox verification - regular verification
  45. k8s-dashboard
  46. How many questions can you answer?
  47. Spring annotation -- transactional
  48. [k8s cluster] construction steps
  49. k8s-kubeadm
  50. k8s-etcd
  51. Using HashMap to improve search performance in Java
  52. There is no class problem when Maven publishes jar package
  53. JavaScriptBOM操作
  54. J2EE
  55. k8s-prometheus-memory
  56. k8s-prometheus disk
  57. k8s-prometheus
  58. JavaScript BOM operation
  59. k8s-prometheus-memory
  60. k8s-prometheus disk