Re: Simple example of using slab allocator?

2001-06-19 Thread Andreas Dilger

Matthew Dharm writes:
> Well, if it's really that simple
> 
> Another aspect of this, tho, is that I'd like to be able to profile my
> memory usage.  Does the SA have any ability to report (easily) the number
> of pages allocated and how full each one is?

Then "cat /proc/slabinfo" is your friend.  It lists currently allocated
objects, maximum objects that will fit in the current allocated pages,
size of object, pages used if objects were tightly packed, real pages
used, and pages per slab.

On SMP systems it also lists the number of slab cache objects kept
local to each CPU to avoid global locking when they need to allocate.

Cheers, Andreas

> On Mon, Jun 18, 2001 at 10:56:36AM -0600, Andreas Dilger wrote:
> > The slab allocator IS dead simple to use, basically:
> > 
> > - driver global variable:
> > 
> > kmem_cache_t *usb_mass_cachep;
> > 
> > - in the driver init function:
> > 
> > usb_mass_cachep = kmem_cache_create("usb_mass_cache",
> > sizeof(struct whatever),
> > 0, SLAB_HWCACHE_ALIGN,
> > NULL, NULL);
> > (check for NULL usb_mass_slab)
> > 
> > - in the driver cleanup function:
> > 
> > if (usb_mass_cachep && kmem_cache_destroy(usb_mass_cachep))
> > printk(KERN_ERR "usb_mass_cache: not all structures freed\n");
> > 
> > - wherever you need an item from the slab cache:
> > 
> > whateverp = kmem_cache_alloc(usb_mass_cachep, GFP_KERNEL);
> > (check for NULL whateverp)
> > 
> > - when you are done with it:
> > 
> > kmem_cache_free(usb_mass_cachep, whateverp);
> > 
> > Notes:
> > - if you have a slab leak and you don't free all of the items (hence the slab
> >   cache is not removed), you will probably get an oops when you reload the
> >   driver.  You can only have one slab cache per name ("usb_mass_cache" here).
> > - You may need different alignment (SLAB_HWCACHE_ALIGN), or not
> > - You may need different allocation policy (GFP_KERNEL), or not
-- 
Andreas Dilger  \ "If a man ate a pound of pasta and a pound of antipasto,
 \  would they cancel out, leaving him still hungry?"
http://www-mddsp.enel.ucalgary.ca/People/adilger/   -- Dogbert
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/



Re: Simple example of using slab allocator?

2001-06-19 Thread Andreas Dilger

Matthew Dharm writes:
 Well, if it's really that simple
 
 Another aspect of this, tho, is that I'd like to be able to profile my
 memory usage.  Does the SA have any ability to report (easily) the number
 of pages allocated and how full each one is?

Then cat /proc/slabinfo is your friend.  It lists currently allocated
objects, maximum objects that will fit in the current allocated pages,
size of object, pages used if objects were tightly packed, real pages
used, and pages per slab.

On SMP systems it also lists the number of slab cache objects kept
local to each CPU to avoid global locking when they need to allocate.

Cheers, Andreas

 On Mon, Jun 18, 2001 at 10:56:36AM -0600, Andreas Dilger wrote:
  The slab allocator IS dead simple to use, basically:
  
  - driver global variable:
  
  kmem_cache_t *usb_mass_cachep;
  
  - in the driver init function:
  
  usb_mass_cachep = kmem_cache_create(usb_mass_cache,
  sizeof(struct whatever),
  0, SLAB_HWCACHE_ALIGN,
  NULL, NULL);
  (check for NULL usb_mass_slab)
  
  - in the driver cleanup function:
  
  if (usb_mass_cachep  kmem_cache_destroy(usb_mass_cachep))
  printk(KERN_ERR usb_mass_cache: not all structures freed\n);
  
  - wherever you need an item from the slab cache:
  
  whateverp = kmem_cache_alloc(usb_mass_cachep, GFP_KERNEL);
  (check for NULL whateverp)
  
  - when you are done with it:
  
  kmem_cache_free(usb_mass_cachep, whateverp);
  
  Notes:
  - if you have a slab leak and you don't free all of the items (hence the slab
cache is not removed), you will probably get an oops when you reload the
driver.  You can only have one slab cache per name (usb_mass_cache here).
  - You may need different alignment (SLAB_HWCACHE_ALIGN), or not
  - You may need different allocation policy (GFP_KERNEL), or not
-- 
Andreas Dilger  \ If a man ate a pound of pasta and a pound of antipasto,
 \  would they cancel out, leaving him still hungry?
http://www-mddsp.enel.ucalgary.ca/People/adilger/   -- Dogbert
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/



Re: Simple example of using slab allocator?

2001-06-18 Thread Matthew Dharm

Well, if it's really that simple

Another aspect of this, tho, is that I'd like to be able to profile my
memory usage.  Does the SA have any ability to report (easily) the number
of pages allocated and how full each one is?

Matt Dharm

On Mon, Jun 18, 2001 at 10:56:36AM -0600, Andreas Dilger wrote:
> Matthew Dharm writes:
> > For 2.5, I'm planning on switching my driver over to the slab allocator,
> > for a variety of reasons.  Does anyone have a _dead_ simple example of how
> > to use such a beast?  I've seen the various web pages and document
> > explaining the API, but I love to see working examples for reference (and
> > to fill in the blanks).
> 
> The slab allocator IS dead simple to use, basically:
> 
> - driver global variable:
> 
> kmem_cache_t *usb_mass_cachep;
>   
> - in the driver init function:
> 
>   usb_mass_cachep = kmem_cache_create("usb_mass_cache",
>   sizeof(struct whatever),
>   0, SLAB_HWCACHE_ALIGN,
>   NULL, NULL);
>   (check for NULL usb_mass_slab)
> 
> - in the driver cleanup function:
> 
>   if (usb_mass_cachep && kmem_cache_destroy(usb_mass_cachep))
>   printk(KERN_ERR "usb_mass_cache: not all structures freed\n");
> 
> - wherever you need an item from the slab cache:
> 
>   whateverp = kmem_cache_alloc(usb_mass_cachep, GFP_KERNEL);
>   (check for NULL whateverp)
> 
> - when you are done with it:
> 
>   kmem_cache_free(usb_mass_cachep, whateverp);
> 
> Notes:
> - if you have a slab leak and you don't free all of the items (hence the slab
>   cache is not removed), you will probably get an oops when you reload the
>   driver.  You can only have one slab cache per name ("usb_mass_cache" here).
> - You may need different alignment (SLAB_HWCACHE_ALIGN), or not
> - You may need different allocation policy (GFP_KERNEL), or not
> 
> Cheers, Andreas
> -- 
> Andreas Dilger  \ "If a man ate a pound of pasta and a pound of antipasto,
>  \  would they cancel out, leaving him still hungry?"
> http://www-mddsp.enel.ucalgary.ca/People/adilger/   -- Dogbert

-- 
Matthew Dharm  Home: [EMAIL PROTECTED] 
Maintainer, Linux USB Mass Storage Driver

God, root, what is difference?
-- Pitr
User Friendly, 11/11/1999

 PGP signature


Re: Simple example of using slab allocator?

2001-06-18 Thread Andreas Dilger

Matthew Dharm writes:
> For 2.5, I'm planning on switching my driver over to the slab allocator,
> for a variety of reasons.  Does anyone have a _dead_ simple example of how
> to use such a beast?  I've seen the various web pages and document
> explaining the API, but I love to see working examples for reference (and
> to fill in the blanks).

The slab allocator IS dead simple to use, basically:

- driver global variable:

kmem_cache_t *usb_mass_cachep;

- in the driver init function:

usb_mass_cachep = kmem_cache_create("usb_mass_cache",
sizeof(struct whatever),
0, SLAB_HWCACHE_ALIGN,
NULL, NULL);
(check for NULL usb_mass_slab)

- in the driver cleanup function:

if (usb_mass_cachep && kmem_cache_destroy(usb_mass_cachep))
printk(KERN_ERR "usb_mass_cache: not all structures freed\n");

- wherever you need an item from the slab cache:

whateverp = kmem_cache_alloc(usb_mass_cachep, GFP_KERNEL);
(check for NULL whateverp)

- when you are done with it:

kmem_cache_free(usb_mass_cachep, whateverp);

Notes:
- if you have a slab leak and you don't free all of the items (hence the slab
  cache is not removed), you will probably get an oops when you reload the
  driver.  You can only have one slab cache per name ("usb_mass_cache" here).
- You may need different alignment (SLAB_HWCACHE_ALIGN), or not
- You may need different allocation policy (GFP_KERNEL), or not

Cheers, Andreas
-- 
Andreas Dilger  \ "If a man ate a pound of pasta and a pound of antipasto,
 \  would they cancel out, leaving him still hungry?"
http://www-mddsp.enel.ucalgary.ca/People/adilger/   -- Dogbert
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/



Re: Simple example of using slab allocator?

2001-06-18 Thread Andreas Dilger

Matthew Dharm writes:
 For 2.5, I'm planning on switching my driver over to the slab allocator,
 for a variety of reasons.  Does anyone have a _dead_ simple example of how
 to use such a beast?  I've seen the various web pages and document
 explaining the API, but I love to see working examples for reference (and
 to fill in the blanks).

The slab allocator IS dead simple to use, basically:

- driver global variable:

kmem_cache_t *usb_mass_cachep;

- in the driver init function:

usb_mass_cachep = kmem_cache_create(usb_mass_cache,
sizeof(struct whatever),
0, SLAB_HWCACHE_ALIGN,
NULL, NULL);
(check for NULL usb_mass_slab)

- in the driver cleanup function:

if (usb_mass_cachep  kmem_cache_destroy(usb_mass_cachep))
printk(KERN_ERR usb_mass_cache: not all structures freed\n);

- wherever you need an item from the slab cache:

whateverp = kmem_cache_alloc(usb_mass_cachep, GFP_KERNEL);
(check for NULL whateverp)

- when you are done with it:

kmem_cache_free(usb_mass_cachep, whateverp);

Notes:
- if you have a slab leak and you don't free all of the items (hence the slab
  cache is not removed), you will probably get an oops when you reload the
  driver.  You can only have one slab cache per name (usb_mass_cache here).
- You may need different alignment (SLAB_HWCACHE_ALIGN), or not
- You may need different allocation policy (GFP_KERNEL), or not

Cheers, Andreas
-- 
Andreas Dilger  \ If a man ate a pound of pasta and a pound of antipasto,
 \  would they cancel out, leaving him still hungry?
http://www-mddsp.enel.ucalgary.ca/People/adilger/   -- Dogbert
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/



Re: Simple example of using slab allocator?

2001-06-18 Thread Matthew Dharm

Well, if it's really that simple

Another aspect of this, tho, is that I'd like to be able to profile my
memory usage.  Does the SA have any ability to report (easily) the number
of pages allocated and how full each one is?

Matt Dharm

On Mon, Jun 18, 2001 at 10:56:36AM -0600, Andreas Dilger wrote:
 Matthew Dharm writes:
  For 2.5, I'm planning on switching my driver over to the slab allocator,
  for a variety of reasons.  Does anyone have a _dead_ simple example of how
  to use such a beast?  I've seen the various web pages and document
  explaining the API, but I love to see working examples for reference (and
  to fill in the blanks).
 
 The slab allocator IS dead simple to use, basically:
 
 - driver global variable:
 
 kmem_cache_t *usb_mass_cachep;
   
 - in the driver init function:
 
   usb_mass_cachep = kmem_cache_create(usb_mass_cache,
   sizeof(struct whatever),
   0, SLAB_HWCACHE_ALIGN,
   NULL, NULL);
   (check for NULL usb_mass_slab)
 
 - in the driver cleanup function:
 
   if (usb_mass_cachep  kmem_cache_destroy(usb_mass_cachep))
   printk(KERN_ERR usb_mass_cache: not all structures freed\n);
 
 - wherever you need an item from the slab cache:
 
   whateverp = kmem_cache_alloc(usb_mass_cachep, GFP_KERNEL);
   (check for NULL whateverp)
 
 - when you are done with it:
 
   kmem_cache_free(usb_mass_cachep, whateverp);
 
 Notes:
 - if you have a slab leak and you don't free all of the items (hence the slab
   cache is not removed), you will probably get an oops when you reload the
   driver.  You can only have one slab cache per name (usb_mass_cache here).
 - You may need different alignment (SLAB_HWCACHE_ALIGN), or not
 - You may need different allocation policy (GFP_KERNEL), or not
 
 Cheers, Andreas
 -- 
 Andreas Dilger  \ If a man ate a pound of pasta and a pound of antipasto,
  \  would they cancel out, leaving him still hungry?
 http://www-mddsp.enel.ucalgary.ca/People/adilger/   -- Dogbert

-- 
Matthew Dharm  Home: [EMAIL PROTECTED] 
Maintainer, Linux USB Mass Storage Driver

God, root, what is difference?
-- Pitr
User Friendly, 11/11/1999

 PGP signature


Simple example of using slab allocator?

2001-06-15 Thread Matthew Dharm

For 2.5, I'm planning on switching my driver over to the slab allocator,
for a variety of reasons.  Does anyone have a _dead_ simple example of how
to use such a beast?  I've seen the various web pages and document
explaining the API, but I love to see working examples for reference (and
to fill in the blanks).

Matt

-- 
Matthew Dharm  Home: [EMAIL PROTECTED] 
Maintainer, Linux USB Mass Storage Driver

Okay, this isn't funny anymore! Let me down!  I'll tell Bill on you!!
-- Microsoft Salesman
User Friendly, 4/1/1998

 PGP signature


Simple example of using slab allocator?

2001-06-15 Thread Matthew Dharm

For 2.5, I'm planning on switching my driver over to the slab allocator,
for a variety of reasons.  Does anyone have a _dead_ simple example of how
to use such a beast?  I've seen the various web pages and document
explaining the API, but I love to see working examples for reference (and
to fill in the blanks).

Matt

-- 
Matthew Dharm  Home: [EMAIL PROTECTED] 
Maintainer, Linux USB Mass Storage Driver

Okay, this isn't funny anymore! Let me down!  I'll tell Bill on you!!
-- Microsoft Salesman
User Friendly, 4/1/1998

 PGP signature