Received: by 10.223.176.5 with SMTP id f5csp427560wra; Wed, 7 Feb 2018 01:30:44 -0800 (PST) X-Google-Smtp-Source: AH8x225lGigDmrSlszh0mgN7xA6CySmRWbYwHTqXrFEFo9M42jXDOFB6Oy+xXERtp2AV7A7bmEhL X-Received: by 2002:a17:902:a983:: with SMTP id bh3-v6mr5374624plb.237.1517995844072; Wed, 07 Feb 2018 01:30:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517995844; cv=none; d=google.com; s=arc-20160816; b=Flvtr9rte0qZwtk2voHu1fCCjodgsYZTNTEXeqvmBACIZz5tuOzRCTdzDPgJaNXg74 MY4UmN36zGwPkk5I7n/odW/IRd0Ub3N0CzzP4Eisb5SuulyZYTPmDuubrOzVSoa48ZPm ykBnRpmWeih3DxiWUAr0Bp7e8jq0j1ehQMkbhcbczWJfM4WFFhTbJXrQVqwFjqzRpwCG P54/dCJnqlpzmHEVrbTNSHBiSVu173aGllYznw0upUtEX5wHBc2reuxwhFpSOsz4SoV1 vuG/nJEHqd1dgRn5u67vH9Akph8PKxat8FwfnfaiU87sOlFAHcdt0MTnN/mIHDLlUXdm jyYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=MSJMWpBzRAJnvp09fYIRx9phV5ipGFIYHO1rcaUq6y0=; b=YVNttOzui3zHeHGar26dnvYIcM59SJmELF8gP4xVMZVJHhyAe/upQ7S2ASjWx+7TyF kazquLEt1io2ToAOjPDGos7Ef/N0JMZYjKTg4FND3iyrnZL7YA99f5pWbEshJAv0vUoj XhMFOtlejAuFdKEoW98QY0mMUSk51A7x89ffXHCHIoHUWBq9mEaQUjbANmsdB6O7J9h1 XcjLn2MPMADzzHKd0YN7887G/dbsloZtLLmQdTk0dxLtPypjMbGluj/bd5TIexj2UTde h83N+7Og0olSE6sdid1MqwvbXuFbVgUfeB1iEWqfdBi13dIzvjwPh37/QOc7HOQDJxOK ZUAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=f505EP34; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r11-v6si818901plo.624.2018.02.07.01.30.30; Wed, 07 Feb 2018 01:30:44 -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=pass header.i=@gmail.com header.s=20161025 header.b=f505EP34; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753720AbeBGJ3j (ORCPT + 99 others); Wed, 7 Feb 2018 04:29:39 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:34175 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753690AbeBGJ3h (ORCPT ); Wed, 7 Feb 2018 04:29:37 -0500 Received: by mail-pl0-f68.google.com with SMTP id q17so129595pll.1 for ; Wed, 07 Feb 2018 01:29:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MSJMWpBzRAJnvp09fYIRx9phV5ipGFIYHO1rcaUq6y0=; b=f505EP34DK0WlaqV0tOhfieLecXobvbhJn5aq3O+DtfnHSKB2ym1Ik9nvJcY6MeO3z frf986DFNhsw20cL0+yPt87SAJyEcWCKxuARun/RXWEJWXKMxK9K+dpMPhjiIhBEDgT5 mddgLN6WmQqrGDeRvU9d0HIyEc9ocOadjw3bte614zgfwyQw85kEkDwRRx5fjCuu+Had /daSSqscR7w5/tiBA37GsKT92vHu4nPgIG0DQi0OvAhIfHJWjNNi0s5QI8Pz1gT7ej5r Bwx55b3/jXKLE5Mg+zhvgVrNw5g19bRHk3hTTDaxYslJRl9MIH7OWjtOvxsr4KguprwG lHDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MSJMWpBzRAJnvp09fYIRx9phV5ipGFIYHO1rcaUq6y0=; b=t3CkTcPAuD/r3lnoK6Mz7AZ4CMWdjfcd+wXbpYkP89rwlIc0vwjX0DX/EfPhRE6ssk PAvBQwW21/K8dgv9yKdP0nFFYRQ8tqDRtv5T4ZESIjmnozegipx4cqCt4z6gR/JqoSgo 7Mio4Srr3uc5dq4Bx+1KP/eWYXbqYFh1m60RXWksQqO0gjLd0JF/ViAj2fqkAdu2Nf11 mdrVJfo0C4otJr2Zij4Ce4sgvPBAFBueBY3Hr9pXe1I9AVmvYwXPqkBow92DbuQAX1Yx PapzrrxnG1RrFJVJbN4Ft3aZRVXgTaoBHHAztSDkjOewes1ZFhvPQMFZT7LlDXCEI2hb NGtQ== X-Gm-Message-State: APf1xPCJFy68cvsx9w7kgUf7KLYgLmkUpT/3eSTjg2tvcZIhcgqk5ola RfBmS+5jih41FOVuUcIAkMc= X-Received: by 2002:a17:902:720b:: with SMTP id ba11-v6mr5333406plb.371.1517995776085; Wed, 07 Feb 2018 01:29:36 -0800 (PST) Received: from localhost.localdomain ([39.7.54.25]) by smtp.gmail.com with ESMTPSA id m3sm2244516pgs.90.2018.02.07.01.29.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Feb 2018 01:29:34 -0800 (PST) From: Sergey Senozhatsky X-Google-Original-From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCH 1/2] zsmalloc: introduce zs_huge_object() function Date: Wed, 7 Feb 2018 18:29:18 +0900 Message-Id: <20180207092919.19696-2-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180207092919.19696-1-sergey.senozhatsky@gmail.com> References: <20180207092919.19696-1-sergey.senozhatsky@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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'. + */ +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