Changeset View
Changeset View
Standalone View
Standalone View
sys/geom/geom_io.c
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
#include <vm/vm_map.h> | #include <vm/vm_map.h> | ||||
static int g_io_transient_map_bio(struct bio *bp); | static int g_io_transient_map_bio(struct bio *bp); | ||||
static struct g_bioq g_bio_run_down; | static struct g_bioq g_bio_run_down; | ||||
static struct g_bioq g_bio_run_up; | static struct g_bioq g_bio_run_up; | ||||
static struct g_bioq g_bio_run_task; | static struct g_bioq g_bio_run_task; | ||||
static u_int pace; | /* | ||||
* Pace is a hint that we've had some trouble recently allocating | |||||
* bios, so we should back off trying to send I/O down the stack | |||||
* a bit to let the problem resolve. When pacing, we also turn | |||||
* off direct dispatch to also reduce memory pressure from I/Os | |||||
* there, at the expxense of some added latency while the memory | |||||
* pressures exist. See g_io_schedule_down() for more details | |||||
* and limitations. | |||||
*/ | |||||
static volatile u_int pace; | |||||
static uma_zone_t biozone; | static uma_zone_t biozone; | ||||
/* | /* | ||||
* The head of the list of classifiers used in g_io_request. | * The head of the list of classifiers used in g_io_request. | ||||
* Use g_register_classifier() and g_unregister_classifier() | * Use g_register_classifier() and g_unregister_classifier() | ||||
* to add/remove entries to the list. | * to add/remove entries to the list. | ||||
* Classifiers are invoked in registration order. | * Classifiers are invoked in registration order. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 433 Lines • ▼ Show 20 Lines | #endif | ||||
else | else | ||||
getbinuptime(&bp->bio_t0); | getbinuptime(&bp->bio_t0); | ||||
#ifdef GET_STACK_USAGE | #ifdef GET_STACK_USAGE | ||||
direct = (cp->flags & G_CF_DIRECT_SEND) != 0 && | direct = (cp->flags & G_CF_DIRECT_SEND) != 0 && | ||||
(pp->flags & G_PF_DIRECT_RECEIVE) != 0 && | (pp->flags & G_PF_DIRECT_RECEIVE) != 0 && | ||||
!g_is_geom_thread(curthread) && | !g_is_geom_thread(curthread) && | ||||
((pp->flags & G_PF_ACCEPT_UNMAPPED) != 0 || | ((pp->flags & G_PF_ACCEPT_UNMAPPED) != 0 || | ||||
(bp->bio_flags & BIO_UNMAPPED) == 0 || THREAD_CAN_SLEEP()); | (bp->bio_flags & BIO_UNMAPPED) == 0 || THREAD_CAN_SLEEP()) && | ||||
pace == 0; | |||||
kib: There is no sense in using _acq there, and corresponding _rel in other place. You do not need… | |||||
if (direct) { | if (direct) { | ||||
/* Block direct execution if less then half of stack left. */ | /* Block direct execution if less then half of stack left. */ | ||||
size_t st, su; | size_t st, su; | ||||
GET_STACK_USAGE(st, su); | GET_STACK_USAGE(st, su); | ||||
if (su * 2 > st) | if (su * 2 > st) | ||||
direct = 0; | direct = 0; | ||||
} | } | ||||
#else | #else | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | #endif | ||||
if (bootverbose) | if (bootverbose) | ||||
printf("ENOMEM %p on %p(%s)\n", bp, pp, pp->name); | printf("ENOMEM %p on %p(%s)\n", bp, pp, pp->name); | ||||
bp->bio_children = 0; | bp->bio_children = 0; | ||||
bp->bio_inbed = 0; | bp->bio_inbed = 0; | ||||
bp->bio_driver1 = NULL; | bp->bio_driver1 = NULL; | ||||
bp->bio_driver2 = NULL; | bp->bio_driver2 = NULL; | ||||
bp->bio_pflags = 0; | bp->bio_pflags = 0; | ||||
g_io_request(bp, cp); | g_io_request(bp, cp); | ||||
pace++; | pace = 1; | ||||
Not Done Inline ActionsAtomic_set() does not what you probably want it to do. Simple assignment is guaranteed to be atomic on all arches supported by FreeBSD (i.e. readers are guaranteed to read either previous, or the written value from the assigned location). kib: Atomic_set() does not what you probably want it to do. Simple assignment is guaranteed to be… | |||||
return; | return; | ||||
} | } | ||||
SYSCTL_DECL(_kern_geom); | SYSCTL_DECL(_kern_geom); | ||||
static long transient_maps; | static long transient_maps; | ||||
SYSCTL_LONG(_kern_geom, OID_AUTO, transient_maps, CTLFLAG_RD, | SYSCTL_LONG(_kern_geom, OID_AUTO, transient_maps, CTLFLAG_RD, | ||||
&transient_maps, 0, | &transient_maps, 0, | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | for(;;) { | ||||
if (bp == NULL) { | if (bp == NULL) { | ||||
CTR0(KTR_GEOM, "g_down going to sleep"); | CTR0(KTR_GEOM, "g_down going to sleep"); | ||||
msleep(&g_wait_down, &g_bio_run_down.bio_queue_lock, | msleep(&g_wait_down, &g_bio_run_down.bio_queue_lock, | ||||
PRIBIO | PDROP, "-", 0); | PRIBIO | PDROP, "-", 0); | ||||
continue; | continue; | ||||
} | } | ||||
CTR0(KTR_GEOM, "g_down has work to do"); | CTR0(KTR_GEOM, "g_down has work to do"); | ||||
g_bioq_unlock(&g_bio_run_down); | g_bioq_unlock(&g_bio_run_down); | ||||
if (pace > 0) { | if (pace != 0) { | ||||
CTR1(KTR_GEOM, "g_down pacing self (pace %d)", pace); | /* | ||||
Not Done Inline Actionss/have/has/ emaste: s/have/has/ | |||||
Not Done Inline ActionsNote that this is indeed racy, by allowing stores of '1' to be ignored. kib: Note that this is indeed racy, by allowing stores of '1' to be ignored. | |||||
pause("g_down", hz/10); | * There has been at least one memory allocation | ||||
pace--; | * failure since the last I/O completed. Pause 1ms to | ||||
* give the system a chance to free up memory. We only | |||||
* do this once because a large number of allocations | |||||
* can fail in the direct dispatch case and there's no | |||||
* relationship between the number of these failures and | |||||
* the length of the outage. If there's still an outage, | |||||
* we'll pause again and again until it's | |||||
* resolved. Older versions paused longer and once per | |||||
* allocation failure. This was OK for a single threaded | |||||
* g_down, but with direct dispatch would lead to max of | |||||
* 10 IOPs for minutes at a time when transient memory | |||||
* issues prevented allocation for a batch of requests | |||||
* from the upper layers. | |||||
* | |||||
Not Done Inline Actionssolved emaste: solved | |||||
* XXX This pacing is really lame. It needs to be solved | |||||
* by other methods. This is OK, but in the worst case | |||||
* scenario all memory is tied up waiting for I/O to | |||||
* complete which can never happen since we can't | |||||
* allocate bios for that I/O. | |||||
*/ | |||||
CTR0(KTR_GEOM, "g_down pacing self"); | |||||
pause("g_down", min(hz/1000, 1)); | |||||
pace = 0; | |||||
} | } | ||||
CTR2(KTR_GEOM, "g_down processing bp %p provider %s", bp, | CTR2(KTR_GEOM, "g_down processing bp %p provider %s", bp, | ||||
bp->bio_to->name); | bp->bio_to->name); | ||||
error = g_io_check(bp); | error = g_io_check(bp); | ||||
if (error >= 0) { | if (error >= 0) { | ||||
CTR3(KTR_GEOM, "g_down g_io_check on bp %p provider " | CTR3(KTR_GEOM, "g_down g_io_check on bp %p provider " | ||||
"%s returned %d", bp, bp->bio_to->name, error); | "%s returned %d", bp, bp->bio_to->name, error); | ||||
g_io_deliver(bp, error); | g_io_deliver(bp, error); | ||||
▲ Show 20 Lines • Show All 172 Lines • Show Last 20 Lines |
There is no sense in using _acq there, and corresponding _rel in other place. You do not need any happens-before relations for code after acq/before rel.