/* NUMA */ INIT_LIST_HEAD(&cachep->lists.slabs_full); INIT_LIST_HEAD(&cachep->lists.slabs_partial); INIT_LIST_HEAD(&cachep->lists.slabs_free); 
kmem_cache_create (const char *name, size_t size, size_t align,	unsigned long flags, void (*ctor)(void*, kmem_cache_t *, unsigned long),	void (*dtor)(void*, kmem_cache_t *, unsigned long)){	size_t left_over, slab_size, ralign;	kmem_cache_t *cachep = NULL;	/*	 * Sanity checks... these are all serious usage bugs.	 */	if ((!name) ||		in_interrupt() ||		(size < BYTES_PER_WORD) ||		(size > (1<<MAX_OBJ_ORDER)*PAGE_SIZE) ||		(dtor && !ctor)) {			printk(KERN_ERR "%s: Early error in slab %s\n",					__FUNCTION__, name);			BUG();		}#if DEBUG	WARN_ON(strchr(name, ' '));	/* It confuses parsers */	if ((flags & SLAB_DEBUG_INITIAL) && !ctor) {		/* No constructor, but inital state check requested */		printk(KERN_ERR "%s: No con, but init state check "				"requested - %s\n", __FUNCTION__, name);		flags &= ~SLAB_DEBUG_INITIAL;	}#if FORCED_DEBUG	/*	 * Enable redzoning and last user accounting, except for caches with	 * large objects, if the increased size would increase the object size	 * above the next power of two: caches with object sizes just above a	 * power of two have a significant amount of internal fragmentation.	 */	if ((size < 4096 || fls(size-1) == fls(size-1+3*BYTES_PER_WORD)))		flags |= SLAB_RED_ZONE|SLAB_STORE_USER;	if (!(flags & SLAB_DESTROY_BY_RCU))		flags |= SLAB_POISON;#endif	if (flags & SLAB_DESTROY_BY_RCU)		BUG_ON(flags & SLAB_POISON);#endif	if (flags & SLAB_DESTROY_BY_RCU)		BUG_ON(dtor);	/*	 * Always checks flags, a caller might be expecting debug	 * support which isn't available.	 */	if (flags & ~CREATE_MASK)		BUG();	/* Check that size is in terms of words.  This is needed to avoid	 * unaligned accesses for some archs when redzoning is used, and makes	 * sure any on-slab bufctl's are also correctly aligned.	 */	if (size & (BYTES_PER_WORD-1)) {		size += (BYTES_PER_WORD-1);		size &= ~(BYTES_PER_WORD-1);	}	/* calculate out the final buffer alignment: */	/* 1) arch recommendation: can be overridden for debug */	if (flags & SLAB_HWCACHE_ALIGN) {		/* Default alignment: as specified by the arch code.		 * Except if an object is really small, then squeeze multiple		 * objects into one cacheline.		 */		ralign = cache_line_size();		while (size <= ralign/2)			ralign /= 2;	} else {		ralign = BYTES_PER_WORD;	}	/* 2) arch mandated alignment: disables debug if necessary */	if (ralign < ARCH_SLAB_MINALIGN) {		ralign = ARCH_SLAB_MINALIGN;		if (ralign > BYTES_PER_WORD)			flags &= ~(SLAB_RED_ZONE|SLAB_STORE_USER);	}	/* 3) caller mandated alignment: disables debug if necessary */	if (ralign < align) {		ralign = align;		if (ralign > BYTES_PER_WORD)			flags &= ~(SLAB_RED_ZONE|SLAB_STORE_USER);	}	/* 4) Store it. Note that the debug code below can reduce	 *    the alignment to BYTES_PER_WORD.	 */	align = ralign;	/* Get cache's description obj. */	cachep = (kmem_cache_t *) kmem_cache_alloc(&cache_cache, SLAB_KERNEL);	if (!cachep)		goto opps;	memset(cachep, 0, sizeof(kmem_cache_t));#if DEBUG	cachep->reallen = size;	if (flags & SLAB_RED_ZONE) {		/* redzoning only works with word aligned caches */		align = BYTES_PER_WORD;		/* add space for red zone words */		cachep->dbghead += BYTES_PER_WORD;		size += 2*BYTES_PER_WORD;	}	if (flags & SLAB_STORE_USER) {		/* user store requires word alignment and		 * one word storage behind the end of the real		 * object.		 */		align = BYTES_PER_WORD;		size += BYTES_PER_WORD;	}#if FORCED_DEBUG && defined(CONFIG_DEBUG_PAGEALLOC)	if (size > 128 && cachep->reallen > cache_line_size() && size < PAGE_SIZE) {		cachep->dbghead += PAGE_SIZE - size;		size = PAGE_SIZE;	}#endif#endif	/* Determine if the slab management is 'on' or 'off' slab. */	if (size >= (PAGE_SIZE>>3))		/*		 * Size is large, assume best to place the slab management obj		 * off-slab (should allow better packing of objs).		 */		flags |= CFLGS_OFF_SLAB;	size = ALIGN(size, align);	if ((flags & SLAB_RECLAIM_ACCOUNT) && size <= PAGE_SIZE) {		/*		 * A VFS-reclaimable slab tends to have most allocations		 * as GFP_NOFS and we really don't want to have to be allocating		 * higher-order pages when we are unable to shrink dcache.		 */		cachep->gfporder = 0;		cache_estimate(cachep->gfporder, size, align, flags,					&left_over, &cachep->num);	} else {		/*		 * Calculate size (in pages) of slabs, and the num of objs per		 * slab.  This could be made much more intelligent.  For now,		 * try to avoid using high page-orders for slabs.  When the		 * gfp() funcs are more friendly towards high-order requests,		 * this should be changed.		 */		do {			unsigned int break_flag = 0;cal_wastage:			cache_estimate(cachep->gfporder, size, align, flags,						&left_over, &cachep->num);			if (break_flag)				break;			if (cachep->gfporder >= MAX_GFP_ORDER)				break;			if (!cachep->num)				goto next;			if (flags & CFLGS_OFF_SLAB &&					cachep->num > offslab_limit) {				/* This num of objs will cause problems. */				cachep->gfporder--;				break_flag++;				goto cal_wastage;			}			/*			 * Large num of objs is good, but v. large slabs are			 * currently bad for the gfp()s.			 */			if (cachep->gfporder >= slab_break_gfp_order)				break;			if ((left_over*8) <= (PAGE_SIZE<<cachep->gfporder))				break;	/* Acceptable internal fragmentation. */next:			cachep->gfporder++;		} while (1);	}	if (!cachep->num) {		printk("kmem_cache_create: couldn't create cache %s.\n", name);		kmem_cache_free(&cache_cache, cachep);		cachep = NULL;		goto opps;	}	slab_size = ALIGN(cachep->num*sizeof(kmem_bufctl_t)				+ sizeof(struct slab), align);	/*	 * If the slab has been placed off-slab, and we have enough space then	 * move it on-slab. This is at the expense of any extra colouring.	 */	if (flags & CFLGS_OFF_SLAB && left_over >= slab_size) {		flags &= ~CFLGS_OFF_SLAB;		left_over -= slab_size;	}	if (flags & CFLGS_OFF_SLAB) {		/* really off slab. No need for manual alignment */		slab_size = cachep->num*sizeof(kmem_bufctl_t)+sizeof(struct slab);	}	cachep->colour_off = cache_line_size();	/* Offset must be a multiple of the alignment. */	if (cachep->colour_off < align)		cachep->colour_off = align;	cachep->colour = left_over/cachep->colour_off;	cachep->slab_size = slab_size;	cachep->flags = flags;	cachep->gfpflags = 0;	if (flags & SLAB_CACHE_DMA)		cachep->gfpflags |= GFP_DMA;	spin_lock_init(&cachep->spinlock);	cachep->objsize = size;	/* NUMA */	INIT_LIST_HEAD(&cachep->lists.slabs_full);	INIT_LIST_HEAD(&cachep->lists.slabs_partial);	INIT_LIST_HEAD(&cachep->lists.slabs_free);	if (flags & CFLGS_OFF_SLAB)		cachep->slabp_cache = kmem_find_general_cachep(slab_size,0);	cachep->ctor = ctor;	cachep->dtor = dtor;	cachep->name = name;	/* Don't let CPUs to come and go */	lock_cpu_hotplug();	if (g_cpucache_up == FULL) {		enable_cpucache(cachep);	} else {		if (g_cpucache_up == NONE) {			/* Note: the first kmem_cache_create must create			 * the cache that's used by kmalloc(24), otherwise			 * the creation of further caches will BUG().			 */			cachep->array[smp_processor_id()] = &initarray_generic.cache;			g_cpucache_up = PARTIAL;		} else {			cachep->array[smp_processor_id()] = kmalloc(sizeof(struct arraycache_init),GFP_KERNEL);		}		BUG_ON(!ac_data(cachep));		ac_data(cachep)->avail = 0;		ac_data(cachep)->limit = BOOT_CPUCACHE_ENTRIES;		ac_data(cachep)->batchcount = 1;		ac_data(cachep)->touched = 0;		cachep->batchcount = 1;		cachep->limit = BOOT_CPUCACHE_ENTRIES;		cachep->free_limit = (1+num_online_cpus())*cachep->batchcount					+ cachep->num;	} 	cachep->lists.next_reap = jiffies + REAPTIMEOUT_LIST3 +					((unsigned long)cachep)%REAPTIMEOUT_LIST3;	/* Need the semaphore to access the chain. */	down(&cache_chain_sem);	{		struct list_head *p;		mm_segment_t old_fs;		old_fs = get_fs();		set_fs(KERNEL_DS);		list_for_each(p, &cache_chain) {			kmem_cache_t *pc = list_entry(p, kmem_cache_t, next);			char tmp;			/* This happens when the module gets unloaded and doesn't			   destroy its slab cache and noone else reuses the vmalloc			   area of the module. Print a warning. */			if (__get_user(tmp,pc->name)) { 				printk("SLAB: cache with size %d has lost its name\n", 					pc->objsize); 				continue; 			} 				if (!strcmp(pc->name,name)) { 				printk("kmem_cache_create: duplicate cache %s\n",name); 				up(&cache_chain_sem); 				unlock_cpu_hotplug();				BUG(); 			}			}		set_fs(old_fs);	}	/* cache setup completed, link it into the list */	list_add(&cachep->next, &cache_chain);	up(&cache_chain_sem);	unlock_cpu_hotplug();opps:	if (!cachep && (flags & SLAB_PANIC))		panic("kmem_cache_create(): failed to create slab `%s'\n",			name);	return cachep;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/e498be7dafd72fd68848c1eef1575aa7c5d658df/slab.c/clean/mm/slab.c