Received: by 10.223.185.116 with SMTP id b49csp90915wrg; Mon, 19 Feb 2018 17:26:31 -0800 (PST) X-Google-Smtp-Source: AH8x224TFjrzczA7NXKwgKAEGGVxuq5+sH9gMKjyOsPBEg904JZicISibWNIK3oogpz8YTwB94Rg X-Received: by 10.101.88.138 with SMTP id d10mr13777877pgu.52.1519089991273; Mon, 19 Feb 2018 17:26:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519089991; cv=none; d=google.com; s=arc-20160816; b=VZeVnll2m0ibLP1HfDBDhX21FCv6x0UegslLOyHVdjwvzzp2q3u5Z51mEeypVAVTir zwPWq20zg5VeOHkdcUBTQt3+ThiZ9AHJ940J6nQtrNYSPdhm1mDqkK7l2gkFe9Fx7jyQ P+dhResUiD7+5bWJ3sg7KKlBVZqkaZIcS7CHG3m6Jbi1EEsNu8MBWsXKaQ8MqV8XA6aP yS5hJZqpVlExKmHrFih1VLc51dbCuf+Mw1oNMGKnn3UCB0JxEugxRd87dCk3TvLmLmai CVo5+Z/6C3fpZ6sw6xtulN03fqtTzzJUHZA0G5L5ol1QY+GCrWlpPhtZZwmHCnSSajsE y73A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=p//qGjhjVV+b+flWEzp7vVklKq3p+jgAemkfWsHCO5w=; b=YJZjbXkdJNDDfC6uNJMAzFG6NNYgZ5ecoHmLlj3xY2nRq0NKWknNaRnXmrIAPtO90Q VbRNov1j78tDz7+TxCC7ClXcCbQcPIqDVhaCk6FhkZM5KiihInbVOuB6IaWIxTsbWNj/ J7Da44k5Bv5eJJjP9ZWhOW8zY/XpT8phFfg9yRf4QZapD7vBVxH29DGJkBwWBe94ZVW1 KoH1FjqQeIYqS+YsWZIFF4fSlZ1GIeKLZAZUrJuOnMmNg2XZTQRmAWBSTiyMjG0YseyK d3KRk3k1HCvVKx8cZdLhZ8D5trepCda5Zb66rcS2raZk6MihIorsH9pVEkqQG5kN+WHF gvkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=H8osnFML; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b187si4890496pfg.273.2018.02.19.17.26.16; Mon, 19 Feb 2018 17:26:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=H8osnFML; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932337AbeBTBYh (ORCPT + 99 others); Mon, 19 Feb 2018 20:24:37 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:46415 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932280AbeBTBYf (ORCPT ); Mon, 19 Feb 2018 20:24:35 -0500 Received: by mail-pg0-f68.google.com with SMTP id m1so2440122pgp.13 for ; Mon, 19 Feb 2018 17:24:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=p//qGjhjVV+b+flWEzp7vVklKq3p+jgAemkfWsHCO5w=; b=H8osnFMLaYYm7uMt6TcoIUHFibwksLAgmo6cYBs7oER0FL5Ghz6PfmWAU5qoA5MkO/ 0WQ0Kbxc3sVthBWsDOqt8oZVdPEnFqQquv1VF+80fqDVoftlUyN6FY7uAc94s7qjsKk2 7Gm5sjnBTKAIAZV5DPM1cam41DlmTglPMueZiTR3Dj3Ux/AlZdjf4hY4cWxn+UeiFhXr F0cWsSO47HuzMX1xSa6bkYYvHDR4DnwBYKPbz5vqnyofMFJhguCZ/WSGSDJsOFPO3I8+ 5whQOdjb6v6LhxW663N3E31lM/IrTM2pKnuGvy20jOyiXivFd+1/VSPXMsRcVDe7BeGf okVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=p//qGjhjVV+b+flWEzp7vVklKq3p+jgAemkfWsHCO5w=; b=umJNuFtJeK+N9UL6Ou4H77Trjl6P28JO/2APQoJn/4NfM86iX0pXJdX6DrYqYO4Nn/ vIOTxHIIehJVvYifpLfBFtj4UGElPhnh5Jd2TsrRrYDlzmME5YoIfChW/A8ZqP4GO/4+ xgcMd+LC8bXok0WLHQuzKTm754gZkOWJj5cgaBOH8lnq4G5UNSHfrozSOFwo/p4dJ+st kEtDA0pN+ZSuQEO9eCQ9RZR9dbfGEinp6XIv39YUWT5lln+yW3V5JaZSEu0LZtkb3wCw b3ATESPO6e2+nKik6wJ5ZuUvQQ887R2gtmeqLCqluTjoZcVeKk58myg1whJEwmHnMp6W 9P7Q== X-Gm-Message-State: APf1xPByU8qSuXFRoeXWm/X3OIidUCquzscSPPor+o8QH/yFApZ06rWc y+w4EHYnsRl06pei+rbvIs4= X-Received: by 10.98.31.79 with SMTP id f76mr12516840pff.60.1519089875193; Mon, 19 Feb 2018 17:24:35 -0800 (PST) Received: from rodete-desktop-imager.corp.google.com ([2401:fa00:d:0:6c6:f8e5:871:b853]) by smtp.gmail.com with ESMTPSA id w63sm7086900pgb.80.2018.02.19.17.24.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Feb 2018 17:24:33 -0800 (PST) Date: Tue, 20 Feb 2018 10:24:29 +0900 From: Minchan Kim To: Sergey Senozhatsky Cc: Andrew Morton , Mike Rapoport , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: Re: [PATCHv3 1/2] zsmalloc: introduce zs_huge_object() function Message-ID: <20180220012429.GA186771@rodete-desktop-imager.corp.google.com> References: <20180210082321.17798-1-sergey.senozhatsky@gmail.com> <20180214055747.8420-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180214055747.8420-1-sergey.senozhatsky@gmail.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Sergey, On Wed, Feb 14, 2018 at 02:57:47PM +0900, Sergey Senozhatsky wrote: > Not every object can be share its zspage with other objects, e.g. > when the object is as big as zspage or nearly as big a zspage. > For such objects zsmalloc has a so called huge class - every object > which belongs to huge class consumes the entire zspage (which > consists of a physical page). On x86_64, PAGE_SHIFT 12 box, the > first non-huge class size is 3264, so starting down from size 3264, > objects can share page(-s) and thus minimize memory wastage. > > ZRAM, however, has its own statically defined watermark for huge > objects - "3 * PAGE_SIZE / 4 = 3072", and forcibly stores every > object larger than this watermark (3072) as a PAGE_SIZE object, > in other words, to a huge class, while zsmalloc can keep some of > those objects in non-huge classes. This results in increased > memory consumption. > > zsmalloc knows better if the object is huge or not. Introduce > zs_huge_object() function which tells if the given object can be > stored in one of non-huge classes or not. This will let us to drop > ZRAM's huge object watermark and fully rely on zsmalloc when we > decide if the object is huge. > > Signed-off-by: Sergey Senozhatsky > --- > include/linux/zsmalloc.h | 2 ++ > mm/zsmalloc.c | 26 ++++++++++++++++++++++++++ > 2 files changed, 28 insertions(+) > > diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h > index 57a8e98f2708..9a1baf673cc1 100644 > --- a/include/linux/zsmalloc.h > +++ b/include/linux/zsmalloc.h > @@ -47,6 +47,8 @@ void zs_destroy_pool(struct zs_pool *pool); > unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t flags); > void zs_free(struct zs_pool *pool, unsigned long obj); > > +bool zs_huge_object(size_t sz); > + > void *zs_map_object(struct zs_pool *pool, unsigned long handle, > enum zs_mapmode mm); > void zs_unmap_object(struct zs_pool *pool, unsigned long handle); > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c > index c3013505c305..e43fc6ebb8e1 100644 > --- a/mm/zsmalloc.c > +++ b/mm/zsmalloc.c > @@ -192,6 +192,7 @@ static struct vfsmount *zsmalloc_mnt; > * (see: fix_fullness_group()) > */ > static const int fullness_threshold_frac = 4; > +static size_t zs_huge_class_size; > > struct size_class { > spinlock_t lock; > @@ -1417,6 +1418,28 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle) > } > EXPORT_SYMBOL_GPL(zs_unmap_object); > > +/** > + * zs_huge_object() - Test if a compressed object's size is too big for normal > + * zspool classes and it should be stored in a huge class. > + * @sz: Size of the compressed object (in bytes). > + * > + * The function checks if the object's size falls into huge_class > + * area. We must take handle size into account and test the actual > + * size we are going to use, because zs_malloc() unconditionally > + * adds %ZS_HANDLE_SIZE before it performs &size_class lookup. > + * > + * Context: Any context. > + * > + * Return: > + * * true - The object is too big, it will be stored in the huge class. > + * * false - The object will be stored in a normal zspool class. > + */ > +bool zs_huge_object(size_t sz) > +{ > + return sz + ZS_HANDLE_SIZE >= zs_huge_class_size; > +} > +EXPORT_SYMBOL_GPL(zs_huge_object); > + > static unsigned long obj_malloc(struct size_class *class, > struct zspage *zspage, unsigned long handle) > { > @@ -2404,6 +2427,9 @@ struct zs_pool *zs_create_pool(const char *name) > INIT_LIST_HEAD(&class->fullness_list[fullness]); > > prev_class = class; > + if (pages_per_zspage == 1 && objs_per_zspage == 1 > + && !zs_huge_class_size) > + zs_huge_class_size = size; > } Sorry for the long delay. I was horribly busy for a few weeks. ;-( 1. I didn't see your next patch but I bet it is thing to apply this new API to zram. Normally, it's hard to review without callsite in same patch because sometime we need to know context where the API is used. In my understanding, if we judge new API is really complex to get review from others, then, introducing new API function without callsite is justified enough. In this case, I think it's simple enough. :) 2. Can't zram ask to zsmalloc about what size is for hugeobject from? With that, zram can save the wartermark in itself and use it. What I mean is as follows, zram: size_t huge_size = _zs_huge_object(pool); .. .. if (comp_size >= huge_size) memcpy(dst, src, 4K);