From owner-svn-src-head@freebsd.org Thu Nov 12 20:20:57 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id ECBB7463FA2; Thu, 12 Nov 2020 20:20:57 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CXCfK6PZxz4jNw; Thu, 12 Nov 2020 20:20:57 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CF0A543F2; Thu, 12 Nov 2020 20:20:57 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0ACKKvCp090943; Thu, 12 Nov 2020 20:20:57 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0ACKKvFa090942; Thu, 12 Nov 2020 20:20:57 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202011122020.0ACKKvFa090942@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Thu, 12 Nov 2020 20:20:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367626 - head/sys/geom/bde X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/geom/bde X-SVN-Commit-Revision: 367626 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Nov 2020 20:20:58 -0000 Author: mjg Date: Thu Nov 12 20:20:57 2020 New Revision: 367626 URL: https://svnweb.freebsd.org/changeset/base/367626 Log: gbde: replace malloc_last_fail with a kludge This facilitates removal of malloc_last_fail without really impacting anything. Modified: head/sys/geom/bde/g_bde_work.c Modified: head/sys/geom/bde/g_bde_work.c ============================================================================== --- head/sys/geom/bde/g_bde_work.c Thu Nov 12 20:20:43 2020 (r367625) +++ head/sys/geom/bde/g_bde_work.c Thu Nov 12 20:20:57 2020 (r367626) @@ -77,6 +77,20 @@ #include #include +/* + * FIXME: This used to call malloc_last_fail which in practice was almost + * guaranteed to return time_uptime even in face of severe memory shortage. + * As GBDE is the only consumer the kludge below was added to facilitate the + * removal with minimial changes. The code should be fixed to respond to memory + * pressure (e.g., by using lowmem eventhandler) instead. + */ +static int +g_bde_malloc_last_fail(void) +{ + + return (time_uptime); +} + static void g_bde_delete_sector(struct g_bde_softc *wp, struct g_bde_sector *sp); static struct g_bde_sector * g_bde_new_sector(struct g_bde_work *wp, u_int len); static void g_bde_release_keysector(struct g_bde_work *wp); @@ -210,7 +224,7 @@ g_bde_get_keysector(struct g_bde_work *wp) g_trace(G_T_TOPOLOGY, "g_bde_get_keysector(%p, %jd)", wp, (intmax_t)offset); sc = wp->softc; - if (malloc_last_fail() < g_bde_ncache) + if (g_bde_malloc_last_fail() < g_bde_ncache) g_bde_purge_sector(sc, -1); sp = TAILQ_FIRST(&sc->freelist); @@ -228,7 +242,7 @@ g_bde_get_keysector(struct g_bde_work *wp) if (sp->ref == 1) sp->owner = wp; } else { - if (malloc_last_fail() < g_bde_ncache) { + if (g_bde_malloc_last_fail() < g_bde_ncache) { TAILQ_FOREACH(sp, &sc->freelist, list) if (sp->ref == 0) break; @@ -311,7 +325,7 @@ g_bde_purge_sector(struct g_bde_softc *sc, int fractio if (fraction > 0) n = sc->ncache / fraction + 1; else - n = g_bde_ncache - malloc_last_fail(); + n = g_bde_ncache - g_bde_malloc_last_fail(); if (n < 0) return; if (n > sc->ncache)