From owner-dev-commits-src-branches@freebsd.org Sun Sep 12 16:35:19 2021 Return-Path: Delivered-To: dev-commits-src-branches@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 AEF726694C4; Sun, 12 Sep 2021 16:35:19 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H6wFg4JLmz3nXw; Sun, 12 Sep 2021 16:35:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6A55F1728C; Sun, 12 Sep 2021 16:35:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 18CGZJUS073964; Sun, 12 Sep 2021 16:35:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 18CGZJCc073963; Sun, 12 Sep 2021 16:35:19 GMT (envelope-from git) Date: Sun, 12 Sep 2021 16:35:19 GMT Message-Id: <202109121635.18CGZJCc073963@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: cca384d7e546 - stable/13 - geom_disk: use a preallocated geom_event for disk destruction. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: cca384d7e546c4ff64214d37b4ad042cf726dcf6 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Sep 2021 16:35:19 -0000 The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=cca384d7e546c4ff64214d37b4ad042cf726dcf6 commit cca384d7e546c4ff64214d37b4ad042cf726dcf6 Author: Warner Losh AuthorDate: 2021-07-23 21:21:02 +0000 Commit: Warner Losh CommitDate: 2021-09-12 15:56:14 +0000 geom_disk: use a preallocated geom_event for disk destruction. Preallocate a geom_event (using the new geom_alloc_event) when we create a disk. When we create the disk, we're going to be in a sleepable context, so we can always allocate this extra bit of memory. Then use this preallocated memory to free the disk. CAM can try to free the disk from an unsleepable context if there was I/O outstanding when the disk was destroyted (say because the SIM said it had gone away). The I/O context isn't sleepable. Rather than trying to invent a retry mechanism and making sure all the other geom_disk consumers did it properly, preallocating the event ensure that the geom_disk will be properly torn down, even when there's memory pressure when the disk departs. Reviewd by: jhb Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D30544 (cherry picked from commit 47aeda7b70555049eccd7f020365aec031f41c62) --- sys/geom/geom_disk.c | 5 ++++- sys/geom/geom_disk.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/geom/geom_disk.c b/sys/geom/geom_disk.c index 3ce203c33a73..2f0e72fad52d 100644 --- a/sys/geom/geom_disk.c +++ b/sys/geom/geom_disk.c @@ -885,6 +885,7 @@ disk_create(struct disk *dp, int version) dp->d_sectorsize, DEVSTAT_ALL_SUPPORTED, DEVSTAT_TYPE_DIRECT, DEVSTAT_PRIORITY_MAX); dp->d_geom = NULL; + dp->d_event = g_alloc_event(M_WAITOK); dp->d_init_level = DISK_INIT_NONE; @@ -896,12 +897,14 @@ void disk_destroy(struct disk *dp) { + KASSERT(dp->d_event != NULL, + ("Disk destroy for %p with event NULL", dp)); disk_gone(dp); dp->d_destroyed = 1; g_cancel_event(dp); if (dp->d_devstat != NULL) devstat_remove_entry(dp->d_devstat); - g_post_event(g_disk_destroy, dp, M_WAITOK, NULL); + g_post_event_ep(g_disk_destroy, dp, dp->d_event, NULL); } void diff --git a/sys/geom/geom_disk.h b/sys/geom/geom_disk.h index 8e2282a09a3a..7dd6e34c9ae2 100644 --- a/sys/geom/geom_disk.h +++ b/sys/geom/geom_disk.h @@ -125,6 +125,7 @@ struct disk { /* Fields private to geom_disk, to be moved on next version bump */ LIST_HEAD(,disk_alias) d_aliases; + void *d_event; }; #define DISKFLAG_RESERVED 0x0001 /* Was NEEDSGIANT */