linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: David Rientjes <rientjes@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Ben Hutchings <ben@decadent.org.uk>,
	Andrea Arcangeli <aarcange@redhat.com>,
	linux-mm@kvack.org, Mel Gorman <mel@csn.ul.ie>,
	Johannes Weiner <jweiner@redhat.com>,
	Rik van Riel <riel@redhat.com>, Hugh Dickins <hughd@google.com>
Subject: Re: [PATCH] mm/thp: Use conventional format for boolean attributes
Date: Thu, 14 Apr 2011 14:48:07 +1000	[thread overview]
Message-ID: <20110414144807.19ec5f69@notabene.brown> (raw)
In-Reply-To: <alpine.DEB.2.00.1104131202230.5563@chino.kir.corp.google.com>

On Wed, 13 Apr 2011 12:04:59 -0700 (PDT) David Rientjes <rientjes@google.com>
wrote:

> On Tue, 22 Mar 2011, Ben Hutchings wrote:
> 
> > The conventional format for boolean attributes in sysfs is numeric
> > ("0" or "1" followed by new-line).  Any boolean attribute can then be
> > read and written using a generic function.  Using the strings
> > "yes [no]", "[yes] no" (read), "yes" and "no" (write) will frustrate
> > this.
> > 
> > Cc'd to stable in order to change this before many scripts depend on
> > the current strings.
> > 
> 
> I agree with this in general, it's certainly the standard way of altering 
> a boolean tunable throughout the kernel so it would be nice to use the 
> same userspace libraries with THP.
> 
> Let's cc Andrew on this since it will go through the -mm tree if it's 
> merged.
> 
> > Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
> > Cc: stable@kernel.org [2.6.38]
> > ---
> >  mm/huge_memory.c |   21 +++++++++++----------
> >  1 files changed, 11 insertions(+), 10 deletions(-)
> > 
> > diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> > index 113e35c..dc0b3f0 100644
> > --- a/mm/huge_memory.c
> > +++ b/mm/huge_memory.c
> > @@ -244,24 +244,25 @@ static ssize_t single_flag_show(struct kobject *kobj,
> >  				struct kobj_attribute *attr, char *buf,
> >  				enum transparent_hugepage_flag flag)
> >  {
> > -	if (test_bit(flag, &transparent_hugepage_flags))
> > -		return sprintf(buf, "[yes] no\n");
> > -	else
> > -		return sprintf(buf, "yes [no]\n");
> > +	return sprintf(buf, "%d\n",
> > +		       test_bit(flag, &transparent_hugepage_flags));

It test bit guaranteed to return 0 or 1?

I think the x86 version returns 0 or -1 (that is from reading the code and
using google to check what 'sbb' does).

Maybe make it "!!test_bit" or even

     strcpy(buf, test_bit(...) ? "1\n" : "0\n");
     return 2;


NeilBrown


> >  }
> >  static ssize_t single_flag_store(struct kobject *kobj,
> >  				 struct kobj_attribute *attr,
> >  				 const char *buf, size_t count,
> >  				 enum transparent_hugepage_flag flag)
> >  {
> > -	if (!memcmp("yes", buf,
> > -		    min(sizeof("yes")-1, count))) {
> > +	unsigned long value;
> > +	char *endp;
> > +
> > +	value = simple_strtoul(buf, &endp, 0);
> > +	if (endp == buf || value > 1)
> > +		return -EINVAL;
> > +
> > +	if (value)
> >  		set_bit(flag, &transparent_hugepage_flags);
> > -	} else if (!memcmp("no", buf,
> > -			   min(sizeof("no")-1, count))) {
> > +	else
> >  		clear_bit(flag, &transparent_hugepage_flags);
> > -	} else
> > -		return -EINVAL;
> >  
> >  	return count;
> >  }
> 
> --
> 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>

--
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>

  parent reply	other threads:[~2011-04-14  4:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-22  5:45 [PATCH] mm/thp: Use conventional format for boolean attributes Ben Hutchings
2011-04-13 19:04 ` David Rientjes
2011-04-13 19:19   ` Andrew Morton
2011-04-13 19:28     ` David Rientjes
2011-04-13 19:35       ` Andrea Arcangeli
2011-04-14  4:48   ` NeilBrown [this message]
2011-04-14 14:29     ` Andrea Arcangeli
2011-04-14 16:57       ` Ben Hutchings
2011-04-14 19:09     ` Andrew Morton
2011-04-14 19:50       ` David Rientjes
2011-04-13 19:31 ` Andrew Morton

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=20110414144807.19ec5f69@notabene.brown \
    --to=neilb@suse.de \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=ben@decadent.org.uk \
    --cc=hughd@google.com \
    --cc=jweiner@redhat.com \
    --cc=linux-mm@kvack.org \
    --cc=mel@csn.ul.ie \
    --cc=riel@redhat.com \
    --cc=rientjes@google.com \
    /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).