Subject: Re: 1.6.2 kernel: ex driver sometimes can't allocate
To: Chapman Flack <flack@cerias.purdue.edu>
From: Manuel Bouyer <bouyer@antioche.eu.org>
List: tech-kern
Date: 09/19/2004 14:16:56
On Sat, Sep 18, 2004 at 07:58:50PM -0500, Chapman Flack wrote:
> Hi,
> 
> My PC-Card NIC (3c575B-TX) always works fine if it is present at boot.
> 
> If I plug it in later, it sometimes works fine, and sometimes fails in
> attach at this line (/sys/dev/ic/elinkxl.c:276):
> 
>         /*
>          * Allocate the download descriptors, and create and load the DMA
>          * map for them.
>          */
>         if ((error = bus_dmamem_alloc(sc->sc_dmat,
>             EX_NDPD * sizeof (struct ex_dpd), PAGE_SIZE, 0, &sc->sc_dseg, 1, 
>             &sc->sc_drseg, BUS_DMA_NOWAIT)) != 0) {
>                 printf("%s: can't allocate download descriptors, error = %d\n",
>                     sc->sc_dev.dv_xname, error);
>                 goto fail;
>         }
> 
> error comes back 12 (ENOMEM?)
> 
> I actually got it to attach last time by popping the card back out and then
> closing a few xterms and mozilla; shoved the card back in and it worked.
> How does *that* work - what resources are userland programs able to starve
> bus_dmamem_alloc of?

This is because of the BUS_DMA_NOWAIT flag passed to bus_dmamem_alloc().
There may be no pages free at this time, and we explicitely tell bus_dma
that we can't wait for some to be available.

> 
> Is there any way I can configure some kind of resource reservation so this
> doesn't happen when I plug this card in after boot?

something like
dd if=/dev/wd0d of=/dev/null bs=10m count=1
before plugin in the card can help. It should cause some pages to be swapped
out to make room for dd's buffers, wich will then be free when dd exit.

> Would it work better if
> I explicitly config ex0 and ex1, instead of clone ex* ?

no, it wouldn't change anything.

-- 
Manuel Bouyer <bouyer@antioche.eu.org>
     NetBSD: 26 ans d'experience feront toujours la difference
--