Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* A problem porting sbrk
@ 1997-02-22  2:01 Steven White
  1997-02-23  2:45 ` Richard Henderson
  1997-03-04 19:02 ` gcc-2.7.2.2 / g77-0.5.20 on RH4.1 Lev D Gelb
  0 siblings, 2 replies; 7+ messages in thread
From: Steven White @ 1997-02-22  2:01 UTC (permalink / raw)


I have a problem for you sophisticated linux-alpha kernel hackers...

I'm trying to port some code compiled on a Digital UNIX V3.2C 
machine to an 500 MHz 21164 alpha linux machine, running Red Hat 
Linux 4.1, Kernel 2.0.27. It appears that sbrk doesn't work
right when I do this. Here is a simple test:

file tbrk.c:
#include <stdio.h>

extern void * sbrk(long inc);

int main()
    {

    double *pa;
    pa = sbrk(20000000); printf("%ld\n",(long)pa); printf("%f\n",*pa);
    pa = sbrk(20000000); printf("%ld\n",(long)pa); printf("%f\n",*pa);
    pa = sbrk(20000000); printf("%ld\n",(long)pa); printf("%f\n",*pa);
    pa = sbrk(20000000); printf("%ld\n",(long)pa); printf("%f\n",*pa);
    pa = sbrk(20000000); printf("%ld\n",(long)pa); printf("%f\n",*pa);
    pa = sbrk(20000000); printf("%ld\n",(long)pa); printf("%f\n",*pa);
    pa = sbrk(20000000); printf("%ld\n",(long)pa); printf("%f\n",*pa);
    pa = sbrk(20000000); printf("%ld\n",(long)pa); printf("%f\n",*pa);
    pa = sbrk(20000000); printf("%ld\n",(long)pa); printf("%f\n",*pa);
    pa = sbrk(20000000); printf("%ld\n",(long)pa); printf("%f\n",*pa);
    pa = sbrk(20000000); printf("%ld\n",(long)pa); printf("%f\n",*pa);
    pa = sbrk(20000000); printf("%ld\n",(long)pa); printf("%f\n",*pa);
    pa = sbrk(20000000); printf("%ld\n",(long)pa); printf("%f\n",*pa);
    pa = sbrk(20000000); printf("%ld\n",(long)pa); printf("%f\n",*pa);

    }

Now run on the Digital Unix machine:
5368734016
0.000000
5388734016
0.000000
5408734016
0.000000
5428734016
0.000000
5448734016
0.000000
5468734016
0.000000
5488734016
0.000000
5508734016
0.000000
5528734016
0.000000
5548734016
0.000000
-1
Segmentation fault

This does what you expect. It gets lots of memory (200 Meg, on a 160 Meg
machine), then dies in the appropriate fashion. 

Now I compile with 
cc -g -non_shared tbrk.c -o tbrk, 
move it to the 256 Meg linux machine, and I get

5368734016
0.000000
5388734016
0.000000
5408734016
0.000000
5428734016
0.000000
5448734016
0.000000
5468734016
Segmentation fault

It gets about 100 Meg of memory, then dies.
The last address is out of bounds, and I didn't get the -1 error
indicator.

Does anyone understand this or have any suggestions?

		Steve White
		UC Irvine Dept of Physics

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

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

* Re: A problem porting sbrk
  1997-02-22  2:01 A problem porting sbrk Steven White
@ 1997-02-23  2:45 ` Richard Henderson
  1997-03-04 19:02 ` gcc-2.7.2.2 / g77-0.5.20 on RH4.1 Lev D Gelb
  1 sibling, 0 replies; 7+ messages in thread
From: Richard Henderson @ 1997-02-23  2:45 UTC (permalink / raw)


> It gets about 100 Meg of memory, then dies.
> The last address is out of bounds, and I didn't get the -1 error
> indicator.

Hmm.  Yep.  This is one case where, either through design or
carelessness, we followed Linux/i386 instead of OSF/1.  What is
happening is brk(2) always returns the current brk address.  If
this is not what you'd requested, you know an error has occurred.

I'll have to investigate what would happen to libc if this were
changed.  I think we can get away with it without changes to libc.

r~

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

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

* Re: A problem porting sbrk
       [not found] <199702230245.UAA27778@atheist.tamu.edu>
@ 1997-02-23 17:12 ` Richard Henderson
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 1997-02-23 17:12 UTC (permalink / raw)


Would the person having the sbrk problem try this out?  I think this
will be close enough to satisfy both OSF and current Linux libc. 

Unfortunately, coming to exact sync with OSF would mean changing libc.
Trivially, but still it would have to be propogated.

r~

--- arch/alpha/kernel/entry.S.orig	Sun Feb 23 10:21:52 1997
+++ arch/alpha/kernel/entry.S	Sun Feb 23 10:22:09 1997
@@ -709,7 +709,7 @@ sys_call_table:
 /*0*/	.quad do_entSys, sys_exit, sys_fork, sys_read, sys_write
 	.quad do_entSys, sys_close, sys_wait4, do_entSys, sys_link
 	.quad sys_unlink, do_entSys, sys_chdir, sys_fchdir, sys_mknod
-	.quad sys_chmod, sys_chown, sys_brk, do_entSys, sys_lseek
+	.quad sys_chmod, sys_chown, osf_brk, do_entSys, sys_lseek
 	.quad sys_getxpid, osf_mount, osf_umount, sys_setuid, sys_getxuid
 	.quad do_entSys, sys_ptrace, do_entSys, do_entSys, do_entSys
 	.quad do_entSys, do_entSys, do_entSys, sys_access, do_entSys
--- arch/alpha/kernel/osf_sys.c.orig	Sun Feb 23 10:15:23 1997
+++ arch/alpha/kernel/osf_sys.c	Sun Feb 23 10:29:55 1997
@@ -50,6 +50,20 @@ extern asmlinkage int sys_swapon(const c
 extern asmlinkage unsigned long sys_brk(unsigned long);
 
 /*
+ * Brk needs to return an error.  Still support Linux's brk(0) query idiom,
+ * which OSF programs just shouldn't be doing.  We're still not quite
+ * identical to OSF as we don't return 0 on success, but doing otherwise
+ * would require changes to libc.  Hopefully this is good enough.
+ */
+asmlinkage unsigned long osf_brk(unsigned long brk)
+{
+	unsigned long retval = sys_brk(brk);
+	if (brk && brk != retval)
+		retval = -ENOMEM;
+	return retval;
+}
+ 
+/*
  * This is pure guess-work..
  */
 asmlinkage int osf_set_program_attributes(

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

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

* Re: A problem porting sbrk
@ 1997-02-23 23:01 Steven White
  0 siblings, 0 replies; 7+ messages in thread
From: Steven White @ 1997-02-23 23:01 UTC (permalink / raw)


Richard Henderson writes:

> Would the person having the sbrk problem try this out?  I think
> this will be close enough to satisfy both OSF and current Linux libc. 

...
Changes to kernel source listed, adding new system call to the kernel...
...

(By the way, sbrk and brk are called by malloc, and so are
crucial to many programs.) 

Right now I'm afraid to try this, because I just got my machine
(preconfigured from SWT) and I haven't recompiled the kernel
myself yet, at this point. Even though the change looks simple,
I might screw it up and then I'd be in big trouble...

However, it seems to me that this doesn't address the main
problem. Regardless of the way the "out of memory" error is reported, 
the OSF program isn't able to get as much memory as the same
program compiled with gcc on the linux machine itself.
When I compile with gcc on linux and run on linux, I get 30
successful calls to sbrk before it runs out of memory (600 Mb). When I 
compile with cc on OSF and run on OSF, I get 10 successful calls
(200 Mb). Both of these are behaving correctly. But when I 
compile with cc on OSF and run on linux, I only get 5 successful
calls to sbrk--100 Mb when the machine has 256 Mb of RAM.
(limits are datasize=614400 kbytes, stacksize=8192 kbytes).

I don't really care about how it dies if it runs out of memory--
I just want to be able to run big programs. I purchased the OSF
c++ compiler cxx for my OSF machine, and it optimizes much better
than gcc.

		Steve White
		srwhite@uci.edu
		UC Irvine Dept of Physics

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

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

* Re: A problem porting sbrk
       [not found] <199702232301.PAA30446@hedrock.ps.uci.edu>
@ 1997-02-24 17:29 ` Richard Henderson
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 1997-02-24 17:29 UTC (permalink / raw)


> However, it seems to me that this doesn't address the main
> problem. Regardless of the way the "out of memory" error is reported, 
> the OSF program isn't able to get as much memory as the same
> program compiled with gcc on the linux machine itself.

I don't see this effect.  To be sure, I modified your program a 
little to make sure memory was actually being allocated, rather 
than getting a few hundred thousand copy-on-write duplicates of
the zero page.  I append it.

In any case, on a machine with 64MB ram and no swap, I get 5227
pages allocated by a native linux application, and 5100 pages
allocated by a static OSF application -- roughly 40.8MB and 39.8MB
respectively.  Some but not all of that can be explained by the
larger static binary, but in any case would not seem to indicate
the problem you describe.

Disregarding ulimits, there should be no arbitrary limit to how
much memory an application can grab, native or otherwise.

Can anyone else duplicate this problem?  I recommend trying this
without to terribly much swap, as it can take forever to page
through even a 64M partition.

r~

#include <stdio.h>

extern void * sbrk(long inc);

int main()
    {
    int i = 0;
    long *pa;
    while(1)
	{
	pa = sbrk(8*1024); 
	printf("%p %d\n",pa,++i); 
	printf("%ld\n",*pa = 1);
	}

    }

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

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

* Re: A problem porting sbrk
@ 1997-02-24 19:38 Steven White
  0 siblings, 0 replies; 7+ messages in thread
From: Steven White @ 1997-02-24 19:38 UTC (permalink / raw)


Richard Henderson writes:

>> However, it seems to me that this doesn't address the main
>> problem. Regardless of the way the "out of memory" error is reported, 
>> the OSF program isn't able to get as much memory as the same
>> program compiled with gcc on the linux machine itself.
>
>I don't see this effect.  To be sure, I modified your program a 
>little to make sure memory was actually being allocated, rather 
>than getting a few hundred thousand copy-on-write duplicates of
>the zero page.  I append it.

I've verified I still get the same effect with your version of
the test program.

>In any case, on a machine with 64MB ram and no swap, I get 5227
>pages allocated by a native linux application, and 5100 pages
>allocated by a static OSF application -- roughly 40.8MB and 39.8MB
>respectively.  Some but not all of that can be explained by the
>larger static binary, but in any case would not seem to indicate
>the problem you describe.

Could it be something that comes up only for large-memory programs?
Something weird is going on near 100 Mb when I try it.

>Can anyone else duplicate this problem?  I recommend trying this
>without to terribly much swap, as it can take forever to page
>through even a 64M partition.

But more than about 100 Mb of memory and swap may be needed to 
duplicate the problem.

		Steve White
		srwhite@uci.edu
		UC Irvine Dept of Physics

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

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

* gcc-2.7.2.2 / g77-0.5.20 on RH4.1
  1997-02-22  2:01 A problem porting sbrk Steven White
  1997-02-23  2:45 ` Richard Henderson
@ 1997-03-04 19:02 ` Lev D Gelb
  1 sibling, 0 replies; 7+ messages in thread
From: Lev D Gelb @ 1997-03-04 19:02 UTC (permalink / raw)


OK, I'm trying to compile the new release of
g77 on my redhat-4.1 box.

I got the src.rpm for gcc-2.7.2.1,
and the 2.7.2.2 distribution, unpacked the second,
and applied the patches to it.

But, when I then try to apply the g77-0.5.20-included
patch to the resulting distribution, the patching fails
while patching "configure", which then does not work.

If... I apply the g77 patch to the clean distribution
and THEN apply the RedHat patches, it gets about halfway
through the first "make" of the compiler, with lots of
warnings about "alloca", and then dies because it can't
find "crt0.o"...

If... I just try to make gcc without g77, the RH patches
and the gcc-2.7.2.2 distribution work OK.

If... I just apply the g77 patch to the clean distribution,
(e.g., following the g77 instructions) It dies on the first compile:

[root@eddie gcc]# make "LANGUAGES=c"
cc  -DIN_GCC   -g     -I. -I. -I./config \

-DGCC_INCLUDE_DIR=\"/usr/lib/gcc-lib/alpha-unknown-linux/2.7.2.2.f.2/include\"\
  -DGPLUSPLUS_INCLUDE_DIR=\"/usr/lib/g++-include\" \
  -DLOCAL_INCLUDE_DIR=\"/usr/local/include\" \

-DCROSS_INCLUDE_DIR=\"/usr/lib/gcc-lib/alpha-unknown-linux/2.7.2.2.f.2/sys-include\"\
  -DTOOL_INCLUDE_DIR=\"/usr/alpha-unknown-linux/include\" \
  -c `echo ./cccp.c | sed 's,^\./,,'`
cccp.c:322: conflicting types for `sys_errlist'
/usr/include/stdio.h:216: previous declaration of `sys_errlist'
make: *** [cccp.o] Error 1

Any ideas, anyone?

Lev Gelb

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

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

end of thread, other threads:[~1997-03-04 19:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-02-22  2:01 A problem porting sbrk Steven White
1997-02-23  2:45 ` Richard Henderson
1997-03-04 19:02 ` gcc-2.7.2.2 / g77-0.5.20 on RH4.1 Lev D Gelb
     [not found] <199702230245.UAA27778@atheist.tamu.edu>
1997-02-23 17:12 ` A problem porting sbrk Richard Henderson
  -- strict thread matches above, loose matches on Subject: below --
1997-02-23 23:01 Steven White
     [not found] <199702232301.PAA30446@hedrock.ps.uci.edu>
1997-02-24 17:29 ` Richard Henderson
1997-02-24 19:38 Steven White

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