From owner-svn-src-head@freebsd.org Tue Nov 17 03:15:15 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 143FD47DBD7; Tue, 17 Nov 2020 03:15:15 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CZrfV745bz3JsH; Tue, 17 Nov 2020 03:15:14 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-wr1-x443.google.com with SMTP id j7so21627355wrp.3; Mon, 16 Nov 2020 19:15:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=fwnA28FacBsEwmca48e1CIxnICN/NvXjHaN4FR6U1zI=; b=Jj2Q/gXFpeHHLuvqNxKqN5+Q2WHqH5DVb3J+W8dEyeWzkurgVKEB8vtBXCd/R8Biv8 thHyWhNwh5mJ7wtM9lL6k1y/5ZgrjMAB7DJl6nkK4wUxGLYj/xpIUwr9fLXFjt9+UnXw gmyIswnezdltD3Vl9pV5QQNO71Aj6iuuL7g4Dy/BwiMhNam85Q8otw0UwmGVUipGQG1j B6bWSM9YoxlBDxuDMxA8HreJZovmJ/oMDUqPIjj2OqTfJPinqD51k+LYZYH7n8tMIin9 eRUxQrL6CfU6/IB8aHJj6fB95iBTsz1pCNzfoc7e852qqzTkhnGVOH7l0kIJYrzuNCV6 V3FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=fwnA28FacBsEwmca48e1CIxnICN/NvXjHaN4FR6U1zI=; b=rc5VjQ1BYht+RYF+zbBQwDE0U4XMohHMPqTSI3u9VgPkhjQu/j3x5iMgqbPOFcdKb6 E35e/ufqVFCAP33fD3Wu0f6anG979pE22je360/7uWlFcS+U/SE0D4REIzEMj2A92gCq H4JKAQEZcV1gojM7cm0b3jZglekYG2aNEJC4VZdgAdn3uS1bu1XyAmV99lkVMnqdQI/H qfhtcxeRb94qAnNE/IQCC0FSlHKpsk9C8LiGJwBxa6TRpMgq4AaJE4rlDlOnkKsx6dgb LH8/MWmlwD2u7IY5ETiL/UxGc8QbRqOxp2AHT+MSg8fwISpX+nA3cSfAepfP7DdQf2pe oYOw== X-Gm-Message-State: AOAM530zpDYDgBGK8G9F51HQM42czGKRRNamsenPAgEZfwz9Kk1exe4o fmanCJZmwW541BP9RODPwumGe+WJar/1lFxHmZL3QvYifkc= X-Google-Smtp-Source: ABdhPJyhnA1TVVpdA35ClSiY14RQ4R2WpFEkOzwuda/T+PikAcm3ph6Fy9H0O/s5StMSjANOJz9mZMQlcJYRW89JAcs= X-Received: by 2002:adf:9b98:: with SMTP id d24mr22266698wrc.17.1605582913402; Mon, 16 Nov 2020 19:15:13 -0800 (PST) MIME-Version: 1.0 Received: by 2002:adf:dec7:0:0:0:0:0 with HTTP; Mon, 16 Nov 2020 19:15:12 -0800 (PST) In-Reply-To: References: <202011160309.0AG39JmP067464@repo.freebsd.org> From: Mateusz Guzik Date: Tue, 17 Nov 2020 04:15:12 +0100 Message-ID: Subject: Re: svn commit: r367713 - head/sys/kern To: Konstantin Belousov Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 4CZrfV745bz3JsH X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] 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: Tue, 17 Nov 2020 03:15:15 -0000 On 11/17/20, Konstantin Belousov wrote: > On Mon, Nov 16, 2020 at 03:09:19AM +0000, Mateusz Guzik wrote: >> Author: mjg >> Date: Mon Nov 16 03:09:18 2020 >> New Revision: 367713 >> URL: https://svnweb.freebsd.org/changeset/base/367713 >> >> Log: >> select: replace reference counting with memory barriers in selfd >> >> Refcounting was added to combat a race between selfdfree and >> doselwakup, >> but it adds avoidable overhead. >> >> selfdfree detects it can free the object by ->sf_si == NULL, thus we >> can >> ensure that the condition only holds after all accesses are completed. >> >> Modified: >> head/sys/kern/sys_generic.c >> >> Modified: head/sys/kern/sys_generic.c >> ============================================================================== >> --- head/sys/kern/sys_generic.c Sun Nov 15 22:49:28 2020 (r367712) >> +++ head/sys/kern/sys_generic.c Mon Nov 16 03:09:18 2020 (r367713) >> @@ -156,7 +156,6 @@ struct selfd { >> struct mtx *sf_mtx; /* Pointer to selinfo mtx. */ >> struct seltd *sf_td; /* (k) owning seltd. */ >> void *sf_cookie; /* (k) fd or pollfd. */ >> - u_int sf_refs; >> }; >> >> MALLOC_DEFINE(M_SELFD, "selfd", "selfd"); >> @@ -1704,16 +1703,17 @@ static void >> selfdfree(struct seltd *stp, struct selfd *sfp) >> { >> STAILQ_REMOVE(&stp->st_selq, sfp, selfd, sf_link); >> - if (sfp->sf_si != NULL) { >> + /* >> + * Paired with doselwakeup. >> + */ >> + if (atomic_load_acq_ptr((uintptr_t *)&sfp->sf_si) != (uintptr_t)NULL) { > This could be != 0. > >> mtx_lock(sfp->sf_mtx); >> if (sfp->sf_si != NULL) { >> TAILQ_REMOVE(&sfp->sf_si->si_tdlist, sfp, sf_threads); >> - refcount_release(&sfp->sf_refs); >> } >> mtx_unlock(sfp->sf_mtx); >> } >> - if (refcount_release(&sfp->sf_refs)) >> - free(sfp, M_SELFD); >> + free(sfp, M_SELFD); > What guarantees that doselwakeup() finished with sfp ? > Release semantics provided by atomic_store_rel_ptr -- it means the NULL store is the last access, neither CPU nor the compiler are going to reorder preceding loads/stores past it. -- Mateusz Guzik