Received: by 10.223.176.5 with SMTP id f5csp2105157wra; Thu, 8 Feb 2018 08:31:15 -0800 (PST) X-Google-Smtp-Source: AH8x227sx5ai0imjFqQhwTv1hFf1RuGhM+iET6SzMv8oTFwmc49J4eyFDCTV7EZfJi3c5N1KbCk3 X-Received: by 10.98.6.130 with SMTP id 124mr1206318pfg.117.1518107475572; Thu, 08 Feb 2018 08:31:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518107475; cv=none; d=google.com; s=arc-20160816; b=iJnWQOr8slOOrdKig8PboFRlRZIfSDY7C0KORwHDMqeRCW8+eWCx0tJDFxP9r5RCkD tMykUmWuBTetEdrRZYjfYlAOmCgibZpScsAqyBPgYz1do0rGtL7sqlnBjU8NT+2bBsT1 vHgLsTud+ZLDfBbbLWwfC+PEmLISmevtywbkUr9Xxk58uF5Cp4jLgOJm7KTo7aH6abop kqrdEr/UL4NVMZK2toIs2FVc9c9L6+lalAu2QuvLZAgGYbv1u8ozRgf31++vcsoPa/EP 6j/KpB89QRdyFZLQ8d42srvihjmqyGnFc6Jw+w1BE5fT/TRDbuT4zwlESNXYYq+JzgdO p6YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:subject:cc:to:from:date :arc-authentication-results; bh=8DX2HM28EaJv0MSKVM11opHJmgpSL7zsZAO6Q8ZW9qE=; b=pZRKY28g5k1Dmt33UoXpAJg7JW1Z5gkY4BHvljmvNaymmknqh/eAJWCQ1ioSMQiBey GyRTRIoMOGg07X0YFIi7Wp61r+dcBV7Gok6iTI87qeu+Y6pmc2rlQ9Q5NYxypu/m09HH vHZKhcLXNxwL91uCsoel3PPel4mfLjh0eWA96r4r7sMp3alMb2GscQ0X+7whogK8VySh T07oiEQFL30ghkTeZukQfQHIFSs0PTfZYh/ImCr8M61ueTk6GwJ14AYxh16ff730QS6O jIoeWc0ceCU2h6R+6MN+xP1xS08A5inzYsGahJup4e2Uwh/+e4Xy97mjR1LwqDLJtpwJ aBVg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p11si185431pfl.310.2018.02.08.08.31.00; Thu, 08 Feb 2018 08:31:15 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752111AbeBHQaR (ORCPT + 99 others); Thu, 8 Feb 2018 11:30:17 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:40618 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750961AbeBHQaP (ORCPT ); Thu, 8 Feb 2018 11:30:15 -0500 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w18GTjh6060486 for ; Thu, 8 Feb 2018 11:30:15 -0500 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2g0s8nb20c-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 08 Feb 2018 11:30:14 -0500 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 8 Feb 2018 16:30:12 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 8 Feb 2018 16:30:09 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w18GU9GS48955586; Thu, 8 Feb 2018 16:30:09 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D52FF4C040; Thu, 8 Feb 2018 16:23:58 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 46DB24C044; Thu, 8 Feb 2018 16:23:58 +0000 (GMT) Received: from rapoport-lnx (unknown [9.148.8.106]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 8 Feb 2018 16:23:58 +0000 (GMT) Date: Thu, 8 Feb 2018 18:30:07 +0200 From: Mike Rapoport To: Sergey Senozhatsky Cc: Minchan Kim , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: Re: [PATCH 1/2] zsmalloc: introduce zs_huge_object() function References: <20180207092919.19696-1-sergey.senozhatsky@gmail.com> <20180207092919.19696-2-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180207092919.19696-2-sergey.senozhatsky@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-TM-AS-GCONF: 00 x-cbid: 18020816-0008-0000-0000-000004CAD583 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18020816-0009-0000-0000-00001E5E8A1D Message-Id: <20180208163006.GB17354@rapoport-lnx> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-02-08_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=9 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1802080191 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 07, 2018 at 06:29:18PM +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 | 17 +++++++++++++++++ > 2 files changed, 19 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..b3e295a806be 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,19 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle) > } > EXPORT_SYMBOL_GPL(zs_unmap_object); > > +/* > + * Check if the object's size falls into huge_class area. We must take > + * ZS_HANDLE_SIZE into account and test the actual size we are going to > + * use up. zs_malloc() unconditionally adds handle size before it performs > + * size_class lookup, so we may endup in a huge class yet zs_huge_object() > + * returned 'false'. > + */ Can you please reformat this comment as kernel-doc? > +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 +2418,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; > } > > /* debug only, don't abort if it fails */ > -- > 2.16.1 > > -- > 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: email@kvack.org > -- Sincerely yours, Mike.