linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Changli Gao <xiaosuo@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: akpm@linux-foundation.org, Hoang-Nam Nguyen <hnguyen@de.ibm.com>,
	Christoph Raisch <raisch@de.ibm.com>,
	Roland Dreier <rolandd@cisco.com>,
	Sean Hefty <sean.hefty@intel.com>,
	Hal Rosenstock <hal.rosenstock@gmail.com>,
	Divy Le Ray <divy@chelsio.com>,
	"James E.J. Bottomley" <James.Bottomley@suse.de>,
	"Theodore Ts'o" <tytso@mit.edu>, Andreas Dilger <adilger@sun.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Paul Menage <menage@google.com>, Li Zefan <lizf@cn.fujitsu.com>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, linux-scsi@vger.kernel.org,
	linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-mm@kvack.org, containers@lists.linux-foundation.org,
	Eric Dumazet <eric.dumazet@gmail.com>,
	Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Subject: Re: [PATCH 1/9] mm: add generic adaptive large memory allocation APIs
Date: Thu, 13 May 2010 22:08:26 +0800	[thread overview]
Message-ID: <AANLkTinLT5g5SKjqmQlS2kxvvMq1gsi1jPDgOKTnrT-q@mail.gmail.com> (raw)
In-Reply-To: <1273756816.5605.3547.camel@twins>

On Thu, May 13, 2010 at 9:20 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Thu, 2010-05-13 at 17:51 +0800, Changli Gao wrote:
>> +void *__kvmalloc(size_t size, gfp_t flags)
>> +{
>> +       void *ptr;
>> +
>> +       if (size < PAGE_SIZE)
>> +               return kmalloc(size, GFP_KERNEL | flags);
>> +       size = PAGE_ALIGN(size);
>> +       if (is_power_of_2(size))
>> +               ptr = (void *)__get_free_pages(GFP_KERNEL | flags |
>> +                                              __GFP_NOWARN, get_order(size));
>> +       else
>> +               ptr = alloc_pages_exact(size, GFP_KERNEL | flags |
>> +                                             __GFP_NOWARN);
>> +       if (ptr != NULL) {
>> +               virt_to_head_page(ptr)->private = size;
>> +               return ptr;
>> +       }
>> +
>> +       ptr = vmalloc(size);
>> +       if (ptr != NULL && (flags & __GFP_ZERO))
>> +               memset(ptr, 0, size);
>> +
>> +       return ptr;
>> +}
>> +EXPORT_SYMBOL(__kvmalloc);
>
> So if I do kvmalloc(size, GFP_ATOMIC) I get GFP_KERNEL|GFP_ATOMIC, which
> is not a recommended variation because one should not mix __GFP_WAIT and
> __GFP_HIGH.

__kvmalloc() is only for internal use(kvmalloc, kvcalloc, and
kvzalloc), and the only value of flags is __GFP_ZERO. How about
replacing flags with a bool variable zero?

void *__kvmalloc(size_t size, bool zero);

 Or check the value of flags in the front of __kvmalloc().

BUG_ON((flags & (~__GFP_ZERO)) != 0);

>
> So I would simply drop the gfp argument to avoid confusion.
>
>> +void __kvfree(void *ptr, bool inatomic)
>> +{
>> +       if (unlikely(ZERO_OR_NULL_PTR(ptr)))
>> +               return;
>> +       if (is_vmalloc_addr(ptr)) {
>> +               if (inatomic) {
>> +                       struct work_struct *work;
>> +
>> +                       work = ptr;
>> +                       BUILD_BUG_ON(sizeof(struct work_struct) > PAGE_SIZE);
>> +                       INIT_WORK(work, kvfree_work);
>> +                       schedule_work(work);
>> +               } else {
>> +                       vfree(ptr);
>> +               }
>> +       } else {
>> +               struct page *page;
>> +
>> +               page = virt_to_head_page(ptr);
>> +               if (PageSlab(page) || PageCompound(page))
>> +                       kfree(ptr);
>> +               else if (is_power_of_2(page->private))
>> +                       free_pages((unsigned long)ptr,
>> +                                  get_order(page->private));
>> +               else
>> +                       free_pages_exact(ptr, page->private);
>> +       }
>> +}
>> +EXPORT_SYMBOL(__kvfree);
>
> NAK, I really utterly dislike that inatomic argument. The alloc side
> doesn't function in atomic context either. Please keep the thing
> symmetric in that regards.
>

There are some users, who release memory in atomic context. for
example: fs/file.c: fdmem.

-- 
Regards,
Changli Gao(xiaosuo@gmail.com)

  parent reply	other threads:[~2010-05-13 14:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-13  9:51 [PATCH 1/9] mm: add generic adaptive large memory allocation APIs Changli Gao
2010-05-13 13:20 ` Peter Zijlstra
2010-05-13 13:36   ` [PATCH 1/9] mm: add generic adaptive large memory allocationAPIs Tetsuo Handa
2010-05-17  1:34     ` KOSAKI Motohiro
2010-05-13 14:08   ` Changli Gao [this message]
2010-05-14  8:03     ` [PATCH 1/9] mm: add generic adaptive large memory allocation APIs Peter Zijlstra
2010-05-14  8:12       ` Changli Gao
2010-05-13 14:39 ` Milton Miller
2010-05-13 14:49   ` Changli Gao

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=AANLkTinLT5g5SKjqmQlS2kxvvMq1gsi1jPDgOKTnrT-q@mail.gmail.com \
    --to=xiaosuo@gmail.com \
    --cc=James.Bottomley@suse.de \
    --cc=adilger@sun.com \
    --cc=akpm@linux-foundation.org \
    --cc=containers@lists.linux-foundation.org \
    --cc=divy@chelsio.com \
    --cc=eric.dumazet@gmail.com \
    --cc=hal.rosenstock@gmail.com \
    --cc=hnguyen@de.ibm.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=menage@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=peterz@infradead.org \
    --cc=raisch@de.ibm.com \
    --cc=rolandd@cisco.com \
    --cc=sean.hefty@intel.com \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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).