linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marco Elver <elver@google.com>
To: Daniel Latypov <dlatypov@google.com>
Cc: glittao@gmail.com, Christoph Lameter <cl@linux.com>,
	Pekka Enberg <penberg@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux Memory Management List <linux-mm@kvack.org>,
	KUnit Development <kunit-dev@googlegroups.com>
Subject: Re: [PATCH v3 1/2] kunit: add a KUnit test for SLUB debugging functionality
Date: Thu, 1 Apr 2021 23:24:32 +0200	[thread overview]
Message-ID: <CANpmjNPhWUsQrG62Z2jchdqzgSOfVYOsD1QDJpRghJwzwRZcQA@mail.gmail.com> (raw)
In-Reply-To: <CAGS_qxpWtNLJ7_i5pDYhiGq_Jy+oPPc+HpWjNTJKAPyvQf+gsQ@mail.gmail.com>

On Thu, 1 Apr 2021 at 21:04, Daniel Latypov <dlatypov@google.com> wrote:
...
> > > --- a/include/linux/slub_def.h
> > > +++ b/include/linux/slub_def.h
> > > @@ -133,6 +133,8 @@ struct kmem_cache {
> > >       unsigned int usersize;          /* Usercopy region size */
> > >
> > >       struct kmem_cache_node *node[MAX_NUMNODES];
> > > +
> > > +     int errors;                     /* Number of errors in cache */
> >
> > So, I think it's bad design to add a new field 'errors', just for the
> > test. This will increase kmem_cache size for all builds, which is
> > unnecessary.
> >
> > Is there use to retrieve 'errors' elsewhere?
> >
> > While you could guard this with #ifdef CONFIG_SLUB_DEBUG or so, there's
> > a better design option if this is just for the KUnit test's benefit: use
> > kunit_resource.
> >
> > The way it'd work is that for each test (you can add a common init
> > function) you add a named resource, in this case just an 'int' I guess,
> > that slab would be able to retrieve if this test is being run.
> >
> > In the test somewhere, you could add something like this:
> >
> >
> >         static struct kunit_resource resource;
> >         static int slab_errors;
> >
> >         ..........
> >
> >         static int test_init(struct kunit *test)
> >         {
> >                 slab_errors = 0;
> >                 kunit_add_named_resource(test, NULL, NULL, &resource,
> >                                          "slab_errors", &slab_errors);
> >                 return 0;
> >         }
> >
> >         ...... tests now check slab_errors .....
> >
> > and then in slub.c you'd have:
> >
> >         #if IS_ENABLED(CONFIG_KUNIT)
> >         static bool slab_add_kunit_errors(void)
> >         {
> >                 struct kunit_resource *resource;
> >
> >                 if (likely(!current->kunit_test))
> >                         return false;
> >                 resource = kunit_find_named_resource(current->kunit_test, "slab_errors");
> >                 if (!resource)
> >                         return false;
> >                 (*(int *)resource->data)++;
> >                 kunit_put_resource(resource);

      return true;

was missing.

> >         }
> >         #else
> >         static inline bool slab_add_kunit_errors(void) { return false; }
> >         #endif
> >
> > And anywhere you want to increase the error count, you'd call
> > slab_add_kunit_errors().
> >
> > Another benefit of this approach is that if KUnit is disabled, there is
> > zero overhead and no additional code generated (vs. the current
> > approach).
>
> The resource approach looks really good, but...
> You'd be picking up a dependency on
> https://lore.kernel.org/linux-kselftest/20210311152314.3814916-2-dlatypov@google.com/
> current->kunit_test will always be NULL unless CONFIG_KASAN=y &&
> CONFIG_KUNIT=y at the moment.
> My patch drops the CONFIG_KASAN requirement and opens it up to all tests.

Oh, that's a shame, but hopefully it'll be in -next soon.

> At the moment, it's just waiting another look over from Brendan or David.
> Any ETA on that, folks? :)
>
> So if you don't want to get blocked on that for now, I think it's fine to add:
>   #ifdef CONFIG_SLUB_KUNIT_TEST
>   int errors;
>   #endif

Until kunit fixes setting current->kunit_test, a cleaner workaround
that would allow to do the patch with kunit_resource, is to just have
an .init/.exit function that sets it ("current->kunit_test = test;").
And then perhaps add a note ("FIXME: ...") to remove it once the above
patch has landed.

At least that way we get the least intrusive change for mm/slub.c, and
the test is the only thing that needs a 2-line patch to clean up
later.

Thanks,
-- Marco

  reply	other threads:[~2021-04-01 21:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-31  8:51 [PATCH v3 1/2] kunit: add a KUnit test for SLUB debugging functionality glittao
2021-03-31  8:51 ` [PATCH v3 2/2] slub: remove resiliency_test() function glittao
2021-04-01  7:41 ` [PATCH v3 1/2] kunit: add a KUnit test for SLUB debugging functionality Vlastimil Babka
2021-04-01  9:16 ` Marco Elver
2021-04-01 19:04   ` Daniel Latypov
2021-04-01 21:24     ` Marco Elver [this message]
2021-04-06 10:57       ` Vlastimil Babka
2021-04-08 10:29         ` Marco Elver
2021-04-08 17:19           ` Daniel Latypov
2021-04-09  7:54             ` Brendan Higgins
2021-04-02  9:38     ` Brendan Higgins

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=CANpmjNPhWUsQrG62Z2jchdqzgSOfVYOsD1QDJpRghJwzwRZcQA@mail.gmail.com \
    --to=elver@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=dlatypov@google.com \
    --cc=glittao@gmail.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=vbabka@suse.cz \
    /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;
as well as URLs for NNTP newsgroup(s).