Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 17: Data Synchronization


50

100

150

200

250

60 80 100 120 140 160 180 200 220 240 260
nr_requests

congestion_on
congestion_off
nr_requests

Figure 17-9: Thresholds for the number of requests that turn congestion on and off,
respectively. The thresholds are obviously always smaller than the number of requests
that can maximally be queued.

17.11.3 Setting and Clearing the Congested State


The kernel provides two standard functions (declared in<blkdev.h>) to set queues to the congested
state and to clear this state:blk_set_queue_congestedandblk_clear_queue_congested, respectively.
Both obtain thebacking_dev_infofor the queue under consideration and hand over the real work to
set_bdi_congestedorclear_bdi_congested, respectively, inmm/backing-dev.c.

Two data structures are manipulated to change the state. First, the request queue of the block device
must be modified (you are familiar with the associatedrequest_queuedata structure from Chapter 6),
and second, note must be taken of the global congestion array (congestion_wqh).

blk_set_queue_congestedis used to mark a queue as congested. Remarkably, it is invoked at only a
single point in the kernel — byget_request.^5 As discussed in Chapter 6, the purpose ofget_request
is to allocate arequestinstance for a queue or to fetch one from the appropriate cache. This is the
ideal place to check for congestion. If the number ofrequestinstances falls below the threshold,
set_queue_congestedinforms the remaining code that congestion has occurred.

(^5) This is not entirely precise: It is also called fromqueue_request_store. But since this code path is only activated if the system
administrator changes thenr_requestsfield of a request queue via sysfs, I do not bother to discuss this possibility any further.

Free download pdf