From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 22962 invoked from network); 28 Jun 2022 13:50:51 -0000 Received: from tb-ob1.topicbox.com (64.147.108.173) by inbox.vuxu.org with ESMTPUTF8; 28 Jun 2022 13:50:51 -0000 Received: from tb-mx0.topicbox.com (tb-mx0.nyi.icgroup.com [10.90.30.73]) by tb-ob1.topicbox.com (Postfix) with ESMTP id AEE9026AF0 for ; Tue, 28 Jun 2022 09:50:49 -0400 (EDT) (envelope-from bounce.mM6c48d66d6cc15f19fd28066c.r522be890-2105-11eb-b15e-8d699134e1fa@9fans.bounce.topicbox.com) Received: by tb-mx0.topicbox.com (Postfix, from userid 1132) id B70142A41FFC; Tue, 28 Jun 2022 09:50:49 -0400 (EDT) ARC-Authentication-Results: i=2; topicbox.com; arc=pass; dkim=pass (2048-bit rsa key sha256) header.d=gmail.com header.i=@gmail.com header.b=CNHnTlTo header.a=rsa-sha256 header.s=20210112 x-bits=2048; dmarc=pass policy.published-domain-policy=none policy.published-subdomain-policy=quarantine policy.applied-disposition=none policy.evaluated-disposition=none (p=none,sp=quarantine,d=none,d.eval=none) policy.policy-from=p header.from=gmail.com; spf=pass smtp.mailfrom=crossd@gmail.com smtp.helo=mail-oa1-f51.google.com; x-internal-arc=fail (as.1.topicbox.com=pass, ams.1.topicbox.com=fail (message has been altered)) (Message modified while forwarding at Topicbox) ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d= topicbox.com; h=mime-version:references:in-reply-to:from:date :message-id:subject:to:content-type:list-help:list-id:list-post :list-subscribe:reply-to:content-transfer-encoding :list-unsubscribe; s=sysmsg-1; t=1656424249; bh=0gtLd6JGpC9hPA2i 6FS1SdHZTtvPXzWKIcxwHSEp0VQ=; b=coNNrdTq/FSFwfdIY3khbI7j9kYeYKN/ szvJf8vDfNsYE50lGrL5MaAgjYGo/s1E/3G7M6PauzUZdal3LD7vfEoG3AX41SRx kr5u9wpECupuloX7GrqpycauSY1956ycNT90oo6q26a+nJH71gdgM+UQshklpMOE puFZ8Lf5s7g= ARC-Seal: i=2; a=rsa-sha256; cv=pass; d=topicbox.com; s=sysmsg-1; t= 1656424249; b=o1XrQp0+4DuUBoq7nyrjuROITIwsYkxLW++olKrDOfIxY7GJNM 8k3Clr77vl0Mt7VJwVIXr+5TVJ6iM0pI47dump3ThtD/ETm3Y58k4SCW5b9gSo11 qml55xgUBN83JjXYVPY0e0AD/Q2q7xPfYuGiRLNDmRGHYU7iRnJs6dZc4= Authentication-Results: topicbox.com; arc=pass; dkim=pass (2048-bit rsa key sha256) header.d=gmail.com header.i=@gmail.com header.b=CNHnTlTo header.a=rsa-sha256 header.s=20210112 x-bits=2048; dmarc=pass policy.published-domain-policy=none policy.published-subdomain-policy=quarantine policy.applied-disposition=none policy.evaluated-disposition=none (p=none,sp=quarantine,d=none,d.eval=none) policy.policy-from=p header.from=gmail.com; spf=pass smtp.mailfrom=crossd@gmail.com smtp.helo=mail-oa1-f51.google.com; x-internal-arc=fail (as.1.topicbox.com=pass, ams.1.topicbox.com=fail (message has been altered)) (Message modified while forwarding at Topicbox) X-Received-Authentication-Results: tb-mx0.topicbox.com; arc=none (no signatures found); bimi=skipped (DMARC Policy is not at enforcement); dkim=pass (2048-bit rsa key sha256) header.d=gmail.com header.i=@gmail.com header.b=CNHnTlTo header.a=rsa-sha256 header.s=20210112 x-bits=2048; dmarc=pass policy.published-domain-policy=none policy.published-subdomain-policy=quarantine policy.applied-disposition=none policy.evaluated-disposition=none (p=none,sp=quarantine,d=none,d.eval=none) policy.policy-from=p header.from=gmail.com; iprev=pass smtp.remote-ip=209.85.160.51 (mail-oa1-f51.google.com); spf=pass smtp.mailfrom=crossd@gmail.com smtp.helo=mail-oa1-f51.google.com; x-aligned-from=pass (Address match); x-google-dkim=pass (2048-bit rsa key) header.d=1e100.net header.i=@1e100.net header.b=IDj5Qdn4; x-me-sender=none; x-ptr=pass smtp.helo=mail-oa1-f51.google.com policy.ptr=mail-oa1-f51.google.com; x-return-mx=pass header.domain=gmail.com policy.is_org=yes (MX Records found: alt4.gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com,alt1.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,gmail-smtp-in.l.google.com); x-return-mx=pass smtp.domain=gmail.com policy.is_org=yes (MX Records found: alt4.gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com,alt1.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,gmail-smtp-in.l.google.com); x-tls=pass smtp.version=TLSv1.2 smtp.cipher=ECDHE-RSA-AES256-GCM-SHA384 smtp.bits=256/256; x-vs=clean score=0 state=0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=9fans.net; h= mime-version:references:in-reply-to:from:date:message-id:subject :to:content-type:list-help:list-id:list-post:list-subscribe :reply-to:content-transfer-encoding:list-unsubscribe; s=dkim-1; t=1656424249; x=1656510649; bh=eW1Eyndna9PkQdLrcopLYnyaqmBGx1+m u4sbrRe8olE=; b=ErUupPyMkuCF0ynsXNU9NRuSmI63bXG3k1Vxg5RpXnjTyCM6 +HnbZ+UEJGupLAo01QDK+ajwEObWcm+v2+TkRMIT+x+7MX2Rxbxlz7xT2FvGlIbC YwmkZm97h6bARGmh/8Jrpr4BG3UGCTxZT2ic1FX137mBddc7+enuopJ571w= Received: from tb-mx0.topicbox.com (localhost.local [127.0.0.1]) by tb-mx0.topicbox.com (Postfix) with ESMTP id 4D11B2A41BE6 for <9fans@9fans.net>; Tue, 28 Jun 2022 09:50:38 -0400 (EDT) (envelope-from crossd@gmail.com) Received: from tb-mx0.topicbox.com (localhost [127.0.0.1]) by tb-mx0.topicbox.com (Authentication Milter) with ESMTP id EE591B21C42; Tue, 28 Jun 2022 09:50:38 -0400 ARC-Seal: i=1; a=rsa-sha256; cv=none; d=topicbox.com; s=arcseal; t= 1656424238; b=EBGPeTxDzZdwmz+Qn1MWDvL2PonAACgirdnriHU4T1MUI+C7LU FEZ4iMzDomvr0aBlglSP91xOTfHDu9v8hnw996tvY5j01mEJ9c9PCRwy1sDcZ4rw U0xFjvEoGtchgu7asrkfh+7tpWyJosIc0IOoo8v7YiBlJJXokdSb3sJ36LD5zDk0 kcGgW1R/xM0QOBuk6MYwVg7Ewm1OpeGrx3OKjiR5sOs9+OUJ4TlE+p0cGvHAbVd0 skaPuLTuvpBHb9XnZzx1VfVPaRw0ylbZlqsJfnARuaoxIJFzWt9kQJYiMWl5rW0i V9caHitB/5ee5QVJA57pU0lIXPwyOntDMPAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= topicbox.com; h=mime-version:references:in-reply-to:from:date :message-id:subject:to:content-type; s=arcseal; t=1656424238; bh=htjckZEvUKraMIzZWBmyDiZTFeg+jayuim/c6bfjgS8=; b=bfP5ObGT2oZB Bv7rHL6TfXXqbLDCvE5Cg1Spk0nmu4VtV7jvZecLGxhXLbGWjclTeAhtw3MHfErF HhA7ivD+jAmqAQgAvPZ6ZLt2W6RLMkrpjnORr60LzJklbmMF0Asvuy9eu+ZCat29 5KrZJJA5RV4j+IsvEx7Ro3ni8/E0nO5fRVFoyhvI/IX1N2l6hIRHan1HiTgzGwV4 LObrhXZK5GSP+kupxbEKYQNQd+iswFRGR9h6ZT1ao//XZmU4tQDNCqUM7OZaZWtA avnG9tqqUaLQU7WaR8E6YkGwDwmfLZrzOFJgtG9IG83A0eauDkvVqz3VUtkUBG73 HXps306rog== ARC-Authentication-Results: i=1; tb-mx0.topicbox.com; arc=none (no signatures found); bimi=skipped (DMARC Policy is not at enforcement); dkim=pass (2048-bit rsa key sha256) header.d=gmail.com header.i=@gmail.com header.b=CNHnTlTo header.a=rsa-sha256 header.s=20210112 x-bits=2048; dmarc=pass policy.published-domain-policy=none policy.published-subdomain-policy=quarantine policy.applied-disposition=none policy.evaluated-disposition=none (p=none,sp=quarantine,d=none,d.eval=none) policy.policy-from=p header.from=gmail.com; iprev=pass smtp.remote-ip=209.85.160.51 (mail-oa1-f51.google.com); spf=pass smtp.mailfrom=crossd@gmail.com smtp.helo=mail-oa1-f51.google.com; x-aligned-from=pass (Address match); x-google-dkim=pass (2048-bit rsa key) header.d=1e100.net header.i=@1e100.net header.b=IDj5Qdn4; x-me-sender=none; x-ptr=pass smtp.helo=mail-oa1-f51.google.com policy.ptr=mail-oa1-f51.google.com; x-return-mx=pass header.domain=gmail.com policy.is_org=yes (MX Records found: alt4.gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com,alt1.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,gmail-smtp-in.l.google.com); x-return-mx=pass smtp.domain=gmail.com policy.is_org=yes (MX Records found: alt4.gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com,alt1.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,gmail-smtp-in.l.google.com); x-tls=pass smtp.version=TLSv1.2 smtp.cipher=ECDHE-RSA-AES256-GCM-SHA384 smtp.bits=256/256; x-vs=clean score=0 state=0 X-ME-VSCause: gggruggvucftvghtrhhoucdtuddrgedvfedrudegjedgieekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeggfhgjhf ffkffuvfgtsehttdertddttdejnecuhfhrohhmpeffrghnucevrhhoshhsuceotghrohhs shgusehgmhgrihhlrdgtohhmqeenucggtffrrghtthgvrhhnpeehvddtgffghefgudehie fhvefffeegudeigedvudegveefgfdulefgvddvhfevudenucfkphepvddtledrkeehrddu iedtrdehudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvtd elrdekhedrudeitddrhedupdhhvghlohepmhgrihhlqdhorgduqdhfhedurdhgohhoghhl vgdrtghomhdpmhgrihhlfhhrohhmpeeotghrohhsshgusehgmhgrihhlrdgtohhmqe X-ME-VSScore: 0 X-ME-VSCategory: clean Received-SPF: pass (gmail.com ... _spf.google.com: Sender is authorized to use 'crossd@gmail.com' in 'mfrom' identity (mechanism 'include:_netblocks.google.com' matched)) receiver=tb-mx0.topicbox.com; identity=mailfrom; envelope-from="crossd@gmail.com"; helo=mail-oa1-f51.google.com; client-ip=209.85.160.51 Received: from mail-oa1-f51.google.com (mail-oa1-f51.google.com [209.85.160.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by tb-mx0.topicbox.com (Postfix) with ESMTPS for <9fans@9fans.net>; Tue, 28 Jun 2022 09:50:37 -0400 (EDT) (envelope-from crossd@gmail.com) Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-fb6b4da1dfso17143966fac.4 for <9fans@9fans.net>; Tue, 28 Jun 2022 06:50:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=htjckZEvUKraMIzZWBmyDiZTFeg+jayuim/c6bfjgS8=; b=IDj5Qdn45mqaw/Tyi3SA+ntnQONAaGdQzApXp15rCgfrwLfTtrOeI95lqXNH+by3zu e97MQKKNWqHflz+1vAUZOhJgUgzy4cHip1K965aqqMYuQKJSuhgvmOoT7VrWwRXWw59O ANzxJmIlURNDW8VScDs928r+O4p3osrMiufmQUrlQ+/waIgieWFE8iMX98PEU7dGfsfW vQmxCFk8hOGvffMWMF7UUQ/PknkU+oAa9o8+Pl/sKTAISnkh+6t5qh/kAIZdVQIrdFhJ +Q2ppoPEcIv8ayyh4IewqZPEAiJX766VVFWbpkQaBp0ynJmY3K2gEl00YtQXf1bd848F 4e8w== X-Gm-Message-State: AJIora+8LxrsCh1F8LOy7nnOT76ZD3bcVYNmP22okiKOV9UppuRlLJAm nbdrsGHkybrHJQUOyuL+SHlrGQ8QrLRSD7FaHoorPxKdwXE= X-Google-Smtp-Source: AGRyM1sFGkUaGXTZ7q5B1HeOh86VhvSYZFi2lept7iJeNNZBBkIKpVb6Gm6yjTwLPlHtoxGwZ86EJDhREnLhRhRWRpM= X-Received: by 2002:a05:6870:32d1:b0:101:dc8:f213 with SMTP id r17-20020a05687032d100b001010dc8f213mr10676185oac.49.1656424236674; Tue, 28 Jun 2022 06:50:36 -0700 (PDT) MIME-Version: 1.0 References: <7eea6efa-711a-31dc-031-dc5c2eddce3d@SDF.ORG> <7f0986f-5958-de7-68b6-8cd49f94e191@SDF.ORG> In-Reply-To: <7f0986f-5958-de7-68b6-8cd49f94e191@SDF.ORG> From: Dan Cross Date: Tue, 28 Jun 2022 09:50:00 -0400 Message-ID: Subject: Re: [9fans] Re: _threadmalloc() size>100000000; shouldn't be totalmalloc? To: 9fans <9fans@9fans.net> Content-Type: text/plain; charset=UTF-8 Topicbox-Policy-Reasoning: allow: sender is a member Topicbox-Message-UUID: 4d4d0550-f6e9-11ec-8e02-fec5112362d1 Archived-At: =?UTF-8?B?PGh0dHBzOi8vOWZhbnMudG9waWNib3guY29tL2dyb3Vwcy85?= =?UTF-8?B?ZmFucy9UZTFiZThkYzcyNzM4MjU4ZC1NNmM0OGQ2NmQ2Y2MxNWYxOWZkMjgw?= =?UTF-8?B?NjZjPg==?= List-Help: List-Id: "9fans" <9fans.9fans.net> List-Post: List-Software: Topicbox v0 List-Subscribe: Precedence: list Reply-To: 9fans <9fans@9fans.net> Content-Transfer-Encoding: quoted-printable List-Unsubscribe: , Topicbox-Delivery-ID: 2:9fans:437d30aa-c441-11e9-8a57-d036212d11b0:522be890-2105-11eb-b15e-8d699134e1fa:M6c48d66d6cc15f19fd28066c:1:pM_6Fdo-AnhG_7T6SNcNK_M90IEeXwE1C9qBrNyPqWw On Tue, Jun 28, 2022 at 9:01 AM adr wrote: > On Sun, 26 Jun 2022, adr wrote: > > [snip] > > /sys/src/libthread/lib.c > > > > [...] > > void* > > _threadmalloc(long size, int z) > > { > > void *m; > > > > m =3D malloc(size); > > if (m =3D=3D nil) > > sysfatal("Malloc of size %ld failed: %r", size); > > setmalloctag(m, getcallerpc(&size)); > > totalmalloc +=3D size; > > if (size > 100000000) { > > fprint(2, "Malloc of size %ld, total %ld\n", size, > > totalmalloc); > > abort(); > > } > > if (z) > > memset(m, 0, size); > > return m; > > } > > [...] > > > > Shouldn't the if statement test the size of totalmalloc before the > > abort? That size, 100M for internal allocations? It has to be > > totalmalloc, doesn't it? If not this if statement should be after > > testing the success of the malloc. Am I missing something? Note that the `if` statement doesn't test the size of *totalmalloc*, but just `size`. `totalsize` is only incidentally printed in the output if `si= ze` exceeds 100 MB: that is, if a single allocation is larger than 100MB. > I mean, I think using libthread more like using small channels and thread= 's stack sizes, but: > > Why put a limit here to size when totalmalloc could continue to grow unti= l malloc fails? > > If we want a limit, why don't we take into account the system resources? > > If we want a constant limit, why don't we put it on threadimpl.h, explain= why this value in a comment > and document it in thread(2)? > > Why bother to call malloc before testing if size exeeds that limit??? Given the name of the function (`_threadmalloc`), I'd guess that this isn't intended for general use, but rather, for the internal consumption of the thread library, where indeed such a large allocation would likely be an error (bear in mind this code was developed on 32-bit machines with RAMs measured in Megabytes, not Gigabytes). As for why the abort is after the allocation? The sad answer, as with so ma= ny things in plan 9, is that there probably isn't a particularly good reason. A possible answer may be that this leaves the process in a state where the allocations= can be inspected in a debugger after the abort, complete with a proper allocation tag. An equally plausible answer is that it's just the way the original author t= yped it in. Please understand that Plan 9 spent most of its life as a research system, and the code and its quality reflects that. - Dan C. ------------------------------------------ 9fans: 9fans Permalink: https://9fans.topicbox.com/groups/9fans/Te1be8dc72738258d-M6c48d= 66d6cc15f19fd28066c Delivery options: https://9fans.topicbox.com/groups/9fans/subscription