Exemplo n.º 1
0
long 
SHM_MallocTest(void)
{
	int order;

	/*
 	* Check the static info array. Things will blow up terribly if it's
 	* incorrect. This is a late "compile time" check.....
 	*/

	for (order = 0; BLOCKSIZE(order); order++) 
	{
		if ((NBLOCKS(order) * BLOCKSIZE(order) + 
			sizeof(struct PageDescriptor)) > AREASIZE(order)) 
		{
			printf("Cannot use %d bytes out of %d in order = %d block mallocs\n",
			       (int) (NBLOCKS(order) * BLOCKSIZE(order) +
				      sizeof(struct PageDescriptor)),
			        (int) AREASIZE(order),
			       BLOCKSIZE(order));
			printf("ERROR in SHM\n");
		}
	}

	return 0;
}
Exemplo n.º 2
0
pointer bmalloc(int size) {
  int i;

  /* compute i as the least integer such that i >= log2(size) */
  for (i = 0; BLOCKSIZE( i ) < size; i++)
    ;

  if (i >= sizes) {
    printf("no space available");
    return NULL;
  }
  else if (freelists[i] != NULL) {

    /* we already have the right size block on hand */
    pointer block;
    block = freelists[i];
    freelists[i] = *(pointer *) freelists[i];
    return block;

  }
  else {
    /* we need to split a bigger block */
    pointer block, buddy;
    block = bmalloc(BLOCKSIZE(i + 1));

    if (block != NULL) {
      /* split and put extra on a free list */
      buddy = BUDDYOF(block, i);
      *(pointer *) buddy = freelists[i];
      freelists[i] = buddy;
    }

    return block;
  }
}
Exemplo n.º 3
0
unsigned int ksize(void *__ptr)
{
	unsigned int order;
	struct page_descriptor *page;

	if (!ptr) return 0;
#define ptr ((struct block_header *) __ptr)
	page = PAGE_DESC(ptr);
	__ptr = ptr - 1;

	if (~PAGE_MASK & (unsigned long)page->next) return 0;

	order = (page->order & ~PAGE_MASK);
	if (order >= sizeof(sizes) / sizeof(sizes[0])) return 0;
/*
 *	This looks like we are cheating,  but we are actually just reporting
 *	what ksize would normally report,  the size of the allocated block
 *	that is available to the caller.
 */
	if (BLOCKSIZE(order) > PAGE_SIZE)
		return((page->order & PAGE_MASK) -
				(sizeof(struct block_header) + sizeof(struct page_descriptor)));

	return BLOCKSIZE(order);
}
Exemplo n.º 4
0
static void *block_get(struct block_device *blk, int block)
{
	int ret;
	int num_blocks;

	if (block >= blk->num_blocks)
		return ERR_PTR(-EIO);

	/* first look into write buffer */
	if (block >= blk->wrblock && block <= WRBUFFER_LAST(blk))
		return blk->wrbuf + (block - blk->wrblock) * BLOCKSIZE(blk);

	/* then look into read buffer */
	if (block >= blk->rdblock && block <= blk->rdblockend)
		return blk->rdbuf + (block - blk->rdblock) * BLOCKSIZE(blk);

	/*
	 * If none of the buffers above match read the block from
	 * the device
	 */
	num_blocks = min(blk->rdbufsize, blk->num_blocks - block);

	ret = blk->ops->read(blk, blk->rdbuf, block, num_blocks);
	if (ret)
		return ERR_PTR(ret);

	blk->rdblock = block;
	blk->rdblockend = block + num_blocks - 1;

	return blk->rdbuf;
}
Exemplo n.º 5
0
static int block_put(struct block_device *blk, const void *buf, int block)
{
	if (block >= blk->num_blocks)
		return -EIO;

	if (block < blk->wrblock || block > blk->wrblock + blk->wrbufblocks) {
		writebuffer_flush(blk);
	}

	if (blk->wrbufblocks == 0) {
		blk->wrblock = block;
		blk->wrbufblocks = 1;
	}

	memcpy(blk->wrbuf + (block - blk->wrblock) * BLOCKSIZE(blk),
			buf, BLOCKSIZE(blk));

	if (block > WRBUFFER_LAST(blk))
		blk->wrbufblocks++;

	if (blk->wrbufblocks == blk->wrbufsize)
		writebuffer_flush(blk);

	return 0;
}
Exemplo n.º 6
0
int get_order (int size)
{
	int order;

	/* Add the size of the header */
	size += sizeof (struct block_header); 
	for (order = 0;BLOCKSIZE(order);order++)
		if (size <= BLOCKSIZE (order))
			return order; 
	return -1;
}
Exemplo n.º 7
0
bool	List::Check(void* pData) const
{
    if ( !pData || pData < m_pData )  return false;

    char *pList = (char*)pData - LONGSIZE;

    if ( (pList-m_pData) %  BLOCKSIZE(m_nodesize) != 0 ||
            (pList-m_pData) /  BLOCKSIZE(m_nodesize) > (unsigned long)m_blockcount )
        return false;

    return true;
}
Exemplo n.º 8
0
static ssize_t block_read(struct cdev *cdev, void *buf, size_t count,
		unsigned long offset, unsigned long flags)
{
	struct block_device *blk = cdev->priv;
	unsigned long mask = BLOCKSIZE(blk) - 1;
	unsigned long block = offset >> blk->blockbits;
	size_t icount = count;
	int blocks;

	if (offset & mask) {
		size_t now = BLOCKSIZE(blk) - (offset & mask);
		void *iobuf = block_get(blk, block);

		now = min(count, now);

		if (IS_ERR(iobuf))
			return PTR_ERR(iobuf);

		memcpy(buf, iobuf + (offset & mask), now);
		buf += now;
		count -= now;
		block++;
	}

	blocks = count >> blk->blockbits;

	while (blocks) {
		void *iobuf = block_get(blk, block);

		if (IS_ERR(iobuf))
			return PTR_ERR(iobuf);

		memcpy(buf, iobuf, BLOCKSIZE(blk));
		buf += BLOCKSIZE(blk);
		blocks--;
		block++;
		count -= BLOCKSIZE(blk);
	}

	if (count) {
		void *iobuf = block_get(blk, block);

		if (IS_ERR(iobuf))
			return PTR_ERR(iobuf);

		memcpy(buf, iobuf, count);
	}

	return icount;
}
Exemplo n.º 9
0
void    List::Init()
{
    long  size = BLOCKSIZE(m_nodesize) * m_blockcount ;
    m_pData = (char*) VirtualAlloc(NULL,size,MEM_COMMIT,PAGE_READWRITE);

    assert( m_pData );

    char* pData = m_pData ;
    for ( long i = 0 ; i < m_blockcount ; i++ )
    {
        *( long * )pData = (i+1);
        pData += BLOCKSIZE(m_nodesize) ;
    }
}
Exemplo n.º 10
0
pointer bmalloc2(int size) {

  int i, fit;
  pointer block, buddy;

  for (fit = 0; BLOCKSIZE(fit) < size; fit++)
    ;

  if (freelists[fit]) {
    block = freelists[fit];
    freelists[fit] = *(pointer*) freelists[fit];

    return block;
  }

  i = fit;
  while (freelists[i] == NULL) {
    i++;
    if (i >= sizes)
      return NULL;
  }

  block = freelists[i];
  while (i > fit) {
    i--;
    buddy = BUDDYOF(block, i);
    freelists[i] = buddy;
  }

  return block;
}
Exemplo n.º 11
0
Arquivo: buddy.c Projeto: Jiant/buddy
pointer bmalloc(int size) {

  int i, order;
  pointer block, buddy;

  // calculate minimal order for this size
  i = 0;
  while (BLOCKSIZE(i) < size + 1) // one more byte for storing order
    i++;

  order = i = (i < MIN_ORDER) ? MIN_ORDER : i;

  // level up until non-null list found
  for (;; i++) {
    if (i > MAX_ORDER)
      return NULL;
    if (BUDDY->freelist[i])
      break;
  }

  // remove the block out of list
  block = BUDDY->freelist[i];
  BUDDY->freelist[i] = *(pointer*) BUDDY->freelist[i];

  // split until i == order
  while (i-- > order) {
    buddy = BUDDYOF(block, i);
    BUDDY->freelist[i] = buddy;
  }

  // store order in previous byte
  *((uint8_t*) (block - 1)) = order;
  return block;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// init_sequences
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void init_sequences()
{

	extern Sequence_Wrapper g_sequences;

	// Local Variables
	SystemParameters    sysParams;
    char filename[100];

    gdk_threads_enter();    // Get GDK lock
    int     Br = BITRATE();
    int     Bs = BLOCKSIZE();
    char*   Fn = SEQFILENAME();
    int     Fs = FS();
    gdk_threads_leave();    // Release GDK lock

    // Set up system parameters
    sysParams.setSamplingRate(Fs);
    sysParams.setBlockSize(Bs);
	sysParams.setBitRate(Br);


	// Set up the sequences!
    g_snprintf(filename,100,"../res/%s",Fn);
	g_sequences.setSystemParameters(&sysParams);
	g_sequences.load_sequences_from_file(filename);
	g_sequences.print_sequences();

}
Exemplo n.º 13
0
Arquivo: buddy.c Projeto: Jiant/buddy
static int total_free() {

  int i, bytecount = 0;

  for (i = 0; i <= MAX_ORDER; i++) {
    bytecount += count_blocks(i) * BLOCKSIZE(i);
  }
  return bytecount;
}
Exemplo n.º 14
0
uint32_t _get_free_inode_addr(struct ext2_disk *disk) {
    uint16_t *inode_map = (uint16_t *) &disk->bytes[BLOCKSIZE(disk->superblock) * disk->block_groups[0]->inode_usage_map_bn];
    uint32_t i;
    for (i = 0; i < disk->superblock->num_inodes_per_group; i++) {
        if ((*inode_map & (1 << i)) == 0) {
            return i + 1;
        }
    }
    return 0;
}
Exemplo n.º 15
0
void init_kmalloc( void )
{
	int order;
	
	memset( kmalloc_cache, 0, sizeof( kmalloc_cache ) );

/*
 * Check the static info array. Things will blow up terribly if it's
 * incorrect. This is a late "compile time" check.....
 */
	for ( order = 0; BLOCKSIZE( order ); order++ )
	{
		if ( ( NBLOCKS( order ) * BLOCKSIZE( order ) + sizeof( struct page_descriptor ) ) > AREASIZE( order ) )
		{
			printk( "Cannot use %d bytes out of %d in order = %d block mallocs\n", ( int )( NBLOCKS( order ) * BLOCKSIZE( order ) + sizeof( struct page_descriptor ) ), ( int )AREASIZE( order ), BLOCKSIZE( order ) );
			panic( "This only happens if someone messes with kmalloc" );
		}
	}
//      return start_mem;
}
Exemplo n.º 16
0
int ext2_write_data(struct ext2_disk *disk, struct ext2_inode *file, FILE *source_file) {
    int total_bytes = 0;

    int i;
    for (i = 0; i < 12; i++) {
        void *dest = &disk->bytes[BLOCKSIZE(disk->superblock) * file->direct_blocks[i]];
        size_t bytes_read = fread(dest, (size_t) BLOCKSIZE(disk->superblock), 1, source_file);
        total_bytes += bytes_read;

        // Set block as in-use
        uint16_t *block_map = (uint16_t *) &disk->bytes[BLOCKSIZE(disk->superblock) * disk->block_groups[0]->block_usage_map_bn];
        *block_map |= 1 << file->direct_blocks[i];

        if (bytes_read < BLOCKSIZE(disk->superblock)) {
            break;
        }
    }

    return total_bytes;
}
Exemplo n.º 17
0
bool    List::Free(void *pData)
{
    char *pList = (char*)pData - LONGSIZE;

    *(long*)pList = m_firstblock;

    m_firstblock = ( pList - m_pData ) / BLOCKSIZE(m_nodesize);

    ++ m_validsize ;

    return true;
}
Exemplo n.º 18
0
/**
 * Get the next directory entry.
 */
struct ext2_directory_entry *_next_directory_entry(struct ext2_disk *disk, uint32_t data_block_num, struct ext2_directory_entry *prev) {
    unsigned long byte_addr;
    if (prev == NULL) {
        byte_addr = BLOCKSIZE(disk->superblock) * data_block_num;
    } else {
        // Take `prev` byte address relative to the beginning of the file and add its size with the name,
        // rounding up to a multiple of 4
        byte_addr = ((uintptr_t) prev) - ((uintptr_t) disk->bytes) + (sizeof(prev) + prev->name_length + 3) & ~0x03;
    }

    return (struct ext2_directory_entry *) &disk->bytes[byte_addr];
}
Exemplo n.º 19
0
void*   List::Allocator()
{
    if( m_validsize <= 0 ) return NULL;

    char *pRet = m_pData + ( m_firstblock * BLOCKSIZE(m_nodesize) );

    m_firstblock = *(long*)pRet ;

    --m_validsize;

    *(long*)pRet = m_nodesize;

    return pRet + LONGSIZE ;
}
Exemplo n.º 20
0
long kmalloc_init (long start_mem,long end_mem)
{
	int order;

/* 
 * Check the static info array. Things will blow up terribly if it's
 * incorrect. This is a late "compile time" check.....
 */
for (order = 0;BLOCKSIZE(order);order++)
    {
    if ((NBLOCKS (order)*BLOCKSIZE(order) + sizeof (struct page_descriptor)) >
        PAGE_SIZE) 
        {
        printk ("Cannot use %d bytes out of %d in order = %d block mallocs\n",
                NBLOCKS (order) * BLOCKSIZE(order) + 
                        sizeof (struct page_descriptor),
                (int) PAGE_SIZE,
                BLOCKSIZE (order));
        panic ("This only happens if someone messes with kmalloc");
        }
    }
return start_mem;
}
Exemplo n.º 21
0
void bfree(pointer block, int size) {
  int i;
  pointer * p;
  pointer buddy;

  /* compute i as the least integer such that i >= log2(size) */
  for (i = 0; BLOCKSIZE( i ) < size; i++)
    ;

  /* see if this block's buddy is free */
  buddy = BUDDYOF(block, i);
  p = &freelists[i];
  while ((*p != NULL) && (*p != buddy))
    p = (pointer *) *p;

  if (*p != buddy) {

    /* buddy not free, put block on its free list */
    *(pointer *) block = freelists[i];
    freelists[i] = block;

  }
  else {

    /* buddy found, remove it from its free list */
    *p = *(pointer *) buddy;

    /* deallocate the block and its buddy as one block */
    if (block > buddy) {
      bfree(buddy, BLOCKSIZE(i + 1));
    }
    else {
      bfree(block, BLOCKSIZE(i + 1));
    }
  }
}
Exemplo n.º 22
0
hcell *hopc_gc_alloc_chunk(hopc_runtime *runtime, htag tag) {
    hcell *top = runtime->gc.top;
    hcell *end = runtime->gc.heapend_p;
    hword_t ts = hopc_tagsize(runtime, tag);
    hword_t size = BLOCKSIZE(ts);
    memchunk *chunk = 0;
    if( end - top >= size ) {
        runtime->gc.top += size;
        chunk = (memchunk*)(top + ts);
        chunk->t.gc_alive = 0;
        chunk->t.gc_follow = 1;
        chunk->t.tag = tag;
/*        fprintf(stderr, "allocated: %08X %d %d %04X free: %d\n", chunk, size, hopc_tagsize(runtime, tag), tag, (runtime->gc.heapend_p - runtime->gc.top));*/
        return (hcell*)chunk;
    }
    hopc_out_of_mem_hook(runtime);
    return (hcell*)0;
}
Exemplo n.º 23
0
int main(int argc, char *argv[]) {
    char *disk_image_path;
    char *target_file_name;
    struct ext2_disk *disk;

    if (argc != 3) {
        errx(1, "USAGE: ext2_rm <disk_image> <target_file>\n");
    }

    disk_image_path = argv[1];
    target_file_name = argv[2];

    // Read the disk from file
    disk = ext2_read_disk(disk_image_path);

    // Ensure the superblock has a block size of 1024 bytes (since it's always 1024 in this assignment)
    assert(BLOCKSIZE(disk->superblock) == 1024);

    // Perform the remove operation
    ext2_rm(disk, target_file_name);

    return 0;
}
Exemplo n.º 24
0
int blockdevice_register(struct block_device *blk)
{
	size_t size = blk->num_blocks * BLOCKSIZE(blk);
	int ret;

	blk->cdev.size = size;
	blk->cdev.dev = blk->dev;
	blk->cdev.ops = &block_ops;
	blk->cdev.priv = blk;
	blk->rdbufsize = PAGE_SIZE >> blk->blockbits;
	blk->rdbuf = xmalloc(PAGE_SIZE);
	blk->rdblock = 1;
	blk->rdblockend = 0;
	blk->wrbufsize = PAGE_SIZE >> blk->blockbits;
	blk->wrbuf = xmalloc(PAGE_SIZE);
	blk->wrblock = 0;
	blk->wrbufblocks = 0;

	ret = devfs_create(&blk->cdev);
	if (ret)
		return ret;

	return 0;
}
Exemplo n.º 25
0
static int df_read (void)
{
#if HAVE_STATVFS
	struct statvfs statbuf;
#elif HAVE_STATFS
	struct statfs statbuf;
#endif
	/* struct STATANYFS statbuf; */
	cu_mount_t *mnt_list;
	cu_mount_t *mnt_ptr;

	mnt_list = NULL;
	if (cu_mount_getlist (&mnt_list) == NULL)
	{
		ERROR ("df plugin: cu_mount_getlist failed.");
		return (-1);
	}

	for (mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next)
	{
		unsigned long long blocksize;
		char disk_name[256];
		uint64_t blk_free;
		uint64_t blk_reserved;
		uint64_t blk_used;

		char const *dev = (mnt_ptr->spec_device != NULL)
			? mnt_ptr->spec_device
			: mnt_ptr->device;

		if (ignorelist_match (il_device, dev))
			continue;
		if (ignorelist_match (il_mountpoint, mnt_ptr->dir))
			continue;
		if (ignorelist_match (il_fstype, mnt_ptr->type))
			continue;

		if (STATANYFS (mnt_ptr->dir, &statbuf) < 0)
		{
			char errbuf[1024];
			ERROR (STATANYFS_STR"(%s) failed: %s",
					mnt_ptr->dir,
					sstrerror (errno, errbuf,
						sizeof (errbuf)));
			continue;
		}

		if (!statbuf.f_blocks)
			continue;

		if (by_device)
		{
			/* eg, /dev/hda1  -- strip off the "/dev/" */
			if (strncmp (dev, "/dev/", strlen ("/dev/")) == 0)
				sstrncpy (disk_name, dev + strlen ("/dev/"), sizeof (disk_name));
			else
				sstrncpy (disk_name, dev, sizeof (disk_name));

			if (strlen(disk_name) < 1)
			{
				DEBUG("df: no device name for mountpoint %s, skipping", mnt_ptr->dir);
				continue;
			}
		}
		else
		{
			if (strcmp (mnt_ptr->dir, "/") == 0)
			{
				if (strcmp (mnt_ptr->type, "rootfs") == 0)
					continue;
				sstrncpy (disk_name, "root", sizeof (disk_name));
			}
			else
			{
				int i, len;

				sstrncpy (disk_name, mnt_ptr->dir + 1, sizeof (disk_name));
				len = strlen (disk_name);

				for (i = 0; i < len; i++)
					if (disk_name[i] == '/')
						disk_name[i] = '-';
			}
		}

		blocksize = BLOCKSIZE(statbuf);

		/*
		 * Sanity-check for the values in the struct
		 */
		/* Check for negative "available" byes. For example UFS can
		 * report negative free space for user. Notice. blk_reserved
		 * will start to diminish after this. */
#if HAVE_STATVFS
		/* Cast and temporary variable are needed to avoid
		 * compiler warnings.
		 * ((struct statvfs).f_bavail is unsigned (POSIX)) */
		int64_t signed_bavail = (int64_t) statbuf.f_bavail;
		if (signed_bavail < 0)
			statbuf.f_bavail = 0;
#elif HAVE_STATFS
		if (statbuf.f_bavail < 0)
			statbuf.f_bavail = 0;
#endif
		/* Make sure that f_blocks >= f_bfree >= f_bavail */
		if (statbuf.f_bfree < statbuf.f_bavail)
			statbuf.f_bfree = statbuf.f_bavail;
		if (statbuf.f_blocks < statbuf.f_bfree)
			statbuf.f_blocks = statbuf.f_bfree;

		blk_free     = (uint64_t) statbuf.f_bavail;
		blk_reserved = (uint64_t) (statbuf.f_bfree - statbuf.f_bavail);
		blk_used     = (uint64_t) (statbuf.f_blocks - statbuf.f_bfree);

		if (values_absolute)
		{
			df_submit_one (disk_name, "df_complex", "free",
				(gauge_t) (blk_free * blocksize));
			df_submit_one (disk_name, "df_complex", "reserved",
				(gauge_t) (blk_reserved * blocksize));
			df_submit_one (disk_name, "df_complex", "used",
				(gauge_t) (blk_used * blocksize));
		}

		if (values_percentage)
		{
			if (statbuf.f_blocks > 0)
				{
				df_submit_one (disk_name, "percent_bytes", "free",
					(gauge_t) ((float_t)(blk_free) / statbuf.f_blocks * 100));
				df_submit_one (disk_name, "percent_bytes", "reserved",
					(gauge_t) ((float_t)(blk_reserved) / statbuf.f_blocks * 100));
				df_submit_one (disk_name, "percent_bytes", "used",
					(gauge_t) ((float_t)(blk_used) / statbuf.f_blocks * 100));
				}
			else return (-1);
		}

		/* inode handling */
		if (report_inodes && statbuf.f_files != 0 && statbuf.f_ffree != 0)
		{
			uint64_t inode_free;
			uint64_t inode_reserved;
			uint64_t inode_used;

			/* Sanity-check for the values in the struct */
			if (statbuf.f_ffree < statbuf.f_favail)
				statbuf.f_ffree = statbuf.f_favail;
			if (statbuf.f_files < statbuf.f_ffree)
				statbuf.f_files = statbuf.f_ffree;

			inode_free = (uint64_t) statbuf.f_favail;
			inode_reserved = (uint64_t) (statbuf.f_ffree - statbuf.f_favail);
			inode_used = (uint64_t) (statbuf.f_files - statbuf.f_ffree);

			if (values_percentage)
			{
				if (statbuf.f_files > 0)
				{
					df_submit_one (disk_name, "percent_inodes", "free",
						(gauge_t) ((float_t)(inode_free) / statbuf.f_files * 100));
					df_submit_one (disk_name, "percent_inodes", "reserved",
						(gauge_t) ((float_t)(inode_reserved) / statbuf.f_files * 100));
					df_submit_one (disk_name, "percent_inodes", "used",
						(gauge_t) ((float_t)(inode_used) / statbuf.f_files * 100));
				}
				else return (-1);
			}
			if (values_absolute)
			{
				df_submit_one (disk_name, "df_inodes", "free",
						(gauge_t) inode_free);
				df_submit_one (disk_name, "df_inodes", "reserved",
						(gauge_t) inode_reserved);
				df_submit_one (disk_name, "df_inodes", "used",
						(gauge_t) inode_used);
			}
		}
	}

	cu_mount_freelist (mnt_list);

	return (0);
} /* int df_read */
Exemplo n.º 26
0
Arquivo: df.c Projeto: johnl/collectd
static int df_read (void)
{
#if HAVE_STATVFS
	struct statvfs statbuf;
#elif HAVE_STATFS
	struct statfs statbuf;
#endif
	/* struct STATANYFS statbuf; */
	cu_mount_t *mnt_list;
	cu_mount_t *mnt_ptr;

	unsigned long long blocksize;
	gauge_t df_free;
	gauge_t df_used;
	char mnt_name[256];

	mnt_list = NULL;
	if (cu_mount_getlist (&mnt_list) == NULL)
		return (-1);

	for (mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next)
	{
		if (STATANYFS (mnt_ptr->dir, &statbuf) < 0)
		{
			char errbuf[1024];
			ERROR ("statv?fs failed: %s",
					sstrerror (errno, errbuf,
						sizeof (errbuf)));
			continue;
		}

		if (!statbuf.f_blocks)
			continue;

		blocksize = BLOCKSIZE(statbuf);
		df_free = statbuf.f_bfree * blocksize;
		df_used = (statbuf.f_blocks - statbuf.f_bfree) * blocksize;

		if (strcmp (mnt_ptr->dir, "/") == 0)
		{
			sstrncpy (mnt_name, "root", sizeof (mnt_name));
		}
		else
		{
			int i, len;

			sstrncpy (mnt_name, mnt_ptr->dir + 1, sizeof (mnt_name));
			len = strlen (mnt_name);

			for (i = 0; i < len; i++)
				if (mnt_name[i] == '/')
					mnt_name[i] = '-';
		}

		if (ignorelist_match (il_device,
					(mnt_ptr->spec_device != NULL)
					? mnt_ptr->spec_device
					: mnt_ptr->device))
			continue;
		if (ignorelist_match (il_mountpoint, mnt_ptr->dir))
			continue;
		if (ignorelist_match (il_fstype, mnt_ptr->type))
			continue;

		df_submit (mnt_name, df_used, df_free);
	}

	cu_mount_freelist (mnt_list);

	return (0);
} /* int df_read */
Exemplo n.º 27
0
void * kmalloc (size_t size, int priority)
{
	unsigned long flags;
	int order,tries,i,sz;
	struct block_header *p;
	struct page_descriptor *page;

/* Sanity check... */
	if (intr_count && priority != GFP_ATOMIC) {
		static int count = 0;
		if (++count < 5) {
			printk("kmalloc called nonatomically from interrupt %08lx\n",
				((unsigned long *)&size)[-1]);
			priority = GFP_ATOMIC;
		}
	}
if (size > MAX_KMALLOC_K * 1024) 
     {
     printk ("kmalloc: I refuse to allocate %d bytes (for now max = %d).\n",
                size,MAX_KMALLOC_K*1024);
     return (NULL);
     }

order = get_order (size);
if (order < 0)
    {
    printk ("kmalloc of too large a block (%d bytes).\n",size);
    return (NULL);
    }

save_flags(flags);

/* It seems VERY unlikely to me that it would be possible that this 
   loop will get executed more than once. */
tries = MAX_GET_FREE_PAGE_TRIES; 
while (tries --)
    {
    /* Try to allocate a "recently" freed memory block */
    cli ();
    if ((page = sizes[order].firstfree) &&
        (p    =  page->firstfree))
        {
        if (p->bh_flags == MF_FREE)
            {
            page->firstfree = p->bh_next;
            page->nfree--;
            if (!page->nfree)
                {
                sizes[order].firstfree = page->next;
                page->next = NULL;
                }
            restore_flags(flags);

            sizes [order].nmallocs++;
            sizes [order].nbytesmalloced += size;
            p->bh_flags =  MF_USED; /* As of now this block is officially in use */
            p->bh_length = size;
            return p+1; /* Pointer arithmetic: increments past header */
            }
        printk ("Problem: block on freelist at %08lx isn't free.\n",(long)p);
        return (NULL);
        }
    restore_flags(flags);


    /* Now we're in trouble: We need to get a new free page..... */

    sz = BLOCKSIZE(order); /* sz is the size of the blocks we're dealing with */

    /* This can be done with ints on: This is private to this invocation */
    page = (struct page_descriptor *) __get_free_page (priority & GFP_LEVEL_MASK);
    if (!page) {
        static unsigned long last = 0;
        if (last + 10*HZ < jiffies) {
        	last = jiffies;
	        printk ("Couldn't get a free page.....\n");
	}
        return NULL;
    }
#if 0
    printk ("Got page %08x to use for %d byte mallocs....",(long)page,sz);
#endif
    sizes[order].npages++;

    /* Loop for all but last block: */
    for (i=NBLOCKS(order),p=BH (page+1);i > 1;i--,p=p->bh_next) 
        {
        p->bh_flags = MF_FREE;
        p->bh_next = BH ( ((long)p)+sz);
        }
    /* Last block: */
    p->bh_flags = MF_FREE;
    p->bh_next = NULL;

    page->order = order;
    page->nfree = NBLOCKS(order); 
    page->firstfree = BH(page+1);
#if 0
    printk ("%d blocks per page\n",page->nfree);
#endif
    /* Now we're going to muck with the "global" freelist for this size:
       this should be uniterruptible */
    cli ();
    /* 
     * sizes[order].firstfree used to be NULL, otherwise we wouldn't be
     * here, but you never know.... 
     */
    page->next = sizes[order].firstfree;
    sizes[order].firstfree = page;
    restore_flags(flags);
    }

/* Pray that printk won't cause this to happen again :-) */

printk ("Hey. This is very funny. I tried %d times to allocate a whole\n"
        "new page for an object only %d bytes long, but some other process\n"
        "beat me to actually allocating it. Also note that this 'error'\n"
        "message is soooo very long to catch your attention. I'd appreciate\n"
        "it if you'd be so kind as to report what conditions caused this to\n"
        "the author of this kmalloc: [email protected].\n"
        "(Executive summary: This can't happen)\n", 
                MAX_GET_FREE_PAGE_TRIES,
                size);
return NULL;
}
Exemplo n.º 28
0
memchunk* hopc_gc_prev_chunk(hopc_runtime *r, memchunk *p) {
    return  p - BLOCKSIZE(hopc_tagsize(r, p->t.tag));
}
Exemplo n.º 29
0
/*
 * Ugh, this is ugly, but we want the default case to run
 * straight through, which is why we have the ugly goto's
 */
void *kmalloc(size_t size, int priority)
{
	unsigned long flags;
	unsigned long type;
	int order, dma;
	struct block_header *p;
	struct page_descriptor *page, **pg;
	struct size_descriptor *bucket = sizes;

	/* Get order */
	order = 0;
	{
		unsigned int realsize = size + sizeof(struct block_header);
		for (;;) {
			int ordersize = BLOCKSIZE(order);
			if (realsize <= ordersize)
				break;
			order++;
			bucket++;
			if (ordersize)
				continue;
			printk("kmalloc of too large a block (%d bytes).\n", (int) size);
			return NULL;
		}
	}

	dma = 0;
	type = MF_USED;
	pg = &bucket->firstfree;
	if (priority & GFP_DMA) {
		dma = 1;
		type = MF_DMA;
		pg = &bucket->dmafree;
	}

	priority &= GFP_LEVEL_MASK;

/* Sanity check... */
	if (intr_count && priority != GFP_ATOMIC) {
		static int count = 0;
		if (++count < 5) {
			printk("kmalloc called nonatomically from interrupt %p\n",
			       __builtin_return_address(0));
			priority = GFP_ATOMIC;
		}
	}

	save_flags(flags);
	cli();
	page = *pg;
	if (!page)
		goto no_bucket_page;

	p = page->firstfree;
	if (p->bh_flags != MF_FREE)
		goto not_free_on_freelist;

found_it:
	page->firstfree = p->bh_next;
	page->nfree--;
	if (!page->nfree)
		*pg = page->next;
	restore_flags(flags);
	bucket->nmallocs++;
	bucket->nbytesmalloced += size;
	p->bh_flags = type;	/* As of now this block is officially in use */
	p->bh_length = size;
#ifdef SADISTIC_KMALLOC
	memset(p+1, 0xf0, size);
#endif
	return p + 1;		/* Pointer arithmetic: increments past header */


no_bucket_page:
	/*
	 * If we didn't find a page already allocated for this
	 * bucket size, we need to get one..
	 *
	 * This can be done with ints on: it is private to this invocation
	 */
	restore_flags(flags);

	{
		int i, realpages;
		
		if (BLOCKSIZE(order) < PAGE_SIZE)
			realpages = 1;
		else
			realpages = NUM_PAGES(size + sizeof(struct block_header) +
					sizeof(struct page_descriptor));
			
		page = get_kmalloc_pages(priority, realpages, dma);
		if (!page)
			goto no_free_page;
found_cached_page:

		bucket->npages++;

		page->order = order | (realpages * PAGE_SIZE);
		/* Loop for all but last block: */
		i = (page->nfree = bucket->nblocks) - 1;
		p = BH(page + 1);
		while (i > 0) { /* doesn't happen except for small ^2 mallocs */
			i--;
			p->bh_flags = MF_FREE;
			p->bh_next = BH(((long) p) + BLOCKSIZE(order));
			p = p->bh_next;
		}
		/* Last block: */
		p->bh_flags = MF_FREE;
		p->bh_next = NULL;

		p = BH(page+1);
	}

	/*
	 * Now we're going to muck with the "global" freelist
	 * for this size: this should be uninterruptible
	 */
	cli();
	page->next = *pg;
	*pg = page;
	goto found_it;


no_free_page:
	/*
	 * No free pages, check the kmalloc cache of
	 * pages to see if maybe we have something available
	 */
	if (!dma && order < MAX_CACHE_ORDER) {
		page = xchg(kmalloc_cache+order, page);
		if (page)
			goto found_cached_page;
	}
	{
		static unsigned long last = 0;
		if (priority != GFP_BUFFER && priority != GFP_IO &&
		    (last + 10 * HZ < jiffies)) {
			last = jiffies;
			printk("Couldn't get a free page.....\n");
		}
		return NULL;
	}

not_free_on_freelist:
	restore_flags(flags);
	printk("Problem: block on freelist at %08lx isn't free.\n", (long) p);
	return NULL;
}
Exemplo n.º 30
0
/*
 * Ugh, this is ugly, but we want the default case to run
 * straight through, which is why we have the ugly goto's
 */
void *kmalloc( size_t size, int priority )
{
	unsigned long flags;
	unsigned long type;
	int order, dma;
	struct block_header *p;
	struct page_descriptor *page, **pg;
	struct size_descriptor *bucket = sizes;

	if ( CURRENT_THREAD != NULL && CURRENT_THREAD->tr_nNumLockedCacheBlocks > 0 && ( priority & MEMF_NOBLOCK ) == 0 )
	{
		//printk( "Error: kmalloc() attempt to alloc memory while holding %d cache blocks locked. Could may lead to deadlock\n", CURRENT_THREAD->tr_nNumLockedCacheBlocks );
		//trace_stack( 0, NULL );
	}
	/* Get order */
	order = 0;
	{
		unsigned int realsize = size + sizeof( struct block_header );

		// kmalloc() is inefficient for allocations >= 128K
		//if ( realsize > BLOCKSIZE( 12 ) )
		//{
		//	printk( "Warning: kmalloc() of oversized block (%d bytes). Could cause fragmentation problems\n", size );
		//	trace_stack( 0, NULL );
		//}

		for ( ;; )
		{
			int ordersize = BLOCKSIZE( order );

			if ( realsize <= ordersize )
				break;
			order++;
			bucket++;
			if ( ordersize )
				continue;
			printk( "kmalloc of too large a block (%d bytes).\n", ( int )size );
			return NULL;
		}
	}

	dma = 0;
	type = MF_USED;
	pg = &bucket->firstfree;

#ifndef __ATHEOS__
	if ( priority & GFP_DMA )
	{
		dma = 1;
		type = MF_DMA;
		pg = &bucket->dmafree;
	}
#endif

/* Sanity check... */

	flags = spinlock_disable( &g_sMemSpinLock );
	page = *pg;
	if ( !page )
		goto no_bucket_page;

	p = page->firstfree;

	if ( p->bh_flags != MF_FREE )
		goto not_free_on_freelist;

      found_it:
	page->firstfree = p->bh_next;

	page->nfree--;
	if ( !page->nfree )
		*pg = page->next;

	spinunlock_enable( &g_sMemSpinLock, flags );
	bucket->nmallocs++;
	bucket->nbytesmalloced += size;
	p->bh_flags = type;	/* As of now this block is officially in use */
	p->bh_length = size;

	memset( p +1, 0, size );

	atomic_add( &g_sSysBase.ex_nKernelMemSize, size );
	return ( p +1 );	/* Pointer arithmetic: increments past header */


      no_bucket_page:
	/*
	 * If we didn't find a page already allocated for this
	 * bucket size, we need to get one..
	 *
	 * This can be done with ints on: it is private to this invocation
	 */
	spinunlock_enable( &g_sMemSpinLock, flags );

	{
		int i, sz;

		/* sz is the size of the blocks we're dealing with */
		sz = BLOCKSIZE( order );

		page = get_kmalloc_pages( priority, bucket->gfporder, dma );
		if ( !page )
			goto no_free_page;
	      found_cached_page:
		bucket->npages++;

		page->order = order;
		/* Loop for all but last block: */
		i = ( page->nfree = bucket->nblocks ) - 1;
		p = BH( page + 1 );

		while ( i > 0 )
		{
			i--;
			p->bh_flags = MF_FREE;
			p->bh_next = BH( ( ( long )p )+sz );
			p = p->bh_next;
		}
		/* Last block: */
		p->bh_flags = MF_FREE;
		p->bh_next = NULL;

		p = BH( page + 1 );
	}

	/*
	 * Now we're going to muck with the "global" freelist
	 * for this size: this should be uninterruptible
	 */
	flags = spinlock_disable( &g_sMemSpinLock );
	page->next = *pg;
	*pg = page;
	goto found_it;


      no_free_page:
	/*
	 * No free pages, check the kmalloc cache of
	 * pages to see if maybe we have something available
	 */
	if ( !dma && order < MAX_CACHE_ORDER )
	{
		page = ( struct page_descriptor * )atomic_swap( ( int * )( kmalloc_cache + order ), ( int )page );
		if ( page )
		{
			goto found_cached_page;
		}
	}
	return NULL;


      not_free_on_freelist:
	spinunlock_enable( &g_sMemSpinLock, flags );
	printk( "Problem: block on freelist at %08lx isn't free.\n", ( long )p );
	printk( "%p\n%p\n%p\n", __builtin_return_address( 0 ), __builtin_return_address( 1 ), __builtin_return_address( 2 ) );
	return NULL;
}