Skip to content

gh-120754: Update estimated_size in C truncate#121357

Merged
vstinner merged 1 commit intopython:mainfrom
cmaloney:cmaloney/fix_largefile_amd64
Jul 4, 2024
Merged

gh-120754: Update estimated_size in C truncate#121357
vstinner merged 1 commit intopython:mainfrom
cmaloney:cmaloney/fix_largefile_amd64

Conversation

@cmaloney
Copy link
Contributor

@cmaloney cmaloney commented Jul 4, 2024

goal: Fix buildbot failure https://github.com/python/cpython/pull/120755

Sometimes a large file is truncated (test_largefile). While estimated_size is used as a estimate (the read will get all the bytes in the file when it is wrong), that it is much larger than the actual size of data can result in a significant over allocation and sometimes lead to a MemoryError / running out of memory.

This brings the C implementation to match the Python _pyio implementation.

cc: @vstinner

I've been unable to reproduce the failure locally so far by running ./build/python -bb -E -Wd -m test -r -w -uall test_largefile. My suspicion is that the AMD64 box has limited memory. Working to try and test peak memory usage in the test / if that went down

Sometimes a large file is truncated (test_largefile). While
estimated_size is used as a estimate (the read will stil get the number
of bytes in the file), that it is much larger than the actual size of
data can result in a significant over allocation and sometimes lead to
a MemoryError / running out of memory.

This brings the C implementation to match the Python _pyio
implementation.
@cmaloney cmaloney changed the title gh-120754: Update size_estimated in C truncate Jul 4, 2024
@cmaloney
Copy link
Contributor Author

cmaloney commented Jul 4, 2024

Validated memory usage decrease by running under https://www.gnu.org/software/time/

/usr/bin/time -v ./python -bb -E -Wd -m test -r -w -uall test_largefile -vvv

Maximum resident set size (kbytes): 2464692 (main) -> 24532 (this pr)

Copy link
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.

LGTM

@vstinner vstinner enabled auto-merge (squash) July 4, 2024 09:32
@vstinner vstinner merged commit 06a1c3f into python:main Jul 4, 2024
@cmaloney cmaloney deleted the cmaloney/fix_largefile_amd64 branch July 4, 2024 17:07
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
Sometimes a large file is truncated (test_largefile). While
estimated_size is used as a estimate (the read will stil get the number
of bytes in the file), that it is much larger than the actual size of
data can result in a significant over allocation and sometimes lead to
a MemoryError / running out of memory.

This brings the C implementation to match the Python _pyio
implementation.
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
Sometimes a large file is truncated (test_largefile). While
estimated_size is used as a estimate (the read will stil get the number
of bytes in the file), that it is much larger than the actual size of
data can result in a significant over allocation and sometimes lead to
a MemoryError / running out of memory.

This brings the C implementation to match the Python _pyio
implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants