From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Opportunistic garbage collection Date: Thu, 25 Apr 2019 14:18:03 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="136053"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Paul Eggert Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Apr 25 20:18:55 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hJixR-000ZGk-R1 for ged-emacs-devel@m.gmane.org; Thu, 25 Apr 2019 20:18:54 +0200 Original-Received: from localhost ([127.0.0.1]:33531 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJixQ-0006fs-RC for ged-emacs-devel@m.gmane.org; Thu, 25 Apr 2019 14:18:52 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:47077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJiwg-0006eG-Io for emacs-devel@gnu.org; Thu, 25 Apr 2019 14:18:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJiwf-0001bD-LG for emacs-devel@gnu.org; Thu, 25 Apr 2019 14:18:06 -0400 Original-Received: from mail01.iro.umontreal.ca ([132.204.25.201]:57804) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hJiwf-0001aB-Ef for emacs-devel@gnu.org; Thu, 25 Apr 2019 14:18:05 -0400 Original-Received: from mail01.iro.umontreal.ca (mail01.iro.umontreal.ca [127.0.0.1]) by mail01.iro.umontreal.ca (Postfix) with ESMTP id BCAB286EB413 for ; Thu, 25 Apr 2019 14:18:04 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; h=content-type:content-type:mime-version:user-agent:in-reply-to :date:date:references:message-id:subject:subject:to:from:from; s=dkim; t=1556216284; x=1557080285; bh=t/X4NumcpdM0wNLZQOfzYRnK uDy77YZIjGBjpoTwIPU=; b=KVKpQPcr+2bLNBeP6Vpio+a+1EZWTDzwaCaXMocF tCw7uQzPCNknRpubNEjw4RDk/cJlNLsVmswlAYqQnbpkd1gw6hh7lmaowYjU6nL5 p4ipfVFljzFSwfsfINMwp4FIEY9GMLagxBythVZCTAsy0jkojOYHFlJwbteUN1BW SSCR4jOajxDCQGPmPtEdq5nNtcujFFA0NpqNomm3BzpMzXTfT80Rkubqree32ETx qK5yCIk3XGUBpB42fV32nbEFJ5oVezdEVed12lW55tZ1nbeWT5c9VNnjXl+tg47w gkveHAGofAn17t4HljlnbydGAZJkBgly0jA+Ez/4Wb0uNg== X-Virus-Scanned: amavisd-new at iro.umontreal.ca Original-Received: from mail01.iro.umontreal.ca ([127.0.0.1]) by mail01.iro.umontreal.ca (mail01.iro.umontreal.ca [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HvW3cwNjaCaC for ; Thu, 25 Apr 2019 14:18:04 -0400 (EDT) Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPS id 8122186EB405; Thu, 25 Apr 2019 14:18:03 -0400 (EDT) In-Reply-To: (Paul Eggert's message of "Wed, 24 Apr 2019 17:17:45 -0700") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 132.204.25.201 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:235932 Archived-At: >> +needed to triger automatic allocation took place. */) > triger -> trigger Thanks. >> + byte_ct new_csgc = consing_since_gc * fact; >> + if (new_csgc / fact != consing_since_gc) >> + /* Overflow! */ >> + garbage_collect (); > > This assumes byte_ct is not narrower than EMACS_INT, which isn't true on > 32-bit platforms --with-wide-int. Does it? My understanding is that if byte_ct is narrower what happens is: 1- consing_since_gc is widened to EMACS_INT, preserving the mathematical value. 2- multiplication with `fact`. 3- narrowing the result to byte_ct which will perform the equivalent of a "modulo 2^N". So new_csgc should be mathematically equal to (consing_since_gc * fact) mod 2^N 4- widen new_csgs to an EMACS_INT, again without any loss 5- divide by `fact` the result can't be larger than new_csgs. 6- widen consing_since_gc to EMACS_INT 7- compare So in the end, I believe that we compare truncation((consing_since_gc * fact) mod 2^N) / fact with consing_since_gc so I believe that the inequality test is a reliable way to detect overflow. What am I missing? > It also assumes 'fact' is nonzero, Indeed, I should probably add a check for it. > which might not be true. (Two more reasons to hardwire 2.) > >> + consing_since_gc = new_csgc; >> + maybe_gc (); >> + consing_since_gc /= fact; >> > I'd feel better if we didn't muck with the global variable and passed > the smaller consing value directly to a variant of maybe_gc. Agreed. Stefan