Skip to content

Handle 64-bit systems and large memory allocations - #10076

Merged
pllim merged 1 commit into
astropy:masterfrom
manodeep:patch-1
Apr 3, 2020
Merged

pllim merged 1 commit into
astropy:masterfrom
manodeep:patch-1

Conversation

@manodeep

Copy link
Copy Markdown
Contributor

Now can handle memory allocations greater than 2 GB. I have both a normal and a general solution - might be good to make a decision if the general solution is worth keeping around.

Description

This pull request is to address a memory allocation issue identified in #8946

@astropy-bot astropy-bot Bot added the utils label Mar 27, 2020
@bsipocz bsipocz added the Bug label Mar 27, 2020
@bsipocz bsipocz linked an issue Mar 27, 2020 that may be closed by this pull request
@manodeep

Copy link
Copy Markdown
Contributor Author

@bsipocz In case there is any confusion -- the issue #8946 is different and might (will?) not be impacted by this PR

@bsipocz

bsipocz commented Mar 27, 2020

Copy link
Copy Markdown
Member

Ohh, OK, I didn't check the issue but rather misread your comment in the description.

@bsipocz

bsipocz commented Mar 27, 2020

Copy link
Copy Markdown
Member

I'm in the middle to wrap up the 4.0.1 release, so you can add the changelog entry once the release is out and the changelog is cleaned up (probably tomorrow).

@bsipocz bsipocz added this to the v4.0.2 milestone Mar 27, 2020
Comment thread astropy/utils/xml/src/iterparse.c Resolved
Comment thread astropy/utils/xml/src/iterparse.c Outdated
}
#else
/* This is the general solution for arbitrary widths for Py_ssize_t but is much less
readable and possibly over-kill */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Definitely harder to read but very appealing since we don't need to worry about (Py)_ssize_t increasing or not. I'll defer to C-ext experts.

Comment thread astropy/utils/xml/src/iterparse.c Outdated

n--;

#if 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note to maintainer: I think we need to pick one and remove this "if else".

Comment thread astropy/utils/xml/src/iterparse.c Outdated
readable and possibly over-kill */
const size_t numbits = sizeof(Py_ssize_t)*CHAR_BIT - 1;/* remove one for the sign-bit */
size_t shift = 1, totbits = 0;
while(totbits < numbits) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about the following to replace the whole routine? (Also takes care of n <= 1)

size_t result = 1;
while (n > 1) {
    result <<= 1;
    n >>= 1;
}
return result;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is essentially what I used as the correct code in my testing routine. The biggest difference is that the (worst-case) number of steps in this code snippet scales as the number of bits, while the other two solutions have a constant complexity of O(log_2(nbits))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I now see I really didn't look carefully enough at the original code! Suggestion withdrawn!

Comment thread astropy/utils/xml/src/iterparse.c Resolved
@pllim

pllim commented Mar 30, 2020

Copy link
Copy Markdown
Member

Why don't we wrap this up then?

  1. Apply Handle 64-bit systems and large memory allocations #10076 (comment) and remove the loop implementation. (No need to squash commits.)
  2. Add a change log under bug fix for 4.0.2.

Thank you!

@manodeep

manodeep commented Apr 1, 2020

Copy link
Copy Markdown
Contributor Author

@pllim How should I pull in the latest changelog (before adding in the entry within v4.0.2)?

Also, while we are editing this file, should I uncomment the lines that handle negative arguments? or simply remove those lines?

(First time-committer, please excuse the ignorance)

@pllim

pllim commented Apr 1, 2020

Copy link
Copy Markdown
Member

To grab latest changes from master (assuming you name this repo remote upstream):

git fetch upstream master
git rebase upstream/master

Unless you run into conflicts, the above commands should be all you need. You also need to force push afterwards. Make a backup branch first if in doubt. Thanks for working on this!

negative arguments?

Technically, it is out of scope, right? This PR explicitly states that it addresses 64-bit problem, not negative value. So, I guess, unless you have strong opinion otherwise, to remove it.

@bsipocz

bsipocz commented Apr 1, 2020

Copy link
Copy Markdown
Member

@manodeep - feel free to ping me on slack if you run into any issues with the rebase

@manodeep

manodeep commented Apr 2, 2020

Copy link
Copy Markdown
Contributor Author

@pllim Made the updates the way you suggested - think that went without any fuss. Please let me know if I need to make any other changes. Thanks!

@mhvk

mhvk commented Apr 3, 2020

Copy link
Copy Markdown
Contributor

@manodeep - sorry for the hassle, but could you rebase again, but this time also squash all the commits into one? I don't think we need to preserve the history here. Thanks!

@manodeep

manodeep commented Apr 3, 2020

Copy link
Copy Markdown
Contributor Author

@mhvk Ohh not a problem at all - I was wondering that during the rebase. I totally agree - these individual commits do not add any value to the history. Let me give that a go

@manodeep

manodeep commented Apr 3, 2020

Copy link
Copy Markdown
Contributor Author

@mhvk Updated with a rebase + squash. Seems like it went fine and everything got squashed into one commit.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great, thanks so much!

@mhvk mhvk added the zzz 💤 merge-when-ci-passes Do not use: We have auto-merge option now. label Apr 3, 2020

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks!

@pllim
pllim merged commit 21ee9d6 into astropy:master Apr 3, 2020
@bsipocz

bsipocz commented Apr 3, 2020

Copy link
Copy Markdown
Member

Thanks @manodeep! And I'm looking forward for future contributions!

bsipocz pushed a commit that referenced this pull request Apr 13, 2020
Handle 64-bit systems and large memory allocations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug utils zzz 💤 merge-when-ci-passes Do not use: We have auto-merge option now.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants