Unix SORT no respeta su límite de memoria

Unix SORT no respeta su límite de memoria

Me enfrento a un problema relacionado con sortla muerte debido al uso excesivo de la memoria y no puedo entender por qué supera el límite dado por un margen significativo.

Context: 
Available physical RAM: 8GB 
Memory in use by system: <500MB (FreeBSD 13) 
Free memory: ~7.5GB 
Swap: 2G
No system hard limit on mem usage ($ ulimit -> unlimited)
File being sorted: 300+ GB 
HDD space: 1Tb+ free both on target or temporary dir.

Incluso cuando ejecuto sort especificando un límite de recursos dentro de los disponibles; o sin ningún argumento explícito (que debería establecerse automáticamente en el 90% del disponible), eventualmente se elimina debido al uso excesivo.

[mario@casa-server ~/pjy]$ sort -S 7G -T /filesWD-WMAY03648941/tmp/ -o /filesWD-WMAY03648941/pjA-sorted.txt pjyA.txt

Killed
[mario@casa-server ~/pjy]$
[mario@casa-server ~/pjy]$ sort -T /filesWD-WMAY03648941/tmp/ -o /filesWD-WMAY03648941/pjA-sorted.txt pjyA.txt

Killed
[mario@casa-server ~/pjy]$

Aparentemente, se acabó el uso del límite de recursos. Cuando lo ejecuto con -S 3G, a veces puedo observar alrededor de 5G de uso.

# ~5G USAGE EVEN WITH EXPLICIT -S 3G LIMIT


  [mario@casa-server ~]$ sudo procstat -r 3183
  PID COMM             RESOURCE                          VALUE        
 3183 sort             user time                    00:27:51.849171   
 3183 sort             system time                  00:03:28.220262   
 3183 sort             maximum RSS                          5423072 KB
 3183 sort             integral shared memory              10505728 KB
 3183 sort             integral unshared data               1910064 KB
 3183 sort             integral unshared stack             30560128 KB
 3183 sort             page reclaims                        8172561   
 3183 sort             page faults                             1724   
 3183 sort             swaps                                      0   
 3183 sort             block reads                            24296   
 3183 sort             block writes                           17719   
 3183 sort             messages sent                              0   
 3183 sort             messages received                          0   
 3183 sort             signals received                           0   
 3183 sort             voluntary context switches              5868   
 3183 sort             involuntary context switches           30700   
[mario@casa-server ~]$ 


# TOP excerpt
 PID USERNAME    THR PRI NICE   SIZE    RES STATE    C   TIME    WCPU COMMAND
 3183 mario         1 103    0  4657M  4603M CPU3     3  38:23  99.88% sort -S 3G -T /filesWD-WMAY03648941/tmp/ -o /files



# NO SO LIMIT ON USAGE
[mario@casa-server ~]$ sudo procstat -l 3183
  PID COMM             RLIMIT                  SOFT             HARD     
 3183 sort             cputime             infinity         infinity     
 3183 sort             filesize            infinity         infinity     
 3183 sort             datasize               32768 MB         32768 MB  
 3183 sort             stacksize             524288 KB        524288 KB  
 3183 sort             coredumpsize        infinity         infinity     
 3183 sort             memoryuse           infinity         infinity     
 3183 sort             memorylocked           65536 B          65536 B   
 3183 sort             maxprocesses           12186            12186     
 3183 sort             openfiles             234576           234576     
 3183 sort             sbsize              infinity         infinity     
 3183 sort             vmemoryuse          infinity         infinity     
 3183 sort             pseudo-terminals    infinity         infinity     
 3183 sort             swapuse             infinity         infinity     
 3183 sort             kqueues             infinity         infinity     
 3183 sort             umtxp               infinity         infinity     
[mario@casa-server ~]$
[mario@casa-server ~]$ ulimit 
unlimited

Eso explica por qué se elimina cuando se ejecuta con un límite de 7G (de 7,5 disponible), o cuando el límite se establece automáticamente: de hecho, se acabó el uso de todos los mem+swap (y el sistema operativo lo elimina como se esperaba).

¿Pero qué me falta aquí? man sort:

 -S size, --buffer-size=size
         Use size for the maximum size of the memory buffer.  Size
         modifiers %,b,K,M,G,T,P,E,Z,Y can be used.  If a memory limit is
         not explicitly specified, sort takes up to about 90% of available
         memory.  If the file size is too big to fit into the memory
         buffer, the temporary disk files are used to perform the sorting.

Si -S 3Gestá configurado, ¿por qué se termina el uso de RAM y no de la carpeta temporal del HDD?

PD: Intenté hacer esta pregunta relacionada con otros "tipos que se eliminan por falta de memoria", pero algunos moderadores la administraron mal. Creo que es una pregunta relacionada (y marcarla como no relacionada simplemente fragmenta la solución). Además, leí muchas otras soluciones posibles y no son adecuadas para este caso.

Gracias a todos

información relacionada