Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* memory address space on alpha Linux
@ 2001-01-06 22:00 T. Daniel Crawford
  2001-01-06 22:49 ` Uncle George
  2001-01-06 23:49 ` Richard Henderson
  0 siblings, 2 replies; 8+ messages in thread
From: T. Daniel Crawford @ 2001-01-06 22:00 UTC (permalink / raw)
  To: axp-list

Hi, all,

I'm having trouble with the way the memory allocation system works in C
as implemented under alpha Linux.  Here's some simple code:

------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  long int *n, size;

  printf("%d %d %d\n", sizeof(int), sizeof(long int), sizeof(long long
int));

  size = 1;
  n = (long int *) malloc(size * sizeof(int));
  printf("size = %d; n = %ld\n", size, n);

  size = 1000;
  n = (long int *) malloc(size * sizeof(int));
  printf("size = %d; n = %ld\n", size, n);

  size = 100000;
  n = (long int *) malloc(size * sizeof(int));
  printf("size = %d; n = %ld\n", size, n);

  return 0;
}
------------------------------------------------------------------------------

The output from this program using the Compaq C compiler, ccc, is:

4 8 8
size = 1; n = 4832890112
size = 1000; n = 4832890608
size = 100000; n = 2199023427600

Note that I get nearly the same results using GNU C.

Now, if, instead, I run this under Compaq's Tru64 UNIX, I get:

4 8 8
size = 1; n = 5368717568
size = 1000; n = 5368721408
size = 100000; n = 5368765536

For the large-block allocation, on alpha Linux the address is off in the
middle of nowhere (from my perspective) while on alpha Tru64 both the small-
and large-block allocations end up in approximately the same region of
address space.

My questions: (1) I am misinterpreting my results? (2) If not, why does
this happen?

Thanks in advance for any help!

-Daniel

-- 
T. Daniel Crawford                           Department of Chemistry
crawdad@vt.edu                                    Virginia Tech
www.chem.vt.edu/chem-dept/crawford    Voice: 540-231-7760  FAX: 540-231-3255




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: memory address space on alpha Linux
  2001-01-06 22:00 memory address space on alpha Linux T. Daniel Crawford
@ 2001-01-06 22:49 ` Uncle George
  2001-01-06 23:49 ` Richard Henderson
  1 sibling, 0 replies; 8+ messages in thread
From: Uncle George @ 2001-01-06 22:49 UTC (permalink / raw)
  To: axp-list

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=x-user-defined, Size: 2442 bytes --]

Looks are deceiving, the addr is a mmap() address, rather than from a traditional
malloc pool. I think anything over 128k is mmapped, so that it can be unmapped
without the fragmenting the malloc pool with large memory holes
/gat
btw by printing in hex u may see the allocation better.
btw#2 malloc allocation is on a per 'C' library basis. I dont know if ccc (
true64 c compiler ) uses glibc or their own.


"T. Daniel Crawford" wrote:

> Hi, all,
>
> I'm having trouble with the way the memory allocation system works in C
> as implemented under alpha Linux.  Here's some simple code:
>
> ------------------------------------------------------------------------------
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(void)
> {
>   long int *n, size;
>
>   printf("%d %d %d\n", sizeof(int), sizeof(long int), sizeof(long long
> int));
>
>   size = 1;
>   n = (long int *) malloc(size * sizeof(int));
>   printf("size = %d; n = %ld\n", size, n);
>
>   size = 1000;
>   n = (long int *) malloc(size * sizeof(int));
>   printf("size = %d; n = %ld\n", size, n);
>
>   size = 100000;
>   n = (long int *) malloc(size * sizeof(int));
>   printf("size = %d; n = %ld\n", size, n);
>
>   return 0;
> }
> ------------------------------------------------------------------------------
>
> The output from this program using the Compaq C compiler, ccc, is:
>
> 4 8 8
> size = 1; n = 4832890112
> size = 1000; n = 4832890608
> size = 100000; n = 2199023427600
>
> Note that I get nearly the same results using GNU C.
>
> Now, if, instead, I run this under Compaq's Tru64 UNIX, I get:
>
> 4 8 8
> size = 1; n = 5368717568
> size = 1000; n = 5368721408
> size = 100000; n = 5368765536
>
> For the large-block allocation, on alpha Linux the address is off in the
> middle of nowhere (from my perspective) while on alpha Tru64 both the small-
> and large-block allocations end up in approximately the same region of
> address space.
>
> My questions: (1) I am misinterpreting my results? (2) If not, why does
> this happen?
>
> Thanks in advance for any help!
>
> -Daniel
>
> --
> T. Daniel Crawford                           Department of Chemistry
> crawdad@vt.edu                                    Virginia Tech
> www.chem.vt.edu/chem-dept/crawford    Voice: 540-231-7760  FAX: 540-231-3255
>
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: memory address space on alpha Linux
  2001-01-06 22:00 memory address space on alpha Linux T. Daniel Crawford
  2001-01-06 22:49 ` Uncle George
@ 2001-01-06 23:49 ` Richard Henderson
  2001-01-07  2:46   ` T. Daniel Crawford
  1 sibling, 1 reply; 8+ messages in thread
From: Richard Henderson @ 2001-01-06 23:49 UTC (permalink / raw)
  To: axp-list

On Sat, Jan 06, 2001 at 05:00:53PM -0500, T. Daniel Crawford wrote:
> For the large-block allocation, on alpha Linux the address is off in the
> middle of nowhere (from my perspective) ...

Yes, but so what?  You can read and write to it.



r~




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: memory address space on alpha Linux
  2001-01-06 23:49 ` Richard Henderson
@ 2001-01-07  2:46   ` T. Daniel Crawford
  2001-01-07 20:07     ` Richard Henderson
  2001-01-07 20:36     ` Greg Lindahl
  0 siblings, 2 replies; 8+ messages in thread
From: T. Daniel Crawford @ 2001-01-07  2:46 UTC (permalink / raw)
  To: axp-list

On Sat, 6 Jan 2001, Richard Henderson wrote:

> On Sat, Jan 06, 2001 at 05:00:53PM -0500, T. Daniel Crawford wrote:
> > For the large-block allocation, on alpha Linux the address is off in the
> > middle of nowhere (from my perspective) ...
>
> Yes, but so what?  You can read and write to it.
>

My question stems from my experience on most other operating systems ---
Intel Linux, IBM AIX, SGI, CRAY, etc. --- that the two types of addresses
returned by malloc() lie in the same ballpark.  I'm not arguing that this
is *wrong* per se, but I'm simply wondering why alpha Linux chooses to
place these memory blocks so far away from the smaller allocations when
it seems mosts other mainstream OS's do not.

More to the point, though, is the fact that I have some older Fortran code
that I'm attempting to port to alpha Linux which fails when these addresses
are very, very, very far apart as they are here.  If there is a way to
cleanly force the addresses to be closer together, I need to learn about
it.

Thanks,

-Daniel

-- 
T. Daniel Crawford                           Department of Chemistry
crawdad@vt.edu                                    Virginia Tech
www.chem.vt.edu/chem-dept/crawford    Voice: 540-231-7760  FAX: 540-231-3255




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: memory address space on alpha Linux
  2001-01-07  2:46   ` T. Daniel Crawford
@ 2001-01-07 20:07     ` Richard Henderson
  2001-01-07 20:21       ` T. Daniel Crawford
  2001-01-07 20:36     ` Greg Lindahl
  1 sibling, 1 reply; 8+ messages in thread
From: Richard Henderson @ 2001-01-07 20:07 UTC (permalink / raw)
  To: axp-list

On Sat, Jan 06, 2001 at 09:46:55PM -0500, T. Daniel Crawford wrote:
> I'm simply wondering why alpha Linux chooses to
> place these memory blocks so far away from the smaller allocations when
> it seems mosts other mainstream OS's do not.

To avoid severe heap fragmentation.  The other os's don't
because they didn't think of it.

> More to the point, though, is the fact that I have some older Fortran code
> that I'm attempting to port to alpha Linux which fails when these addresses
> are very, very, very far apart as they are here.

You can handle an address above 6GB, but not above 32TB?
Or are you doing something amazingly strange with 32-bit
displacements against a fake undimensioned array?

> If there is a way to cleanly force the addresses to be closer
> together, I need to learn about it.

See mallopt.


r~




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: memory address space on alpha Linux
  2001-01-07 20:07     ` Richard Henderson
@ 2001-01-07 20:21       ` T. Daniel Crawford
  2001-01-07 20:36         ` Greg Lindahl
  0 siblings, 1 reply; 8+ messages in thread
From: T. Daniel Crawford @ 2001-01-07 20:21 UTC (permalink / raw)
  To: axp-list

On Sun, 7 Jan 2001, Richard Henderson wrote:
>
> > More to the point, though, is the fact that I have some older Fortran code
> > that I'm attempting to port to alpha Linux which fails when these addresses
> > are very, very, very far apart as they are here.
>
> You can handle an address above 6GB, but not above 32TB?
> Or are you doing something amazingly strange with 32-bit
> displacements against a fake undimensioned array?

You are very perceptive, as that's pretty much exactly what's going on.
You may not be interested, but here's what this old code (which I did not
write!) is doing with these addresses:

In order to have access to dynamically allocated memory blocks, the Fortran
program calls a C malloc() (or the extended Fortran intrinsic equivalent)
to allocate one big chunk.  Then the location of this memory relative to
an unitialized blank common block (with one element, an integer*4 array
called ICORE) is computed as an offset in integer*4 words.  This offset is
named I0 and is placed in another common block called "ISTART".  This allows
the subroutines in the program to have access to the dynamically allocated
memory using code like:

C Here are the common blocks with blank common and the offset to the available chunk
	COMMON // ICORE(1)
	COMMON /ISTART/ I0

C Here's a simple access example
        ICORE(I0) = 9

My problem is that I0 (and all other addresses computed from it) is just a
32-bit integer, not large enough to handle address offsets as large as I'm
seeing under alpha Linux.  If the dynamically allocated memory were placed
in the first 2^32 bits of the address space, then I could get away with a
"correct" computation of I0 and then still have access to the core.  This is
what is happening under Tru64 Unix, so we're simply getting lucky there.

As it stands, I believe I will have to go through the code and convert all address
references to 64-bit.  It's not a pleasant thought, but I'm thinking of hiring a graduate
student part-time to do it for me. :)

> > If there is a way to cleanly force the addresses to be closer
> > together, I need to learn about it.
>
> See mallopt.

I'll see if I can find it.  Thanks!

-Daniel

-- 
T. Daniel Crawford                           Department of Chemistry
crawdad@vt.edu                                    Virginia Tech
www.chem.vt.edu/chem-dept/crawford    Voice: 540-231-7760  FAX: 540-231-3255




^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: memory address space on alpha Linux
  2001-01-07  2:46   ` T. Daniel Crawford
  2001-01-07 20:07     ` Richard Henderson
@ 2001-01-07 20:36     ` Greg Lindahl
  1 sibling, 0 replies; 8+ messages in thread
From: Greg Lindahl @ 2001-01-07 20:36 UTC (permalink / raw)
  To: axp-list

> My question stems from my experience on most other operating systems ---
> Intel Linux, IBM AIX, SGI, CRAY, etc. --- that the two types of addresses
> returned by malloc() lie in the same ballpark.

The malloc in glibc, like many other modern mallocs, has 2 kinds of
addresses it returns. Small items are put in pages with other items of
similar sizes, and large items are all done together. So it's completely
normal that an 8000 byte malloc is nowhere near a big one. (There also seems
to be some other tricks going on in this case, but I think this is roughly
right.)

> More to the point, though, is the fact that I have some older Fortran code
> that I'm attempting to port to alpha Linux which fails when these
> addresses
> are very, very, very far apart as they are here.  If there is a way to
> cleanly force the addresses to be closer together, I need to learn about
> it.

-xtaso is your friend. I take it that your fortran code requires the
displacement between any pair of addresses to fit into 32 bits. If you don't
mind being limited to 2 GB total of memory, -xtaso will magically do this
for you.

-- g




^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: memory address space on alpha Linux
  2001-01-07 20:21       ` T. Daniel Crawford
@ 2001-01-07 20:36         ` Greg Lindahl
  0 siblings, 0 replies; 8+ messages in thread
From: Greg Lindahl @ 2001-01-07 20:36 UTC (permalink / raw)
  To: axp-list

> My problem is that I0 (and all other addresses computed from it) is just a
> 32-bit integer, not large enough to handle address offsets as large as I'm
> seeing under alpha Linux.

Actually, this would work fine if ICORE was just 1 chunk of memory -- the
addresses are still 64-bits, you're just limited to a 32-bit offset. So if
you had only 1 chunk of memory smaller than 2GB, you'd be fine, but
apparently you have several.

However, -xtaso does solve exactly this problem. In Tru64 it's called -taso.
You can save the graduate student slavery for something more tedious.

-- g




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-01-07 20:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-01-06 22:00 memory address space on alpha Linux T. Daniel Crawford
2001-01-06 22:49 ` Uncle George
2001-01-06 23:49 ` Richard Henderson
2001-01-07  2:46   ` T. Daniel Crawford
2001-01-07 20:07     ` Richard Henderson
2001-01-07 20:21       ` T. Daniel Crawford
2001-01-07 20:36         ` Greg Lindahl
2001-01-07 20:36     ` Greg Lindahl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox