Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Jan 2022 18:00:19 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 261496] sort -S size documentation is wrong
Message-ID:  <bug-261496-227@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D261496

            Bug ID: 261496
           Summary: sort -S size documentation is wrong
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: wosch@FreeBSD.org

BSD sort has an option to configure the size of the memory buffer:

=C2=A0 =C2=A0 =C2=A0-S size, --buffer-size=3Dsize
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Use size for the maximum si=
ze of the memory buffer. =C2=A0Size
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0modifiers %,b,K,M,G,T,P,E,Z=
,Y can be used. =C2=A0If a memory limit is
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0not explicitly specified, s=
ort takes up to about 90% of available
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0memory. =C2=A0If the file s=
ize is too big to fit into the memory
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0buffer, the temporary disk =
files are used to perform the sorting.

Looking at the source I see no reference to the default 90% except in the
manual page. It appears that sort(1) use by default 50% of main memory, whi=
ch
is more reasonable for a server OS.

$ sysctl hw.physmem
hw.physmem: 68576686080

$ cat /dev/null =C2=A0| sort --debug
Memory to be used for sorting: 34288343040

$ expr 34288343040 \* 2
68576686080

the 50% is apparently from =C2=A0free_memory / 2;
sort.c: available_free_memory =3D free_memory / 2;

However, this is not right for percentage modifiers.

$ cat /dev/null =C2=A0| sort -S 100% --debug
Memory to be used for sorting: 34288343040

so, 100% use only 32GB (50%) of main memory, and=20

cat /dev/null =C2=A0| sort -S 20% --debug=20
Memory to be used for sorting: 6857668608
use only 6.5GB (10%) of main memory.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-261496-227>