简体   繁体   English

FUSE程序中的内存分配如何工作?

[英]How does memory allocation in FUSE programs work?

I am following an example FUSE Tutorial to understand how FUSE works in linux. 我正在遵循一个示例FUSE教程,以了解FUSE在Linux中的工作方式。 In the example all the dynamic data is allocated using malloc, and passed in as user data to the fuse_main function. 在该示例中,所有动态数据都使用malloc分配,并作为用户数据传递到fuse_main函数。 This data is later accessible for any fuse calls. 以后可通过任何保险丝调用访问此数据。 These calls need not be from the same process. 这些调用不必来自同一进程。 How does this work? 这是如何运作的?

To make the question more clear , i run the main bbfs program with ../src/bbfs rootdir mountdir to mount the file system. 为了使问题更清楚,我使用../src/bbfs rootdir mountdir运行主要的bbfs程序来挂载文件系统。 It is in the main() of bbfs.c that the malloc is called. 正是在bbfs.c的main()中调用了malloc。 The bbfs program also defines several fuse function calls. bbfs程序还定义了几个保险丝功能调用。 But this program exits after the filesystem is mounted. 但是该程序在文件系统挂载后退出。

How can other programs(or the kernel) which calls read() or open() on the mounted filesystem 其他程序(或内核)如何在已挂载的文件系统上调用read()open()

1.access the memory allocated using malloc by the bbfs program if it has already exited? 1.访问bbfs程序使用malloc分配的内存(如果已经退出)? Wouldn't the OS free up the memory allocated using malloc after the program bbfs exited? 程序bbfs退出后,操作系统是否不释放使用malloc分配的内存?

2.access the defined functions, if the process that defined them had already exited? 2.访问定义的函数,如果定义它们的过程已经退出? Where would the object code of the fuse functions reside after the process exited? 退出过程后,保险丝功能的object code将驻留在哪里?

I am a bit confused about the lifetimes of the object code and the heap memory objects here and how other programs (or the kernel) use it later. 我对目标代码和堆内存对象的生命周期以及其他程序(或内核)以后如何使用它感到困惑。 Any help or pointers would be appreciated. 任何帮助或指针,将不胜感激。

Most of your question is based on a false assumption: 您的大部分问题都基于错误的假设:

… But [the FUSE server] exits after the filesystem is mounted. …但是[FUSE服务器]在挂载文件系统后退出。

It's not actually exiting at all. 它实际上根本没有退出。 It's forking into the background and continuing to run as long as the filesystem is mounted. 只要挂载了文件系统,它就会进入后台并继续运行。

While it's running, everything works as normal. 在运行时,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM