Skip to content

bpo-27987: pymalloc: align by 16bytes on 64bit platform#12850

Merged
methane merged 3 commits intopython:masterfrom
methane:align-16byte
May 14, 2019
Merged

bpo-27987: pymalloc: align by 16bytes on 64bit platform#12850
methane merged 3 commits intopython:masterfrom
methane:align-16byte

Conversation

@methane
Copy link
Copy Markdown
Member

@methane methane commented Apr 16, 2019

Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea of the impact on memory consumption?

@methane
Copy link
Copy Markdown
Member Author

methane commented Apr 16, 2019

Any idea of the impact on memory consumption?

Typically, tuples and strs are dominants about number of objects.

In case of str, I expect 50+% of the objects are len(s)<8. So I think impact is "+8 bytes for 50+% strings". (56bytes -> 64bytes, 12.5%). But no impact for strings which 8 <= len(s) < 16. (Note that there is trailing NUL bytes. 8-length string like __init__ is 64bytes before and after this patch).

In case of tuples, roughly +8 bytes for 1/2 of tuples. But please note I have removed 8bytes from GC Header in Python 3.8. When comparing to Python 3.7, -8 bytes for 1/2 of tuples.

@vstinner
Copy link
Copy Markdown
Member

In case of str, I expect 50+% of the objects are len(s)<8. So I think impact is "+8 bytes for 50+% strings". (56bytes -> 64bytes, 12.5%). But no impact for strings which 8 <= len(s) < 16. (Note that there is trailing NUL bytes. 8-length string like init is 64bytes before and after this patch).

Ok, but would it be possible to measure the "real" memory usage of a Python program? For example, run "./python -i -m test test_os" and then run:

>>> import os; res=os.system(f"grep VmPeak /proc/{os.getpid()}/status")
VmPeak:	  224828 kB

I'm curious to know if we can see this memory footprint increase for real, not just in theory :-)

@methane
Copy link
Copy Markdown
Member Author

methane commented Apr 16, 2019

Ok, but would it be possible to measure the "real" memory usage of a Python program?

$ ./python -c 'import django, sys; sys._debugmallocstats()'

master:

10 arenas * 262144 bytes/arena     =            2,621,440

# bytes in allocated blocks        =            2,277,200
# bytes in available blocks        =              145,016
33 unused pools * 4096 bytes       =              135,168
# bytes lost to pool headers       =               29,136
# bytes lost to quantization       =               34,920
# bytes lost to arena alignment    =                    0
Total                              =            2,621,440

align-16byte:

10 arenas * 262144 bytes/arena     =            2,621,440

# bytes in allocated blocks        =            2,370,592
# bytes in available blocks        =               87,552
25 unused pools * 4096 bytes       =              102,400
# bytes lost to pool headers       =               29,520
# bytes lost to quantization       =               31,376
# bytes lost to arena alignment    =                    0
Total                              =            2,621,440
>>> (2370592-2277200) / 2277200 * 100
4.101176883892499

About 4% increase in this case.

$ ./python-master -c 'import django, os; os.system(f"grep VmPeak /proc/{os.getpid()}/status")'
VmPeak:    15624 kB

$ ./python-align-16byte -c 'import django, os; os.system(f"grep VmPeak /proc/{os.getpid()}/status")'
VmPeak:    15624 kB

No visible impact about VmPeak.

@brettcannon brettcannon added the type-feature A feature request or enhancement label Apr 17, 2019
@pitrou
Copy link
Copy Markdown
Member

pitrou commented May 10, 2019

Also, can you run the benchmark suite?
Ideally, both CPU numbers and memory consumption numbers (it allows you to track memory consumption).

Copy link
Copy Markdown
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on the principle.

@methane
Copy link
Copy Markdown
Member Author

methane commented May 14, 2019

Also, can you run the benchmark suite?
Ideally, both CPU numbers and memory consumption numbers (it allows you to track memory consumption).

I post the result on bpo issue.

@methane methane merged commit f0be4bb into python:master May 14, 2019
@methane methane deleted the align-16byte branch May 14, 2019 09:51
@miss-islington
Copy link
Copy Markdown
Contributor

Thanks @methane for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 14, 2019
(cherry picked from commit f0be4bb)

Co-authored-by: Inada Naoki <songofacandy@gmail.com>
@bedevere-bot
Copy link
Copy Markdown

GH-13318 is a backport of this pull request to the 3.7 branch.

@miss-islington
Copy link
Copy Markdown
Contributor

Thanks @methane for the PR 🌮🎉.. I'm working now to backport this PR to: 2.7.
🐍🍒⛏🤖

@miss-islington
Copy link
Copy Markdown
Contributor

Sorry, @methane, I could not cleanly backport this to 2.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker f0be4bbb9b3cee876249c23f2ae6f38f43fa7495 2.7

@bedevere-bot
Copy link
Copy Markdown

GH-13319 is a backport of this pull request to the 2.7 branch.

vstinner added a commit that referenced this pull request May 15, 2019
miss-islington added a commit that referenced this pull request May 25, 2019
(cherry picked from commit f0be4bb)

Co-authored-by: Inada Naoki <songofacandy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants