I was just beginning to study the GPU Driver development on Linux. According to the kernel docs, there are two memory managers in Linux DRM, the GEM and the TTM. And the TTM is described as something complicated and general, while the GEM slight and simple but lacking the compatibility of video RAM.
The introduction in the kernel docs is very clear, but after a closer look into the implementation of AMD driver and the DRM GEM program, I've encountered several problems and found out it was not as simple and clear as implied in the docs.
The
drm_gem_object_funcsstruct is used to store the callbacks for the GEM object, I assume, but the AMD driver implementation (indrivers/gpu/drm/amd/amdgpu/amdgpu_gem.c) set the member variablesvmapandvumaptodrm_gem_ttm_vmapanddrm_gem_ttm_vumaprespectively, which seems to imply the GEM object would finally rely on the TTM module to do some of the memory works.The default callbacks setting in DRM VRAM management (in
drivers/gpu/drm/drm_gem_vram_helper.c) set the members ofdrm_gem_object_funcstodrm_gem_vram_object_xxxincludingpin,unpin,freeand so on. But themmapis assgineddrm_gem_ttm_mmap, another function from the TTM helper module.The
freeimplementation in GEM,drm_gem_vram_object_freesimply calls a TTM functionttm_bo_put.
Given the findings above, I have several questions:
- What is the actual relationship between GEM and TTM? Is GEM dependent on TTM to do the memory management works?
- If the GEM can simply call the TTM functions to do the job, why would it "lack compatibility of video RAM"? Couldn't it just call another TTM function to do the difficult parts?
I was not familiar with the driver development and my understanding might be very wrong without the sufficient knowledge of the contexts. I would appreciate it if anyone could correct me and explain how those modules actually work.