Received: by 10.223.176.5 with SMTP id f5csp17413wra; Sat, 10 Feb 2018 00:25:15 -0800 (PST) X-Google-Smtp-Source: AH8x2276xbhDHCmRvRI63SLGWXoxCfWKCX/c+u5jrF9wScTUWF1I3HjYBx8TdPvC0LCZaLSx4Kcm X-Received: by 2002:a17:902:a985:: with SMTP id bh5-v6mr4949367plb.230.1518251114993; Sat, 10 Feb 2018 00:25:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518251114; cv=none; d=google.com; s=arc-20160816; b=bAqZxpcr2d8iTfHdIFi/CxlnQHeUXhaYWrjdy5KxIuf/Kefb6mHz1butomweVnF6pD sIRul6jrEHs5EEh/mnstaxOBI11xViH9ITr6SkXF8Nih/h4UD2Rq7KLgc/5UUbdPKOLs zNOf55KZk2CTXtPkWdWQecUX4tgWPd7yAWYELCcxIPPoicoldEzHh/MNsacCsnH98s0N 1c37gHa/MAIMACAjg65H2VGK+8CNPVqGGbNW6Ny3uWLIVz/3yOR66BEtCOO/Q8jn/AfJ c5lxbSn6Phn5mAwLZfC9khzQ5+CIHjSmrRFor8FjHINLSd/2C0b5UQV6ix+P6+YHEMIx dS5A== 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=x/p5CWV2ErU+HgJsCsbLdHezkUEysIjfV/0NbF5iF4U=; b=P4N0FPREWlZQrNuuFnr+MxQwaedvRTcAIdBP/2nWB2U3sDxEoywXU2jcVetrre2m8Y GLddBfoNt89qEYz3YgiGI6WPZjczBiZF25YN3zZDr4J2OgtzmT6erlgenBxkkZu7gzio iEfGcs2MGsxFIYQvJnqDhDn5F4bZU/xJeleOdocV7+Z/3/BMOhFYRyqoQJpApptZPsjV nraQOyFhI2iTVdP4KMMCq+oC7VlyA//IDQHRpNLN4m1U6HQbCmbf4b7DLz+iHQMcY56b kSQB3xk11XegdnUvrVAbotSdOiLo4y1S27zM9d475EzAbXCxhHYN779bESV+aXj362g6 wm3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=S7tUhPnF; 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 c8-v6si137281plo.356.2018.02.10.00.24.48; Sat, 10 Feb 2018 00:25:14 -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=S7tUhPnF; 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 S1751027AbeBJIXp (ORCPT + 99 others); Sat, 10 Feb 2018 03:23:45 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36332 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750761AbeBJIXo (ORCPT ); Sat, 10 Feb 2018 03:23:44 -0500 Received: by mail-pg0-f67.google.com with SMTP id j9so3981131pgv.3 for ; Sat, 10 Feb 2018 00:23:44 -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=x/p5CWV2ErU+HgJsCsbLdHezkUEysIjfV/0NbF5iF4U=; b=S7tUhPnF7rY6wdC1z6FOtUpNTqVCTd9qI/swEP9XypOTl5K22ObmVJRzP/zgPZT1sf bEzNeKVLI16dBoFeGcXrB5s/i4sN3oA8qprVx4FZorS0BbgJGWVD1NKXs/AaIHQV1MO8 BWD2vEvACK2kBLhhJfz57s9ZQdCXWKuUlxq7TGYG6y6iBiVlOGPQ25iDtwcg00pFRTEr igioFvkHgF7g0SsGHbs5Ft9l17GqMEXbVKsz8YVIlYXb8Kt0DzhO8QnrOUweGOD73nn/ iI/E5CLGCKB0GLuYZf7ewOCrMjDwetFs3CgwfRXSGaZD6vdtV8D7yjXCfeeSEd3pZE0c WADA== 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=x/p5CWV2ErU+HgJsCsbLdHezkUEysIjfV/0NbF5iF4U=; b=iZVzeokc1s3jZI28SbdmxLcl7jtUF0TfNkPS8lmlz0bsQD9fGPd4Co56jpZQczlnfJ 8si7LfWGMt6M6/kANXc44XrEy9YWFe6Rr7/H4q3vjTPFs+AbQ6vxVHAp5v60vJwV0BAl sYDoBSX99j0QVaBpDog9IpxiHqYk5iGJDCLIGmGV8lUNlp6WPIvOpUS4vD7uKrLQHsKD UnN+vtG3Wyv0JQyg6N0U0/WFNKxNeQ0oLZ6ivyVlkbq3r6c+iXgJWGgG5D86igDebDET FUL0stFjt8Clb483a5GvFGyYZFIFw/u90jXbNUZYnwNyuwhlRMPJQnuhKB8hkIaC8aRg 8jxA== X-Gm-Message-State: APf1xPA2qbtYdYxweIIBYtp53za8OIclCsaUECnTtE1m6h6ac78oYJKi U9dyMbQUB26D3dIgzuy4nLs= X-Received: by 10.98.234.19 with SMTP id t19mr5536009pfh.74.1518251023647; Sat, 10 Feb 2018 00:23:43 -0800 (PST) Received: from localhost.localdomain ([121.137.63.184]) by smtp.gmail.com with ESMTPSA id y90sm10506861pfi.34.2018.02.10.00.23.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Feb 2018 00:23:42 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Mike Rapoport , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv2 1/2] zsmalloc: introduce zs_huge_object() function Date: Sat, 10 Feb 2018 17:23:21 +0900 Message-Id: <20180210082321.17798-1-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180207092919.19696-2-sergey.senozhatsky@gmail.com> References: <20180207092919.19696-2-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 | 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..922180183ca3 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 shall 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's size is too big, it will be stored in a huge class. + * * false - The object will be store in normal zspool classes. + */ +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; } /* debug only, don't abort if it fails */ -- 2.16.1