On Sun, 26 Jun 2022, adr wrote:

Date: Sun, 26 Jun 2022 09:50:19 +0000 (UTC)
From: adr <a...@sdf.org>
To: 9fans@9fans.net
Subject: _threadmalloc() size>100000000; shouldn't be totalmalloc?

/sys/src/libthread/lib.c

[...]
void*
_threadmalloc(long size, int z)
{
      void *m;

      m = malloc(size);
      if (m == nil)
              sysfatal("Malloc of size %ld failed: %r", size);
      setmalloctag(m, getcallerpc(&size));
      totalmalloc += 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?

adr.


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 until 
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???

adr

------------------------------------------
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Te1be8dc72738258d-Mf7cdc7010affd696392c0b47
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

Reply via email to