From b23f72e98ae8164c07be4b3780a0b83e094844cf Mon Sep 17 00:00:00 2001 From: Brian Feldman Date: Mon, 2 Aug 2004 00:18:36 +0000 Subject: * Add a "how" argument to uma_zone constructors and initialization functions so that they know whether the allocation is supposed to be able to sleep or not. * Allow uma_zone constructors and initialation functions to return either success or error. Almost all of the ones in the tree currently return success unconditionally, but mbuf is a notable exception: the packet zone constructor wants to be able to fail if it cannot suballocate an mbuf cluster, and the mbuf allocators want to be able to fail in general in a MAC kernel if the MAC mbuf initializer fails. This fixes the panics people are seeing when they run out of memory for mbuf clusters. * Allow debug.nosleepwithlocks on WITNESS to be disabled, without changing the default. Both bmilekic and jeff have reviewed the changes made to make failable zone allocations work. --- sys/dev/en/midway.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'sys/dev/en') diff --git a/sys/dev/en/midway.c b/sys/dev/en/midway.c index 02096b3082cd0..33108381ec810 100644 --- a/sys/dev/en/midway.c +++ b/sys/dev/en/midway.c @@ -437,25 +437,21 @@ en_dump_packet(struct en_softc *sc, struct mbuf *m) * * LOCK: any, not needed */ -static void -en_map_ctor(void *mem, int size, void *arg) +static int +en_map_ctor(void *mem, int size, void *arg, int flags) { struct en_softc *sc = arg; struct en_map *map = mem; int err; - if (map->sc == NULL) - map->sc = sc; - - if (!(map->flags & ENMAP_ALLOC)) { - err = bus_dmamap_create(sc->txtag, 0, &map->map); - if (err != 0) - if_printf(&sc->ifatm.ifnet, - "cannot create DMA map %d\n", err); - else - map->flags |= ENMAP_ALLOC; + err = bus_dmamap_create(sc->txtag, 0, &map->map); + if (err != 0) { + if_printf(&sc->ifatm.ifnet, "cannot create DMA map %d\n", err); + return (err); } - map->flags &= ~ENMAP_LOADED; + map->flags = ENMAP_ALLOC; + map->sc = sc; + return (0); } /* @@ -490,8 +486,7 @@ en_map_fini(void *mem, int size) { struct en_map *map = mem; - if (map->flags & ENMAP_ALLOC) - bus_dmamap_destroy(map->sc->txtag, map->map); + bus_dmamap_destroy(map->sc->txtag, map->map); } /*********************************************************************/ @@ -1041,11 +1036,9 @@ en_start(struct ifnet *ifp) * locks. */ map = uma_zalloc_arg(sc->map_zone, sc, M_NOWAIT); - if (map == NULL || !(map->flags & ENMAP_ALLOC)) { + if (map == NULL) { /* drop that packet */ EN_COUNT(sc->stats.txnomap); - if (map != NULL) - uma_zfree(sc->map_zone, map); EN_UNLOCK(sc); m_freem(m); continue; @@ -2330,13 +2323,11 @@ en_service(struct en_softc *sc) if (m != NULL) { /* M_NOWAIT - called from interrupt context */ map = uma_zalloc_arg(sc->map_zone, sc, M_NOWAIT); - if (map == NULL || !(map->flags & ENMAP_ALLOC)) { + if (map == NULL) { rx.post_skip += mlen; m_freem(m); DBG(sc, SERV, ("rx%td: out of maps", slot - sc->rxslot)); - if (map->map != NULL) - uma_zfree(sc->map_zone, map); goto skip; } rx.m = m; -- cgit v1.3