From: Dan Streetman <ddstreet@ieee.org>
To: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Minchan Kim <minchan@kernel.org>, Linux-MM <linux-mm@kvack.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
Jerome Marchand <jmarchan@redhat.com>,
juno.choi@lge.com, seungho1.park@lge.com,
Luigi Semenzato <semenzato@google.com>,
Nitin Gupta <ngupta@vflare.org>
Subject: Re: [RFC 1/3] zsmalloc: move pages_allocated to zs_pool
Date: Wed, 13 Aug 2014 10:51:40 -0400 [thread overview]
Message-ID: <CALZtONDgYRUwrsN_G7pds2QY6QTOr8G8jAHa6Zta2XDhDHV8_A@mail.gmail.com> (raw)
In-Reply-To: <20140813141413.GA1091@swordfish>
On Wed, Aug 13, 2014 at 10:14 AM, Sergey Senozhatsky
<sergey.senozhatsky@gmail.com> wrote:
> On (08/13/14 09:59), Dan Streetman wrote:
>> On Tue, Aug 5, 2014 at 4:02 AM, Minchan Kim <minchan@kernel.org> wrote:
>> > Pages_allocated has counted in size_class structure and when user
>> > want to see total_size_bytes, it gathers all of value from each
>> > size_class to report the sum.
>> >
>> > It's not bad if user don't see the value often but if user start
>> > to see the value frequently, it would be not a good deal for
>> > performance POV.
>> >
>> > This patch moves the variable from size_class to zs_pool so it would
>> > reduce memory footprint (from [255 * 8byte] to [sizeof(atomic_t)])
>> > but it adds new locking overhead but it wouldn't be severe because
>> > it's not a hot path in zs_malloc(ie, it is called only when new
>> > zspage is created, not a object).
>>
>> Would using an atomic64_t without locking be simpler?
>
> it would be racy.
oh. atomic operations aren't smp safe? is that because other
processors might use a stale value, and barriers must be added? I
guess I don't quite understand the value of atomic then. :-/
>
> -ss
>
>>
>> >
>> > Signed-off-by: Minchan Kim <minchan@kernel.org>
>> > ---
>> > mm/zsmalloc.c | 30 ++++++++++++++++--------------
>> > 1 file changed, 16 insertions(+), 14 deletions(-)
>> >
>> > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
>> > index fe78189624cf..a6089bd26621 100644
>> > --- a/mm/zsmalloc.c
>> > +++ b/mm/zsmalloc.c
>> > @@ -198,9 +198,6 @@ struct size_class {
>> >
>> > spinlock_t lock;
>> >
>> > - /* stats */
>> > - u64 pages_allocated;
>> > -
>> > struct page *fullness_list[_ZS_NR_FULLNESS_GROUPS];
>> > };
>> >
>> > @@ -216,9 +213,12 @@ struct link_free {
>> > };
>> >
>> > struct zs_pool {
>> > + spinlock_t stat_lock;
>> > +
>> > struct size_class size_class[ZS_SIZE_CLASSES];
>> >
>> > gfp_t flags; /* allocation flags used when growing pool */
>> > + unsigned long pages_allocated;
>> > };
>> >
>> > /*
>> > @@ -882,6 +882,7 @@ struct zs_pool *zs_create_pool(gfp_t flags)
>> >
>> > }
>> >
>> > + spin_lock_init(&pool->stat_lock);
>> > pool->flags = flags;
>> >
>> > return pool;
>> > @@ -943,8 +944,10 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size)
>> > return 0;
>> >
>> > set_zspage_mapping(first_page, class->index, ZS_EMPTY);
>> > + spin_lock(&pool->stat_lock);
>> > + pool->pages_allocated += class->pages_per_zspage;
>> > + spin_unlock(&pool->stat_lock);
>> > spin_lock(&class->lock);
>> > - class->pages_allocated += class->pages_per_zspage;
>> > }
>> >
>> > obj = (unsigned long)first_page->freelist;
>> > @@ -997,14 +1000,14 @@ void zs_free(struct zs_pool *pool, unsigned long obj)
>> >
>> > first_page->inuse--;
>> > fullness = fix_fullness_group(pool, first_page);
>> > -
>> > - if (fullness == ZS_EMPTY)
>> > - class->pages_allocated -= class->pages_per_zspage;
>> > -
>> > spin_unlock(&class->lock);
>> >
>> > - if (fullness == ZS_EMPTY)
>> > + if (fullness == ZS_EMPTY) {
>> > + spin_lock(&pool->stat_lock);
>> > + pool->pages_allocated -= class->pages_per_zspage;
>> > + spin_unlock(&pool->stat_lock);
>> > free_zspage(first_page);
>> > + }
>> > }
>> > EXPORT_SYMBOL_GPL(zs_free);
>> >
>> > @@ -1100,12 +1103,11 @@ EXPORT_SYMBOL_GPL(zs_unmap_object);
>> >
>> > u64 zs_get_total_size_bytes(struct zs_pool *pool)
>> > {
>> > - int i;
>> > - u64 npages = 0;
>> > -
>> > - for (i = 0; i < ZS_SIZE_CLASSES; i++)
>> > - npages += pool->size_class[i].pages_allocated;
>> > + u64 npages;
>> >
>> > + spin_lock(&pool->stat_lock);
>> > + npages = pool->pages_allocated;
>> > + spin_unlock(&pool->stat_lock);
>> > return npages << PAGE_SHIFT;
>> > }
>> > EXPORT_SYMBOL_GPL(zs_get_total_size_bytes);
>> > --
>> > 2.0.0
>> >
>> > --
>> > 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/ .
>> > 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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2014-08-13 14:52 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-05 8:02 [RFC 0/3] zram memory control enhance Minchan Kim
2014-08-05 8:02 ` [RFC 1/3] zsmalloc: move pages_allocated to zs_pool Minchan Kim
2014-08-13 13:59 ` Dan Streetman
2014-08-13 14:14 ` Sergey Senozhatsky
2014-08-13 14:51 ` Dan Streetman [this message]
2014-08-13 15:13 ` Sergey Senozhatsky
2014-08-13 15:25 ` Sergey Senozhatsky
2014-08-13 16:11 ` Dan Streetman
2014-08-14 13:03 ` Sergey Senozhatsky
2014-08-14 0:09 ` Minchan Kim
2014-08-13 15:21 ` Seth Jennings
2014-08-05 8:02 ` [RFC 2/3] zsmalloc/zram: add zs_get_max_size_bytes and use it in zram Minchan Kim
2014-08-13 15:25 ` Seth Jennings
2014-08-05 8:02 ` [RFC 3/3] zram: limit memory size for zram Minchan Kim
2014-08-05 9:48 ` Minchan Kim
2014-08-05 13:16 ` Sergey Senozhatsky
2014-08-06 6:52 ` Minchan Kim
2014-08-13 15:30 ` Seth Jennings
2014-08-13 23:31 ` Minchan Kim
2014-08-13 23:27 ` Minchan Kim
2014-08-14 13:29 ` Sergey Senozhatsky
2014-08-17 23:32 ` Minchan Kim
2014-08-14 14:45 ` Dan Streetman
2014-08-06 12:54 ` [RFC 0/3] zram memory control enhance Jerome Marchand
2014-08-13 15:34 ` Seth Jennings
2014-08-13 23:32 ` Minchan 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=CALZtONDgYRUwrsN_G7pds2QY6QTOr8G8jAHa6Zta2XDhDHV8_A@mail.gmail.com \
--to=ddstreet@ieee.org \
--cc=jmarchan@redhat.com \
--cc=juno.choi@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=ngupta@vflare.org \
--cc=semenzato@google.com \
--cc=sergey.senozhatsky@gmail.com \
--cc=seungho1.park@lge.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