linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Paul Hargrove <phhargrove@lbl.gov>
To: linux-mm@kvack.org
Subject: BUG: slub creates kmalloc slabs with refcount=0
Date: Mon, 24 Dec 2012 16:55:21 -0800	[thread overview]
Message-ID: <CAAvDA15U=KCOujRYA5k3YkvC9Z=E6fcG5hopPUJNgULYj_MAJw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1457 bytes --]

I have a 3.7.1 kernel on x86-86
It is configured with
  CONFIG_SLUB=y
  CONFIG_SLUB_DEBUG=y

I have an out-of-tree module calling KMEM_CACHE for an 8-byte struct:
        cr_pdata_cachep = KMEM_CACHE(cr_pdata_s,0);
        if (!cr_pdata_cachep) goto no_pdata_cachep;
        printk(KERN_ERR "@ refcount = %d name = '%s'\n",
cr_pdata_cachep->refcount, cr_pdata_cachep->name);

The output of the printk, below, shows that the request has been merged
with the built-in 8-byte kmalloc pool, BUT the resulting refcount is 1,
rather than 2 (or more):
    @ refcount = 1 name = 'kmalloc-8'

This results in a very unhappy kernel when the module calls
    kmem_cache_destroy(cr_pdata_cachep);
at rmmod time, resulting is messages like
    BUG kmalloc-8 (Tainted: G           O): Objects remaining in kmalloc-96
on kmem_cache_close()

A quick look through mm/slub.c appears to confirm my suspicion that
"s->refcount" is never incremented for the built-in kmalloc-* caches.
 However, I leave it to the experts to determine where the increment
belongs.

FWIW: I am currently passing SLAB_POISON for the flags argument to
KMEM_CACHE() as a work-around (it prevents merging and, if I understand
correctly, has no overhead in a non-debug build).

-Paul

-- 
Paul H. Hargrove                          PHHargrove@lbl.gov
Future Technologies Group
Computer and Data Sciences Department     Tel: +1-510-495-2352
Lawrence Berkeley National Laboratory     Fax: +1-510-486-6900

[-- Attachment #2: Type: text/html, Size: 2092 bytes --]

             reply	other threads:[~2012-12-25  0:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-25  0:55 Paul Hargrove [this message]
2012-12-25  1:18 ` Paul Hargrove
2012-12-25 15:24 ` [PATCH] slub: assign refcount for kmalloc_caches Joonsoo Kim
2012-12-25 15:30   ` JoonSoo Kim
2013-01-11  4:47     ` Paul Hargrove
2013-01-11  7:52       ` Joonsoo Kim
2013-01-14 19:23         ` Greg Kroah-Hartman
2013-01-25  3:32           ` CAI Qian
2013-01-29  6:07             ` Joonsoo Kim
2012-12-27 16:06   ` Christoph Lameter
2012-12-25 15:32 ` BUG: slub creates kmalloc slabs with refcount=0 JoonSoo Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAAvDA15U=KCOujRYA5k3YkvC9Z=E6fcG5hopPUJNgULYj_MAJw@mail.gmail.com' \
    --to=phhargrove@lbl.gov \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox