From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id BF8601F47D; Wed, 1 Mar 2023 23:12:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yhbt.net; s=selector1; t=1677712325; bh=2VNY9m+vunv2ufxffT1ZbN121CfY13JCPmMx1iIKeUI=; h=Date:From:To:Subject:References:In-Reply-To:From; b=kNM3JuJzWXqhue2jpG7ObW51+T9i0hibC7GUjcujBrpOWNmCrslaqg12fAUrkL6Qy dcTL9kVLUqMagHUoLNmJfUtGQQ08ysWlEdLjGlwN/BcTePux7LkFDR00v9zGHF0Pml 4SaF5epPOWNZZZkyzc+RrPEH8L0OK6O+tcwn/238= Date: Wed, 1 Mar 2023 23:12:05 +0000 From: Eric Wong To: unicorn-public@yhbt.net Subject: Re: [PATCH] epollexclusive: avoid Ruby object allocation for buffer Message-ID: <20230301231205.M669849@dcvr> References: <20230215075813.1732969-1-bofh@yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230215075813.1732969-1-bofh@yhbt.net> List-Id: Eric Wong wrote: > Leaving a dangling Ruby object around is suboptimal since it > adds to GC pressure. > > `__attribute__((__cleanup__(foo)))' is an old gcc extension to > provide automatic cleanup functionality by running a pre-declared > function at the end of scope. Unfortunately, this can't be usable due to exceptions. Even if we avoid throwing exceptions ourselves; Thread#raise can be called by a Rack app which spawns a background thread > n = (long)rb_thread_call_without_gvl(do_wait, &epw, RUBY_UBF_IO, NULL); Thread#raise can hit rb_thread_call_wihtout_gvl > - if (n < 0) { > - if (errno != EINTR) rb_sys_fail("epoll_wait"); > - n = 0; > - } > + if (n < 0 && errno != EINTR) rb_sys_fail("epoll_wait"); > /* Linux delivers events in order received */ > for (i = 0; i < n; i++) { > struct epoll_event *ev = &epw.events[i]; > @@ -109,7 +113,6 @@ get_readers(VALUE epio, VALUE ready, VALUE readers, VALUE timeout_msec) > if (RTEST(obj)) > rb_ary_push(ready, obj); > } While the `for' loop can be moved ahead of the rb_sys_fail call and limited in scope, Thread#raise can't be predicted. I suppose rb_ensure works, but that's a PITA.