Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 249adc957292d0dbf0a96b7bd75eab875a0b691d
Ticket: 2960042fffffffffffffffffffffffffffffffff
high water mark memory not shared for file I/O needs
User & Date: ferrieux on 2010-03-04 04:27:01
Changes

  1. icomment:
    Still not reproduced, but I think I know what's happening. 
    
    Notice  that there are two fundamentally different kinds of allocations in the Tcl core: Tcl_Obj's and vanilla mallocs. Tcl_Objs are allocated by blocks (with large mallocs), but the block themselves are never free()ed; instead, freed Tcl_Objs are linked in a free list inside their hosting blocks. Vanilla mallocs are used for everything else, like strings or list storage. 
    
    Now this "high water mark" handling of objects doesn't generate actual leaks _within_ the universe of Tcl_Objs, but it competes for available memory with the rest of vanilla mallocs. Hence, if A is a vanilla malloc and B a block of Tcl_Objs and A+B exceed total available heap space, then:
      (1) A and B cannot be simultaneously allocated (obvious)
      (2) alloc(A);free(A);alloc(B);free(B) works
      (3) alloc(B);free(B);alloc(A);free(A) doesn't, simply because free(B) is a no-op as far as the heap is concerned
    
    So here A is large_file, B is hi_water_mark, and I'd predict that with proper sizes you can even observe the failure skipping the first call to large_file.
    
    Hence, your new title is accurate in describing the situation, though we can generalize "I/O needs" to "vanilla mallocs".  However, it is not really a bug; rather it lays in the gray zone of implementation trade-offs.
    
    Indeed, while it could be imagined to free whole blocks of free Tcl_Objs in certain conditions (like after a failure to malloc or realloc), in the general case there is no guarantee that a completely free block exists (a single non-free obj per block spoils the method). A typical scenario generating this pattern is when long-lived objects are created at any time, not just at the beginning.
    
    To summarize, I'd say that a switch from "high-water-mark" to "non-monotonous" method for Tcl_Obj block allocation could improve *some* cases like the one you've shown, but would leave an overwhelming number of similar cases out of reach. 
    
    Hence I'm tempted to freeze this as Won't Fix.
    I'd welcome counter arguments, or different evaluations of the statistics.
    
    
    a big vanilla malloc (like the big string grown by the  first call to [large_file]) can fit once in memory, then (after freeing it) leave space to an irreversible claim by a big block of Tcl_Objs
    
    
  2. login: "ferrieux"
  3. mimetype: "text/plain"
  4. username: "ferrieux"