···3030 - description of page migration in NUMA systems.3131pagemap.txt3232 - pagemap, from the userspace perspective3333-slabinfo.c3434- - source code for a tool to get reports about slabs.3533slub.txt3634 - a short users guide for SLUB.3735unevictable-lru.txt
+13-1
include/linux/mm_types.h
···7979 };80808181 /* Third double word block */8282- struct list_head lru; /* Pageout list, eg. active_list8282+ union {8383+ struct list_head lru; /* Pageout list, eg. active_list8384 * protected by zone->lru_lock !8485 */8686+ struct { /* slub per cpu partial pages */8787+ struct page *next; /* Next partial slab */8888+#ifdef CONFIG_64BIT8989+ int pages; /* Nr of partial slabs left */9090+ int pobjects; /* Approximate # of objects */9191+#else9292+ short int pages;9393+ short int pobjects;9494+#endif9595+ };9696+ };85978698 /* Remainder is not double word aligned */8799 union {
+4
include/linux/slub_def.h
···3636 ORDER_FALLBACK, /* Number of times fallback was necessary */3737 CMPXCHG_DOUBLE_CPU_FAIL,/* Failure of this_cpu_cmpxchg_double */3838 CMPXCHG_DOUBLE_FAIL, /* Number of times that cmpxchg double did not match */3939+ CPU_PARTIAL_ALLOC, /* Used cpu partial on alloc */4040+ CPU_PARTIAL_FREE, /* USed cpu partial on free */3941 NR_SLUB_STAT_ITEMS };40424143struct kmem_cache_cpu {4244 void **freelist; /* Pointer to next available object */4345 unsigned long tid; /* Globally unique transaction id */4446 struct page *page; /* The slab from which we are allocating */4747+ struct page *partial; /* Partially allocated frozen slabs */4548 int node; /* The node of the page (or -1 for debug) */4649#ifdef CONFIG_SLUB_STATS4750 unsigned stat[NR_SLUB_STAT_ITEMS];···8279 int size; /* The size of an object including meta data */8380 int objsize; /* The size of an object without meta data */8481 int offset; /* Free pointer offset. */8282+ int cpu_partial; /* Number of per cpu partial objects to keep around */8583 struct kmem_cache_order_objects oo;86848785 /* Allocation and freeing of slabs */
+7-12
mm/slab.c
···18511851 unsigned char error = 0;18521852 int bad_count = 0;1853185318541854- printk(KERN_ERR "%03x:", offset);18541854+ printk(KERN_ERR "%03x: ", offset);18551855 for (i = 0; i < limit; i++) {18561856 if (data[offset + i] != POISON_FREE) {18571857 error = data[offset + i];18581858 bad_count++;18591859 }18601860- printk(" %02x", (unsigned char)data[offset + i]);18611860 }18621862- printk("\n");18611861+ print_hex_dump(KERN_CONT, "", 0, 16, 1,18621862+ &data[offset], limit, 1);1863186318641864 if (bad_count == 1) {18651865 error ^= POISON_FREE;···30393039 printk(KERN_ERR "slab: Internal list corruption detected in "30403040 "cache '%s'(%d), slabp %p(%d). Hexdump:\n",30413041 cachep->name, cachep->num, slabp, slabp->inuse);30423042- for (i = 0;30433043- i < sizeof(*slabp) + cachep->num * sizeof(kmem_bufctl_t);30443044- i++) {30453045- if (i % 16 == 0)30463046- printk("\n%03x:", i);30473047- printk(" %02x", ((unsigned char *)slabp)[i]);30483048- }30493049- printk("\n");30423042+ print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, slabp,30433043+ sizeof(*slabp) + cachep->num * sizeof(kmem_bufctl_t),30443044+ 1);30503045 BUG();30513046 }30523047}···4579458445804585static int __init slab_proc_init(void)45814586{45824582- proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);45874587+ proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);45834588#ifdef CONFIG_DEBUG_SLAB_LEAK45844589 proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);45854590#endif
+392-166
mm/slub.c
···467467 */468468static void print_section(char *text, u8 *addr, unsigned int length)469469{470470- int i, offset;471471- int newline = 1;472472- char ascii[17];473473-474474- ascii[16] = 0;475475-476476- for (i = 0; i < length; i++) {477477- if (newline) {478478- printk(KERN_ERR "%8s 0x%p: ", text, addr + i);479479- newline = 0;480480- }481481- printk(KERN_CONT " %02x", addr[i]);482482- offset = i % 16;483483- ascii[offset] = isgraph(addr[i]) ? addr[i] : '.';484484- if (offset == 15) {485485- printk(KERN_CONT " %s\n", ascii);486486- newline = 1;487487- }488488- }489489- if (!newline) {490490- i %= 16;491491- while (i < 16) {492492- printk(KERN_CONT " ");493493- ascii[i] = ' ';494494- i++;495495- }496496- printk(KERN_CONT " %s\n", ascii);497497- }470470+ print_hex_dump(KERN_ERR, text, DUMP_PREFIX_ADDRESS, 16, 1, addr,471471+ length, 1);498472}499473500474static struct track *get_track(struct kmem_cache *s, void *object,···599625 p, p - addr, get_freepointer(s, p));600626601627 if (p > addr + 16)602602- print_section("Bytes b4", p - 16, 16);628628+ print_section("Bytes b4 ", p - 16, 16);603629604604- print_section("Object", p, min_t(unsigned long, s->objsize, PAGE_SIZE));605605-630630+ print_section("Object ", p, min_t(unsigned long, s->objsize,631631+ PAGE_SIZE));606632 if (s->flags & SLAB_RED_ZONE)607607- print_section("Redzone", p + s->objsize,633633+ print_section("Redzone ", p + s->objsize,608634 s->inuse - s->objsize);609635610636 if (s->offset)···617643618644 if (off != s->size)619645 /* Beginning of the filler is the free pointer */620620- print_section("Padding", p + off, s->size - off);646646+ print_section("Padding ", p + off, s->size - off);621647622648 dump_stack();623649}···812838 end--;813839814840 slab_err(s, page, "Padding overwritten. 0x%p-0x%p", fault, end - 1);815815- print_section("Padding", end - remainder, remainder);841841+ print_section("Padding ", end - remainder, remainder);816842817843 restore_bytes(s, "slab padding", POISON_INUSE, end - remainder, end);818844 return 0;···961987 page->freelist);962988963989 if (!alloc)964964- print_section("Object", (void *)object, s->objsize);990990+ print_section("Object ", (void *)object, s->objsize);965991966992 dump_stack();967993 }···14211447 set_freepointer(s, last, NULL);1422144814231449 page->freelist = start;14241424- page->inuse = 0;14501450+ page->inuse = page->objects;14251451 page->frozen = 1;14261452out:14271453 return page;···15081534 struct page *page, int tail)15091535{15101536 n->nr_partial++;15111511- if (tail)15371537+ if (tail == DEACTIVATE_TO_TAIL)15121538 list_add_tail(&page->lru, &n->partial);15131539 else15141540 list_add(&page->lru, &n->partial);···15281554 * Lock slab, remove from the partial list and put the object into the15291555 * per cpu freelist.15301556 *15571557+ * Returns a list of objects or NULL if it fails.15581558+ *15311559 * Must hold list_lock.15321560 */15331533-static inline int acquire_slab(struct kmem_cache *s,15341534- struct kmem_cache_node *n, struct page *page)15611561+static inline void *acquire_slab(struct kmem_cache *s,15621562+ struct kmem_cache_node *n, struct page *page,15631563+ int mode)15351564{15361565 void *freelist;15371566 unsigned long counters;···15491572 freelist = page->freelist;15501573 counters = page->counters;15511574 new.counters = counters;15521552- new.inuse = page->objects;15751575+ if (mode)15761576+ new.inuse = page->objects;1553157715541578 VM_BUG_ON(new.frozen);15551579 new.frozen = 1;···15611583 "lock and freeze"));1562158415631585 remove_partial(n, page);15641564-15651565- if (freelist) {15661566- /* Populate the per cpu freelist */15671567- this_cpu_write(s->cpu_slab->freelist, freelist);15681568- this_cpu_write(s->cpu_slab->page, page);15691569- this_cpu_write(s->cpu_slab->node, page_to_nid(page));15701570- return 1;15711571- } else {15721572- /*15731573- * Slab page came from the wrong list. No object to allocate15741574- * from. Put it onto the correct list and continue partial15751575- * scan.15761576- */15771577- printk(KERN_ERR "SLUB: %s : Page without available objects on"15781578- " partial list\n", s->name);15791579- return 0;15801580- }15861586+ return freelist;15811587}15881588+15891589+static int put_cpu_partial(struct kmem_cache *s, struct page *page, int drain);1582159015831591/*15841592 * Try to allocate a partial slab from a specific node.15851593 */15861586-static struct page *get_partial_node(struct kmem_cache *s,15871587- struct kmem_cache_node *n)15941594+static void *get_partial_node(struct kmem_cache *s,15951595+ struct kmem_cache_node *n, struct kmem_cache_cpu *c)15881596{15891589- struct page *page;15971597+ struct page *page, *page2;15981598+ void *object = NULL;1590159915911600 /*15921601 * Racy check. If we mistakenly see no partial slabs then we···15851620 return NULL;1586162115871622 spin_lock(&n->list_lock);15881588- list_for_each_entry(page, &n->partial, lru)15891589- if (acquire_slab(s, n, page))15901590- goto out;15911591- page = NULL;15921592-out:16231623+ list_for_each_entry_safe(page, page2, &n->partial, lru) {16241624+ void *t = acquire_slab(s, n, page, object == NULL);16251625+ int available;16261626+16271627+ if (!t)16281628+ break;16291629+16301630+ if (!object) {16311631+ c->page = page;16321632+ c->node = page_to_nid(page);16331633+ stat(s, ALLOC_FROM_PARTIAL);16341634+ object = t;16351635+ available = page->objects - page->inuse;16361636+ } else {16371637+ page->freelist = t;16381638+ available = put_cpu_partial(s, page, 0);16391639+ }16401640+ if (kmem_cache_debug(s) || available > s->cpu_partial / 2)16411641+ break;16421642+16431643+ }15931644 spin_unlock(&n->list_lock);15941594- return page;16451645+ return object;15951646}1596164715971648/*15981649 * Get a page from somewhere. Search in increasing NUMA distances.15991650 */16001600-static struct page *get_any_partial(struct kmem_cache *s, gfp_t flags)16511651+static struct page *get_any_partial(struct kmem_cache *s, gfp_t flags,16521652+ struct kmem_cache_cpu *c)16011653{16021654#ifdef CONFIG_NUMA16031655 struct zonelist *zonelist;16041656 struct zoneref *z;16051657 struct zone *zone;16061658 enum zone_type high_zoneidx = gfp_zone(flags);16071607- struct page *page;16591659+ void *object;1608166016091661 /*16101662 * The defrag ratio allows a configuration of the tradeoffs between···1654167216551673 if (n && cpuset_zone_allowed_hardwall(zone, flags) &&16561674 n->nr_partial > s->min_partial) {16571657- page = get_partial_node(s, n);16581658- if (page) {16751675+ object = get_partial_node(s, n, c);16761676+ if (object) {16591677 put_mems_allowed();16601660- return page;16781678+ return object;16611679 }16621680 }16631681 }···16691687/*16701688 * Get a partial page, lock it and return it.16711689 */16721672-static struct page *get_partial(struct kmem_cache *s, gfp_t flags, int node)16901690+static void *get_partial(struct kmem_cache *s, gfp_t flags, int node,16911691+ struct kmem_cache_cpu *c)16731692{16741674- struct page *page;16931693+ void *object;16751694 int searchnode = (node == NUMA_NO_NODE) ? numa_node_id() : node;1676169516771677- page = get_partial_node(s, get_node(s, searchnode));16781678- if (page || node != NUMA_NO_NODE)16791679- return page;16961696+ object = get_partial_node(s, get_node(s, searchnode), c);16971697+ if (object || node != NUMA_NO_NODE)16981698+ return object;1680169916811681- return get_any_partial(s, flags);17001700+ return get_any_partial(s, flags, c);16821701}1683170216841703#ifdef CONFIG_PREEMPT···17481765 for_each_possible_cpu(cpu)17491766 per_cpu_ptr(s->cpu_slab, cpu)->tid = init_tid(cpu);17501767}17511751-/*17521752- * Remove the cpu slab17531753- */1754176817551769/*17561770 * Remove the cpu slab···17611781 enum slab_modes l = M_NONE, m = M_NONE;17621782 void *freelist;17631783 void *nextfree;17641764- int tail = 0;17841784+ int tail = DEACTIVATE_TO_HEAD;17651785 struct page new;17661786 struct page old;1767178717681788 if (page->freelist) {17691789 stat(s, DEACTIVATE_REMOTE_FREES);17701770- tail = 1;17901790+ tail = DEACTIVATE_TO_TAIL;17711791 }1772179217731793 c->tid = next_tid(c->tid);···18731893 if (m == M_PARTIAL) {1874189418751895 add_partial(n, page, tail);18761876- stat(s, tail ? DEACTIVATE_TO_TAIL : DEACTIVATE_TO_HEAD);18961896+ stat(s, tail);1877189718781898 } else if (m == M_FULL) {18791899···19001920 }19011921}1902192219231923+/* Unfreeze all the cpu partial slabs */19241924+static void unfreeze_partials(struct kmem_cache *s)19251925+{19261926+ struct kmem_cache_node *n = NULL;19271927+ struct kmem_cache_cpu *c = this_cpu_ptr(s->cpu_slab);19281928+ struct page *page;19291929+19301930+ while ((page = c->partial)) {19311931+ enum slab_modes { M_PARTIAL, M_FREE };19321932+ enum slab_modes l, m;19331933+ struct page new;19341934+ struct page old;19351935+19361936+ c->partial = page->next;19371937+ l = M_FREE;19381938+19391939+ do {19401940+19411941+ old.freelist = page->freelist;19421942+ old.counters = page->counters;19431943+ VM_BUG_ON(!old.frozen);19441944+19451945+ new.counters = old.counters;19461946+ new.freelist = old.freelist;19471947+19481948+ new.frozen = 0;19491949+19501950+ if (!new.inuse && (!n || n->nr_partial > s->min_partial))19511951+ m = M_FREE;19521952+ else {19531953+ struct kmem_cache_node *n2 = get_node(s,19541954+ page_to_nid(page));19551955+19561956+ m = M_PARTIAL;19571957+ if (n != n2) {19581958+ if (n)19591959+ spin_unlock(&n->list_lock);19601960+19611961+ n = n2;19621962+ spin_lock(&n->list_lock);19631963+ }19641964+ }19651965+19661966+ if (l != m) {19671967+ if (l == M_PARTIAL)19681968+ remove_partial(n, page);19691969+ else19701970+ add_partial(n, page, 1);19711971+19721972+ l = m;19731973+ }19741974+19751975+ } while (!cmpxchg_double_slab(s, page,19761976+ old.freelist, old.counters,19771977+ new.freelist, new.counters,19781978+ "unfreezing slab"));19791979+19801980+ if (m == M_FREE) {19811981+ stat(s, DEACTIVATE_EMPTY);19821982+ discard_slab(s, page);19831983+ stat(s, FREE_SLAB);19841984+ }19851985+ }19861986+19871987+ if (n)19881988+ spin_unlock(&n->list_lock);19891989+}19901990+19911991+/*19921992+ * Put a page that was just frozen (in __slab_free) into a partial page19931993+ * slot if available. This is done without interrupts disabled and without19941994+ * preemption disabled. The cmpxchg is racy and may put the partial page19951995+ * onto a random cpus partial slot.19961996+ *19971997+ * If we did not find a slot then simply move all the partials to the19981998+ * per node partial list.19991999+ */20002000+int put_cpu_partial(struct kmem_cache *s, struct page *page, int drain)20012001+{20022002+ struct page *oldpage;20032003+ int pages;20042004+ int pobjects;20052005+20062006+ do {20072007+ pages = 0;20082008+ pobjects = 0;20092009+ oldpage = this_cpu_read(s->cpu_slab->partial);20102010+20112011+ if (oldpage) {20122012+ pobjects = oldpage->pobjects;20132013+ pages = oldpage->pages;20142014+ if (drain && pobjects > s->cpu_partial) {20152015+ unsigned long flags;20162016+ /*20172017+ * partial array is full. Move the existing20182018+ * set to the per node partial list.20192019+ */20202020+ local_irq_save(flags);20212021+ unfreeze_partials(s);20222022+ local_irq_restore(flags);20232023+ pobjects = 0;20242024+ pages = 0;20252025+ }20262026+ }20272027+20282028+ pages++;20292029+ pobjects += page->objects - page->inuse;20302030+20312031+ page->pages = pages;20322032+ page->pobjects = pobjects;20332033+ page->next = oldpage;20342034+20352035+ } while (this_cpu_cmpxchg(s->cpu_slab->partial, oldpage, page) != oldpage);20362036+ stat(s, CPU_PARTIAL_FREE);20372037+ return pobjects;20382038+}20392039+19032040static inline void flush_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)19042041{19052042 stat(s, CPUSLAB_FLUSH);···20321935{20331936 struct kmem_cache_cpu *c = per_cpu_ptr(s->cpu_slab, cpu);2034193720352035- if (likely(c && c->page))20362036- flush_slab(s, c);19381938+ if (likely(c)) {19391939+ if (c->page)19401940+ flush_slab(s, c);19411941+19421942+ unfreeze_partials(s);19431943+ }20371944}2038194520391946static void flush_cpu_slab(void *d)···21282027 }21292028}2130202920302030+static inline void *new_slab_objects(struct kmem_cache *s, gfp_t flags,20312031+ int node, struct kmem_cache_cpu **pc)20322032+{20332033+ void *object;20342034+ struct kmem_cache_cpu *c;20352035+ struct page *page = new_slab(s, flags, node);20362036+20372037+ if (page) {20382038+ c = __this_cpu_ptr(s->cpu_slab);20392039+ if (c->page)20402040+ flush_slab(s, c);20412041+20422042+ /*20432043+ * No other reference to the page yet so we can20442044+ * muck around with it freely without cmpxchg20452045+ */20462046+ object = page->freelist;20472047+ page->freelist = NULL;20482048+20492049+ stat(s, ALLOC_SLAB);20502050+ c->node = page_to_nid(page);20512051+ c->page = page;20522052+ *pc = c;20532053+ } else20542054+ object = NULL;20552055+20562056+ return object;20572057+}20582058+21312059/*21322060 * Slow path. The lockless freelist is empty or we need to perform21332061 * debugging duties.21342134- *21352135- * Interrupts are disabled.21362062 *21372063 * Processing is still very fast if new objects have been freed to the21382064 * regular freelist. In that case we simply take over the regular freelist···21772049 unsigned long addr, struct kmem_cache_cpu *c)21782050{21792051 void **object;21802180- struct page *page;21812052 unsigned long flags;21822053 struct page new;21832054 unsigned long counters;···21912064 c = this_cpu_ptr(s->cpu_slab);21922065#endif2193206621942194- /* We handle __GFP_ZERO in the caller */21952195- gfpflags &= ~__GFP_ZERO;21962196-21972197- page = c->page;21982198- if (!page)20672067+ if (!c->page)21992068 goto new_slab;22002200-20692069+redo:22012070 if (unlikely(!node_match(c, node))) {22022071 stat(s, ALLOC_NODE_MISMATCH);22032072 deactivate_slab(s, c);···22032080 stat(s, ALLOC_SLOWPATH);2204208122052082 do {22062206- object = page->freelist;22072207- counters = page->counters;20832083+ object = c->page->freelist;20842084+ counters = c->page->counters;22082085 new.counters = counters;22092086 VM_BUG_ON(!new.frozen);22102087···22162093 *22172094 * If there are objects left then we retrieve them22182095 * and use them to refill the per cpu queue.22192219- */20962096+ */2220209722212221- new.inuse = page->objects;20982098+ new.inuse = c->page->objects;22222099 new.frozen = object != NULL;2223210022242224- } while (!__cmpxchg_double_slab(s, page,21012101+ } while (!__cmpxchg_double_slab(s, c->page,22252102 object, counters,22262103 NULL, new.counters,22272104 "__slab_alloc"));2228210522292229- if (unlikely(!object)) {21062106+ if (!object) {22302107 c->page = NULL;22312108 stat(s, DEACTIVATE_BYPASS);22322109 goto new_slab;···22352112 stat(s, ALLOC_REFILL);2236211322372114load_freelist:22382238- VM_BUG_ON(!page->frozen);22392115 c->freelist = get_freepointer(s, object);22402116 c->tid = next_tid(c->tid);22412117 local_irq_restore(flags);22422118 return object;2243211922442120new_slab:22452245- page = get_partial(s, gfpflags, node);22462246- if (page) {22472247- stat(s, ALLOC_FROM_PARTIAL);22482248- object = c->freelist;2249212122502250- if (kmem_cache_debug(s))22512251- goto debug;22522252- goto load_freelist;21222122+ if (c->partial) {21232123+ c->page = c->partial;21242124+ c->partial = c->page->next;21252125+ c->node = page_to_nid(c->page);21262126+ stat(s, CPU_PARTIAL_ALLOC);21272127+ c->freelist = NULL;21282128+ goto redo;22532129 }2254213022552255- page = new_slab(s, gfpflags, node);21312131+ /* Then do expensive stuff like retrieving pages from the partial lists */21322132+ object = get_partial(s, gfpflags, node, c);2256213322572257- if (page) {22582258- c = __this_cpu_ptr(s->cpu_slab);22592259- if (c->page)22602260- flush_slab(s, c);21342134+ if (unlikely(!object)) {2261213522622262- /*22632263- * No other reference to the page yet so we can22642264- * muck around with it freely without cmpxchg22652265- */22662266- object = page->freelist;22672267- page->freelist = NULL;22682268- page->inuse = page->objects;21362136+ object = new_slab_objects(s, gfpflags, node, &c);2269213722702270- stat(s, ALLOC_SLAB);22712271- c->node = page_to_nid(page);22722272- c->page = page;21382138+ if (unlikely(!object)) {21392139+ if (!(gfpflags & __GFP_NOWARN) && printk_ratelimit())21402140+ slab_out_of_memory(s, gfpflags, node);2273214122742274- if (kmem_cache_debug(s))22752275- goto debug;22762276- goto load_freelist;21422142+ local_irq_restore(flags);21432143+ return NULL;21442144+ }22772145 }22782278- if (!(gfpflags & __GFP_NOWARN) && printk_ratelimit())22792279- slab_out_of_memory(s, gfpflags, node);22802280- local_irq_restore(flags);22812281- return NULL;2282214622832283-debug:22842284- if (!object || !alloc_debug_processing(s, page, object, addr))22852285- goto new_slab;21472147+ if (likely(!kmem_cache_debug(s)))21482148+ goto load_freelist;21492149+21502150+ /* Only entered in the debug case */21512151+ if (!alloc_debug_processing(s, c->page, object, addr))21522152+ goto new_slab; /* Slab failed checks. Next slab needed */2286215322872154 c->freelist = get_freepointer(s, object);22882155 deactivate_slab(s, c);22892289- c->page = NULL;22902156 c->node = NUMA_NO_NODE;22912157 local_irq_restore(flags);22922158 return object;···24452333 was_frozen = new.frozen;24462334 new.inuse--;24472335 if ((!new.inuse || !prior) && !was_frozen && !n) {24482448- n = get_node(s, page_to_nid(page));24492449- /*24502450- * Speculatively acquire the list_lock.24512451- * If the cmpxchg does not succeed then we may24522452- * drop the list_lock without any processing.24532453- *24542454- * Otherwise the list_lock will synchronize with24552455- * other processors updating the list of slabs.24562456- */24572457- spin_lock_irqsave(&n->list_lock, flags);23362336+23372337+ if (!kmem_cache_debug(s) && !prior)23382338+23392339+ /*23402340+ * Slab was on no list before and will be partially empty23412341+ * We can defer the list move and instead freeze it.23422342+ */23432343+ new.frozen = 1;23442344+23452345+ else { /* Needs to be taken off a list */23462346+23472347+ n = get_node(s, page_to_nid(page));23482348+ /*23492349+ * Speculatively acquire the list_lock.23502350+ * If the cmpxchg does not succeed then we may23512351+ * drop the list_lock without any processing.23522352+ *23532353+ * Otherwise the list_lock will synchronize with23542354+ * other processors updating the list of slabs.23552355+ */23562356+ spin_lock_irqsave(&n->list_lock, flags);23572357+23582358+ }24582359 }24592360 inuse = new.inuse;24602361···24772352 "__slab_free"));2478235324792354 if (likely(!n)) {24802480- /*23552355+23562356+ /*23572357+ * If we just froze the page then put it onto the23582358+ * per cpu partial list.23592359+ */23602360+ if (new.frozen && !was_frozen)23612361+ put_cpu_partial(s, page, 1);23622362+23632363+ /*24812364 * The list lock was not taken therefore no list24822365 * activity can be necessary.24832366 */···25102377 */25112378 if (unlikely(!prior)) {25122379 remove_full(s, page);25132513- add_partial(n, page, 1);23802380+ add_partial(n, page, DEACTIVATE_TO_TAIL);25142381 stat(s, FREE_ADD_PARTIAL);25152382 }25162383 }···25542421 slab_free_hook(s, x);2555242225562423redo:25572557-25582424 /*25592425 * Determine the currently cpus per cpu slab.25602426 * The cpu may change afterward. However that does not matter since···28172685 n = page->freelist;28182686 BUG_ON(!n);28192687 page->freelist = get_freepointer(kmem_cache_node, n);28202820- page->inuse++;26882688+ page->inuse = 1;28212689 page->frozen = 0;28222690 kmem_cache_node->node[node] = n;28232691#ifdef CONFIG_SLUB_DEBUG···28272695 init_kmem_cache_node(n, kmem_cache_node);28282696 inc_slabs_node(kmem_cache_node, node, page->objects);2829269728302830- add_partial(n, page, 0);26982698+ add_partial(n, page, DEACTIVATE_TO_HEAD);28312699}2832270028332701static void free_kmem_cache_nodes(struct kmem_cache *s)···30432911 * The larger the object size is, the more pages we want on the partial30442912 * list to avoid pounding the page allocator excessively.30452913 */30463046- set_min_partial(s, ilog2(s->size));29142914+ set_min_partial(s, ilog2(s->size) / 2);29152915+29162916+ /*29172917+ * cpu_partial determined the maximum number of objects kept in the29182918+ * per cpu partial lists of a processor.29192919+ *29202920+ * Per cpu partial lists mainly contain slabs that just have one29212921+ * object freed. If they are used for allocation then they can be29222922+ * filled up again with minimal effort. The slab will never hit the29232923+ * per node partial lists and therefore no locking will be required.29242924+ *29252925+ * This setting also determines29262926+ *29272927+ * A) The number of objects from per cpu partial slabs dumped to the29282928+ * per node list when we reach the limit.29292929+ * B) The number of objects in cpu partial slabs to extract from the29302930+ * per node list when we run out of per cpu objects. We only fetch 50%29312931+ * to keep some capacity around for frees.29322932+ */29332933+ if (s->size >= PAGE_SIZE)29342934+ s->cpu_partial = 2;29352935+ else if (s->size >= 1024)29362936+ s->cpu_partial = 6;29372937+ else if (s->size >= 256)29382938+ s->cpu_partial = 13;29392939+ else29402940+ s->cpu_partial = 30;29412941+30472942 s->refcount = 1;30482943#ifdef CONFIG_NUMA30492944 s->remote_node_defrag_ratio = 1000;···3129297031302971/*31312972 * Attempt to free all partial slabs on a node.29732973+ * This is called from kmem_cache_close(). We must be the last thread29742974+ * using the cache and therefore we do not need to lock anymore.31322975 */31332976static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n)31342977{31353135- unsigned long flags;31362978 struct page *page, *h;3137297931383138- spin_lock_irqsave(&n->list_lock, flags);31392980 list_for_each_entry_safe(page, h, &n->partial, lru) {31402981 if (!page->inuse) {31412982 remove_partial(n, page);···31452986 "Objects remaining on kmem_cache_close()");31462987 }31472988 }31483148- spin_unlock_irqrestore(&n->list_lock, flags);31492989}3150299031512991/*···31783020 s->refcount--;31793021 if (!s->refcount) {31803022 list_del(&s->list);30233023+ up_write(&slub_lock);31813024 if (kmem_cache_close(s)) {31823025 printk(KERN_ERR "SLUB %s: %s called for cache that "31833026 "still has objects.\n", s->name, __func__);···31873028 if (s->flags & SLAB_DESTROY_BY_RCU)31883029 rcu_barrier();31893030 sysfs_slab_remove(s);31903190- }31913191- up_write(&slub_lock);30313031+ } else30323032+ up_write(&slub_lock);31923033}31933034EXPORT_SYMBOL(kmem_cache_destroy);31943035···35063347 * list_lock. page->inuse here is the upper limit.35073348 */35083349 list_for_each_entry_safe(page, t, &n->partial, lru) {35093509- if (!page->inuse) {35103510- remove_partial(n, page);35113511- discard_slab(s, page);35123512- } else {35133513- list_move(&page->lru,35143514- slabs_by_inuse + page->inuse);35153515- }33503350+ list_move(&page->lru, slabs_by_inuse + page->inuse);33513351+ if (!page->inuse)33523352+ n->nr_partial--;35163353 }3517335435183355 /*35193356 * Rebuild the partial list with the slabs filled up most35203357 * first and the least used slabs at the end.35213358 */35223522- for (i = objects - 1; i >= 0; i--)33593359+ for (i = objects - 1; i > 0; i--)35233360 list_splice(slabs_by_inuse + i, n->partial.prev);3524336135253362 spin_unlock_irqrestore(&n->list_lock, flags);33633363+33643364+ /* Release empty slabs */33653365+ list_for_each_entry_safe(page, t, slabs_by_inuse, lru)33663366+ discard_slab(s, page);35263367 }3527336835283369 kfree(slabs_by_inuse);···4478431944794320 for_each_possible_cpu(cpu) {44804321 struct kmem_cache_cpu *c = per_cpu_ptr(s->cpu_slab, cpu);43224322+ struct page *page;4481432344824324 if (!c || c->node < 0)44834325 continue;···4493433344944334 total += x;44954335 nodes[c->node] += x;43364336+ }43374337+ page = c->partial;43384338+43394339+ if (page) {43404340+ x = page->pobjects;43414341+ total += x;43424342+ nodes[c->node] += x;44964343 }44974344 per_cpu[c->node]++;44984345 }···45794412};4580441345814414#define SLAB_ATTR_RO(_name) \45824582- static struct slab_attribute _name##_attr = __ATTR_RO(_name)44154415+ static struct slab_attribute _name##_attr = \44164416+ __ATTR(_name, 0400, _name##_show, NULL)4583441745844418#define SLAB_ATTR(_name) \45854419 static struct slab_attribute _name##_attr = \45864586- __ATTR(_name, 0644, _name##_show, _name##_store)44204420+ __ATTR(_name, 0600, _name##_show, _name##_store)4587442145884422static ssize_t slab_size_show(struct kmem_cache *s, char *buf)45894423{···46534485}46544486SLAB_ATTR(min_partial);4655448744884488+static ssize_t cpu_partial_show(struct kmem_cache *s, char *buf)44894489+{44904490+ return sprintf(buf, "%u\n", s->cpu_partial);44914491+}44924492+44934493+static ssize_t cpu_partial_store(struct kmem_cache *s, const char *buf,44944494+ size_t length)44954495+{44964496+ unsigned long objects;44974497+ int err;44984498+44994499+ err = strict_strtoul(buf, 10, &objects);45004500+ if (err)45014501+ return err;45024502+45034503+ s->cpu_partial = objects;45044504+ flush_all(s);45054505+ return length;45064506+}45074507+SLAB_ATTR(cpu_partial);45084508+46564509static ssize_t ctor_show(struct kmem_cache *s, char *buf)46574510{46584511 if (!s->ctor)···47114522 return show_slab_objects(s, buf, SO_PARTIAL|SO_OBJECTS);47124523}47134524SLAB_ATTR_RO(objects_partial);45254525+45264526+static ssize_t slabs_cpu_partial_show(struct kmem_cache *s, char *buf)45274527+{45284528+ int objects = 0;45294529+ int pages = 0;45304530+ int cpu;45314531+ int len;45324532+45334533+ for_each_online_cpu(cpu) {45344534+ struct page *page = per_cpu_ptr(s->cpu_slab, cpu)->partial;45354535+45364536+ if (page) {45374537+ pages += page->pages;45384538+ objects += page->pobjects;45394539+ }45404540+ }45414541+45424542+ len = sprintf(buf, "%d(%d)", objects, pages);45434543+45444544+#ifdef CONFIG_SMP45454545+ for_each_online_cpu(cpu) {45464546+ struct page *page = per_cpu_ptr(s->cpu_slab, cpu) ->partial;45474547+45484548+ if (page && len < PAGE_SIZE - 20)45494549+ len += sprintf(buf + len, " C%d=%d(%d)", cpu,45504550+ page->pobjects, page->pages);45514551+ }45524552+#endif45534553+ return len + sprintf(buf + len, "\n");45544554+}45554555+SLAB_ATTR_RO(slabs_cpu_partial);4714455647154557static ssize_t reclaim_account_show(struct kmem_cache *s, char *buf)47164558{···50654845STAT_ATTR(ORDER_FALLBACK, order_fallback);50664846STAT_ATTR(CMPXCHG_DOUBLE_CPU_FAIL, cmpxchg_double_cpu_fail);50674847STAT_ATTR(CMPXCHG_DOUBLE_FAIL, cmpxchg_double_fail);48484848+STAT_ATTR(CPU_PARTIAL_ALLOC, cpu_partial_alloc);48494849+STAT_ATTR(CPU_PARTIAL_FREE, cpu_partial_free);50684850#endif5069485150704852static struct attribute *slab_attrs[] = {···50754853 &objs_per_slab_attr.attr,50764854 &order_attr.attr,50774855 &min_partial_attr.attr,48564856+ &cpu_partial_attr.attr,50784857 &objects_attr.attr,50794858 &objects_partial_attr.attr,50804859 &partial_attr.attr,···50884865 &destroy_by_rcu_attr.attr,50894866 &shrink_attr.attr,50904867 &reserved_attr.attr,48684868+ &slabs_cpu_partial_attr.attr,50914869#ifdef CONFIG_SLUB_DEBUG50924870 &total_objects_attr.attr,50934871 &slabs_attr.attr,···51304906 &order_fallback_attr.attr,51314907 &cmpxchg_double_fail_attr.attr,51324908 &cmpxchg_double_cpu_fail_attr.attr,49094909+ &cpu_partial_alloc_attr.attr,49104910+ &cpu_partial_free_attr.attr,51334911#endif51344912#ifdef CONFIG_FAILSLAB51354913 &failslab_attr.attr,···5483525754845258static int __init slab_proc_init(void)54855259{54865486- proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);52605260+ proc_create("slabinfo", S_IRUSR, NULL, &proc_slabinfo_operations);54875261 return 0;54885262}54895263module_init(slab_proc_init);