On Mon, Mar 21, 2011 at 04:45:07AM -0400, Esztermann, Ansgar wrote:

On Mar 21, 2011, at 1:36 , Jesse Becker wrote:

Thus, for my *simple* testing, data and rss are both ignored (and yes,
rss *is* documented as being ignored, but data is not).

Did you write to memory after allocation? If not, this might be related to 
copy-on-write.

Yep, there's an explicit call to memset() after the allocation
specifically to avoid this problem.

The code is below, if anyone cares.  There are several variables to
control the size and number of malloc()'ed "chunks", as well the lengths
of various calls to sleep() (this is so the user has a chance to watch the memory allocation in top/ps/etc.)

Yes, the code is sloppy and probably riddled with errors. :)

<----snip---->

/* Copyright (c) 2011, Jesse Becker
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
   must display the following acknowledgement:
   This product includes software developed by the <organization>.
4. Neither the name of the <organization> nor the
   names of its contributors may be used to endorse or promote products
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY JESSE BECKER ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


// Compile with: gcc -o eatmem eatmem.c // No special options are needed.

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

#define KB 2<<10
#define MB 2<<20
#define GB 2<<30

#define SZ 1*MB-1

#define COUNT 50

int main (void) {
    int *p;
    unsigned long int i = 0;
    unsigned long long int total_mem = 0;
    unsigned short startsleep = 1;
    unsigned short intersleep = 0;
    unsigned short finalsleep = 60;

    printf("Will allocate %u blocks of %llu bytes. Total = %llu\n", COUNT, SZ, 
COUNT * SZ);
    printf("Sleeping %d seconds first.\n", startsleep);

    sleep(startsleep);

    for (i=0;i<COUNT;i++) {

        printf("Malloc()ing block %2d of size %llu...", i+1, SZ);
        p=malloc(SZ);
        if (p) {
            total_mem+=SZ;
            printf("success. Total alloc is %llu.  ", total_mem);
        } else {
            printf("FAILED!!!\n");
            sleep(finalsleep);
            exit(1);
        }

        printf("Forcing allocation w/memset()...");
        memset(p,255,SZ-1);
        printf("sleeping %d seconds\n", intersleep);
        sleep(intersleep);
    }

    sleep(finalsleep);

    return 0;
}

<----snip---->

--
Jesse Becker
NHGRI Linux support (Digicon Contractor)
_______________________________________________
users mailing list
[email protected]
https://gridengine.org/mailman/listinfo/users

Reply via email to