How does the Linux DRM GEM work with the TTM in memory management?

252 Views Asked by At

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.

  1. The drm_gem_object_funcs struct is used to store the callbacks for the GEM object, I assume, but the AMD driver implementation (in drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c) set the member variables vmap and vumap to drm_gem_ttm_vmap and drm_gem_ttm_vumap respectively, which seems to imply the GEM object would finally rely on the TTM module to do some of the memory works.

  2. The default callbacks setting in DRM VRAM management (in drivers/gpu/drm/drm_gem_vram_helper.c) set the members of drm_gem_object_funcs to drm_gem_vram_object_xxx including pin, unpin, free and so on. But the mmap is assgined drm_gem_ttm_mmap, another function from the TTM helper module.

  3. The free implementation in GEM, drm_gem_vram_object_free simply calls a TTM function ttm_bo_put.

Given the findings above, I have several questions:

  1. What is the actual relationship between GEM and TTM? Is GEM dependent on TTM to do the memory management works?
  2. 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.

0

There are 0 best solutions below