From: Matt Mackall <mpm@selenic.com>
To: George Spelvin <linux@horizon.com>
Cc: penberg@cs.helsinki.fi, herbert@gondor.apana.org.au,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 5/8] mm/slub: Factor out some common code.
Date: Tue, 15 Mar 2011 22:12:08 -0500 [thread overview]
Message-ID: <1300245128.3128.432.camel@calx> (raw)
In-Reply-To: <20110316022805.27713.qmail@science.horizon.com>
On Mon, 2011-03-14 at 21:58 -0400, George Spelvin wrote:
> For sysfs files that map a boolean to a flags bit.
This one's actually pretty nice. You should really try to put all the
uncontroversial bits of a series first.
> ---
> mm/slub.c | 93 ++++++++++++++++++++++++++++--------------------------------
> 1 files changed, 43 insertions(+), 50 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index e15aa7f..856246f 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -3982,38 +3982,61 @@ static ssize_t objects_partial_show(struct kmem_cache *s, char *buf)
> }
> SLAB_ATTR_RO(objects_partial);
>
> +static ssize_t flag_show(struct kmem_cache *s, char *buf, unsigned flag)
> +{
> + return sprintf(buf, "%d\n", !!(s->flags & flag));
> +}
> +
> +static ssize_t flag_store(struct kmem_cache *s,
> + const char *buf, size_t length, unsigned flag)
> +{
> + s->flags &= ~flag;
> + if (buf[0] == '1')
> + s->flags |= flag;
> + return length;
> +}
> +
> +/* Like above, but changes allocation size; so only allowed on empty slab */
> +static ssize_t flag_store_sizechange(struct kmem_cache *s,
> + const char *buf, size_t length, unsigned flag)
> +{
> + if (any_slab_objects(s))
> + return -EBUSY;
> +
> + flag_store(s, buf, length, flag);
> + calculate_sizes(s, -1);
> + return length;
> +}
> +
> static ssize_t reclaim_account_show(struct kmem_cache *s, char *buf)
> {
> - return sprintf(buf, "%d\n", !!(s->flags & SLAB_RECLAIM_ACCOUNT));
> + return flag_show(s, buf, SLAB_RECLAIM_ACCOUNT);
> }
>
> static ssize_t reclaim_account_store(struct kmem_cache *s,
> const char *buf, size_t length)
> {
> - s->flags &= ~SLAB_RECLAIM_ACCOUNT;
> - if (buf[0] == '1')
> - s->flags |= SLAB_RECLAIM_ACCOUNT;
> - return length;
> + return flag_store(s, buf, length, SLAB_RECLAIM_ACCOUNT);
> }
> SLAB_ATTR(reclaim_account);
>
> static ssize_t hwcache_align_show(struct kmem_cache *s, char *buf)
> {
> - return sprintf(buf, "%d\n", !!(s->flags & SLAB_HWCACHE_ALIGN));
> + return flag_show(s, buf, SLAB_HWCACHE_ALIGN);
> }
> SLAB_ATTR_RO(hwcache_align);
>
> #ifdef CONFIG_ZONE_DMA
> static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
> {
> - return sprintf(buf, "%d\n", !!(s->flags & SLAB_CACHE_DMA));
> + return flag_show(s, buf, SLAB_CACHE_DMA);
> }
> SLAB_ATTR_RO(cache_dma);
> #endif
>
> static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
> {
> - return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
> + return flag_show(s, buf, SLAB_DESTROY_BY_RCU);
> }
> SLAB_ATTR_RO(destroy_by_rcu);
>
> @@ -4032,88 +4055,61 @@ SLAB_ATTR_RO(total_objects);
>
> static ssize_t sanity_checks_show(struct kmem_cache *s, char *buf)
> {
> - return sprintf(buf, "%d\n", !!(s->flags & SLAB_DEBUG_FREE));
> + return flag_show(s, buf, SLAB_DEBUG_FREE);
> }
>
> static ssize_t sanity_checks_store(struct kmem_cache *s,
> const char *buf, size_t length)
> {
> - s->flags &= ~SLAB_DEBUG_FREE;
> - if (buf[0] == '1')
> - s->flags |= SLAB_DEBUG_FREE;
> - return length;
> + return flag_store(s, buf, length, SLAB_DEBUG_FREE);
> }
> SLAB_ATTR(sanity_checks);
>
> static ssize_t trace_show(struct kmem_cache *s, char *buf)
> {
> - return sprintf(buf, "%d\n", !!(s->flags & SLAB_TRACE));
> + return flag_show(s, buf, SLAB_TRACE);
> }
>
> static ssize_t trace_store(struct kmem_cache *s, const char *buf,
> size_t length)
> {
> - s->flags &= ~SLAB_TRACE;
> - if (buf[0] == '1')
> - s->flags |= SLAB_TRACE;
> - return length;
> + return flag_store(s, buf, length, SLAB_TRACE);
> }
> SLAB_ATTR(trace);
>
> static ssize_t red_zone_show(struct kmem_cache *s, char *buf)
> {
> - return sprintf(buf, "%d\n", !!(s->flags & SLAB_RED_ZONE));
> + return flag_show(s, buf, SLAB_RED_ZONE);
> }
>
> static ssize_t red_zone_store(struct kmem_cache *s,
> const char *buf, size_t length)
> {
> - if (any_slab_objects(s))
> - return -EBUSY;
> -
> - s->flags &= ~SLAB_RED_ZONE;
> - if (buf[0] == '1')
> - s->flags |= SLAB_RED_ZONE;
> - calculate_sizes(s, -1);
> - return length;
> + return flag_store_sizechange(s, buf, length, SLAB_RED_ZONE);
> }
> SLAB_ATTR(red_zone);
>
> static ssize_t poison_show(struct kmem_cache *s, char *buf)
> {
> - return sprintf(buf, "%d\n", !!(s->flags & SLAB_POISON));
> + return flag_show(s, buf, SLAB_POISON);
> }
>
> static ssize_t poison_store(struct kmem_cache *s,
> const char *buf, size_t length)
> {
> - if (any_slab_objects(s))
> - return -EBUSY;
> -
> - s->flags &= ~SLAB_POISON;
> - if (buf[0] == '1')
> - s->flags |= SLAB_POISON;
> - calculate_sizes(s, -1);
> - return length;
> + return flag_store_sizechange(s, buf, length, SLAB_POISON);
> }
> SLAB_ATTR(poison);
>
> static ssize_t store_user_show(struct kmem_cache *s, char *buf)
> {
> - return sprintf(buf, "%d\n", !!(s->flags & SLAB_STORE_USER));
> + return flag_show(s, buf, SLAB_STORE_USER);
> }
>
> static ssize_t store_user_store(struct kmem_cache *s,
> const char *buf, size_t length)
> {
> - if (any_slab_objects(s))
> - return -EBUSY;
> -
> - s->flags &= ~SLAB_STORE_USER;
> - if (buf[0] == '1')
> - s->flags |= SLAB_STORE_USER;
> - calculate_sizes(s, -1);
> - return length;
> + return flag_store_sizechange(s, buf, length, SLAB_STORE_USER);
> }
> SLAB_ATTR(store_user);
>
> @@ -4156,16 +4152,13 @@ SLAB_ATTR_RO(free_calls);
> #ifdef CONFIG_FAILSLAB
> static ssize_t failslab_show(struct kmem_cache *s, char *buf)
> {
> - return sprintf(buf, "%d\n", !!(s->flags & SLAB_FAILSLAB));
> + return flag_show(s, buf, SLAB_FAILSLAB);
> }
>
> static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
> size_t length)
> {
> - s->flags &= ~SLAB_FAILSLAB;
> - if (buf[0] == '1')
> - s->flags |= SLAB_FAILSLAB;
> - return length;
> + return flag_store(s, buf, length, SLAB_FAILSLAB);
> }
> SLAB_ATTR(failslab);
> #endif
--
Mathematics is the supreme nostalgia of our time.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2011-03-16 3:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-15 1:58 [PATCH 5/8] mm/slub: Factor out some common code George Spelvin
2011-03-16 3:12 ` Matt Mackall [this message]
2011-03-16 6:32 ` Pekka Enberg
2011-03-16 20:28 ` David Rientjes
2011-03-16 20:51 ` George Spelvin
2011-03-16 21:51 ` David Rientjes
2011-03-16 22:36 ` George Spelvin
2011-03-17 6:23 ` Pekka Enberg
2011-03-17 7:07 ` George Spelvin
2011-03-17 8:01 ` Pekka Enberg
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=1300245128.3128.432.camel@calx \
--to=mpm@selenic.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@horizon.com \
--cc=penberg@cs.helsinki.fi \
/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).