Linux documents the default buffer size for tcp, but not for AF_UNIX ("local") sockets. The value can be read (or written) at runtime.

cat /proc/sys/net/core/[rw]mem_default

Is this value always set the same across different Linux kernels, or is there a range of possible values it could be?

1 Answer 1


The default is not configurable, but it is different between 32-bit and 64-bit Linux. The value appears to written so as to allow 256 packets of 256 bytes each, accounting for the different per-packet overhead (structs with 32-bit v.s. 64-bit pointers or integers).

On 64-bit Linux 4.14.18: 212992 bytes

On 32-bit Linux 4.4.92: 163840 bytes

The default buffer sizes are the same for both the read and write buffers. The per-packet overhead is a combination of struct sk_buff and struct skb_shared_info, so it depends on the exact size of these structures (rounded up slightly for alignment). E.g. in the 64-bit kernel above, the overhead is 576 bytes per packet.


/* Take into consideration the size of the struct sk_buff overhead in the
 * determination of these values, since that is non-constant across
 * platforms.  This makes socket queueing behavior and performance
 * not depend upon such differences.
#define _SK_MEM_PACKETS     256

/* Run time adjustable parameters. */
__u32 sysctl_wmem_max __read_mostly = SK_WMEM_MAX;
__u32 sysctl_rmem_max __read_mostly = SK_RMEM_MAX;
__u32 sysctl_wmem_default __read_mostly = SK_WMEM_MAX;
__u32 sysctl_rmem_default __read_mostly = SK_RMEM_MAX;

Interestingly, if you set a non-default socket buffer size, Linux doubles it to provide for the overheads. This means that if you send smaller packets (e.g. less than the 576 bytes above), you won't be able to fit as many bytes of user data in the buffer, as you had specified for its size.

  • Does the per-packet overhead also apply to individual send calls on a UNIX domain socket of type SOCK_STREAM?
    – Armali
    Commented Jan 10, 2020 at 8:54
  • @Armali Good point. I don't know.
    – sourcejedi
    Commented Jan 10, 2020 at 9:36
  • Thanks - I hoped you could save me from studying the kernel source myself. ;-)
    – Armali
    Commented Jan 10, 2020 at 9:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .