You are on page 1of 9

scull's Memory Usage

SMP

scull's Memory Usage

The region of memory used by scull, also called a device here, is variable in length. The more you write, the more it grows; trimming is performed by overwriting the device with a shorter file. In scull, each device is a linked list of pointers, each of which points to a Scull_Dev structure. Each such structure can refer, by default, to at most four million bytes, through an array of intermediate pointers. The released source uses an array of 1000 pointers to areas of 4000 bytes

SMP

scull's Memory Usage

We call each memory area a quantum and the array (or its length) a quantum set. A scull device and its memory areas are shown

Scull_Dev

Scull_Dev

SMP

scull's Memory Usage

Choosing the appropriate values for the quantum and the quantum set is a question of policy, rather than mechanism, and the optimal sizes depend on how the device is used. Thus, the scull driver should not force the use of any particular values for the quantum and quantum set sizes.

SMP

scull's Memory Usage


In scull, the user can change the values in charge in several ways:

By changing the macros SCULL_QUANTUM and SCULL_QSET in scull.h at compile time,

By setting the integer values scull_quantum and scull_qset at module load time, or

By changing both the current and default values using ioctl at runtime.

SMP

scull's Memory Usage


The data structure used to hold device information is as follows:
void **data; Struct Scull_Dev *next int quantum; int qset; unsigned long size; unsigned int access_key; struct semaphore sem; }; /* Pointer to first quantum set */ /* next list item */ /* the current quantum size */ /* the current array size */ /* amount of data stored here */ /* used by sculluid and scullpriv */ /* mutual exclusion semaphore */

struct scull_dev {

SMP

scull's Memory Usage

The function scull_trim is in charge of freeing the whole data area and is invoked by scull_open when the file is opened for writing. It simply walks through the list and frees any quantum and quantum set it finds.

SMP

scull's Memory Usage

SMP

scull's Memory Usage

SMP

You might also like