In my opinion, these are probably fragments in memory. First of all, chunks of memory that are longer than 255 bytes will be allocated using malloc in CPython. You can link to
Improving Python Memory Allocator
For performance reasons, most of the memory allocation, such as malloc, will return an aligned address. For example, you will never get an address, for example
0x00003
It is not aligned by 4 bytes, for a computer it will access memory very slowly. So the whole address you get through malloc should be
0x00000 0x00004 0x00008
etc. Alignment by 4 bytes is only the basic general rule, and the actual alignment policy will be an OS variant.
And the memory usage you are talking about should be RSS (not sure). For most of the OS, the virtual memory page size is 4 KB. For what you allocate, you need 2 pages to store 5000 bytes. Let's see an example to illustrate a memory leak. Assume alignment is 256 bytes.
0x00000 { ... chunk 1 0x01388 } 0x01389 { ... fragment 1 0x013FF } 0x01400 { ... chunk 2 0x02788 } 0x02789 { ... fragment 2 0x027FF } 0x02800 { ... chunk 3 0x03B88 } 0x03B89 { ... fragment 3 0x04000 }
As you can see, there are so many fragments in the memory, they cannot be used, but nevertheless they occupy the memory space on the page. I'm not sure what the FreeBSD alignment policy is, but I think this is due to such a reason. For efficient memory utilization using Python, you can use a large fragment of the pre-allocated bytearray and choose a good number as a piece to use (you need to check which number is better, it depends on the OS).
Fang-pen lin
source share