I am trying my hand with Linux, just come across the concept of module stacking. It can be used to use symbol exported by other Modules. Means we can use something already made in some module so we do not have to do something that is already done. But still I am not getting where in real-time we see this type of concept with Linux.

I am following the same link from the o'reilly book - http://www.makelinux.net/ldd3/chp-2-sect-5.shtml

Stacking in the parallel port subsystem is shown in Figure 2-2:

enter image description here

I am not able to understand this figure.

Can you just give SOME REALTIME EXAMPLE APPLICATION where we can use concept of module stacking, which will increase my vision horizon?


Stacking just means that some module calls functions defined in another module. There is an example right on the page you cite. According to the figure, lp is a driver for printers on parallel ports. It makes calls into the generic parallel port driver parport. There are several different kinds of parallel ports, and each has its own low-level driver; the most common one is parport_pc. On current kernels, it's actually parport_pc that calls functions defined in parport, and not the opposite as the figure suggests. Of course, all of them make calls to basic kernel features (which aren't in modules).

There are a lot of similar cases. For example most storage (disk) drivers communicate with (a variant of) the SCSI protocol, so they make calls into the generic scsi_mod module. The usb_storage module makes calls into both sci_mod (for the storage aspects) and usbcore (for the USB aspects).

You can see the dependencies for all the modules you have installed (i.e. what modules call functions from what other modules) in /lib/modules/*/modules.dep (there'll be a lot of them). You can see the dependencies for modules that are currently loaded with lsmod; for example the following output line shows that parport_pc, ppdev and lp all depend on parport:

parport                27954  3 parport_pc,ppdev,lp

Here's a small script that generates a dependency graph for the modules you have loaded. You need to have graphviz (available in most distributions).

lsmod | awk '
    BEGIN {print "digraph modules {"}
    END {print "}"}
    NR != 1 {split($4, a, ","); for (i in a) print a[i], "->", $1;}
' | dot -Tpdf >lsmod.pdf
  • you have metioned about an script, what scripting language is it ? please suggest. – user6363 Apr 8 '11 at 7:36
  • @user6363 It's a shell script, most of it (the part between '…') being obviously an awk script. – Gilles 'SO- stop being evil' Apr 8 '11 at 19:19

There is usually a set of functionalities related to any physical device that interacts with a computer. For example, disk drives-related functionalities include file systems, encryption, redundancy, and others. One of the ways to organize and provide various functionalities is stacking.

This is a general map of Linux kernel, where you can notice "stacks"/"functions" (along vertical direction) and "layers" (along horizontal direction):

enter image description here

This is a little bit more detailed version of the previous diagram:

enter image description here

Following are examples of device driver stacks in Linux:

I/O stack


enter image description here

and in more details:

enter image description here

Graphics stack

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.