[Cbe-oss-dev] spufs: memory leaks with SPU affinity constraint

Kazunori Asayama asayama at sm.sony.co.jp
Thu Oct 18 22:49:44 EST 2007


The spufs seems to cause memory leaks when SPU affinity is specified.
This problem can be observed by running the attached simple test
program, which just iterates construction and destruction of SPU
contexts with affinity constraint. After running the program, a lot of
memory will be still consumed.

I ran it on QS20 with following versions of kernel and got the same
results:

  - vanilla 2.6.23.1
  - SDK 3.0 early release
  - the head of cell-2.6 repository's master branch

Thanks,
--
(ASAYAMA Kazunori
  (asayama at sm.sony.co.jp))
t
-------------- next part --------------
/*
 *  libspe2 - A wrapper library to adapt the JSRE SPU usage model to SPUFS
 *
 *  Copyright (C) 2007 Sony Computer Entertainment Inc.
 *  Copyright 2007 Sony Corp.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

/*
 * Building:
 *   $ gcc -o affinity_memory_leaks affinity_memory_leaks.c -lspe2
 *
 * Running:
 *   $ free
 *   $ ./affinity_memory_leaks
 *   $ free
 *
 */

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

#define NUM_SPES 2
#define COUNT 2000
#define USE_AFFINITY 1

int main(int argc, char **argv)
{
  int ret;
  int i;

  for (i = 0; i < COUNT; i++) {
    spe_gang_context_ptr_t gang;
    spe_context_ptr_t spes[NUM_SPES];
    int j;

    gang = spe_gang_context_create(0);
    if (!gang) {
      perror("spe_gang_context_create\n");
      exit(1);
    }
    
    for (j = 0; j < NUM_SPES; j++) {
#ifdef USE_AFFINITY
      spes[j] = spe_context_create_affinity(0, j ? spes[j - 1] : NULL, gang);
#else
      spes[j] = spe_context_create_affinity(0, NULL, gang);
#endif
      if (!spes[j]) {
	perror("spe_context_create_affinity");
	exit(1);
      }
    }

    for (j = 0; j < NUM_SPES; j++) {
      ret = spe_context_destroy(spes[j]);
      if (ret) {
	perror("spe_context_destroy");
	exit(1);
      }
    }

    ret = spe_gang_context_destroy(gang);
    if (ret) {
      perror("spe_gang_context_destroy");
      exit(1);
    }
  }

  return 0;
}


More information about the cbe-oss-dev mailing list