Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1337896

Re: [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE

From Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Newsgroups linux.kernel
Subject Re: [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE
Date 2016-02-19 06:40 +0100
Message-ID <r3LXk-it-9@gated-at.bofh.it> (permalink)
References (3 earlier) <r3txn-3CY-7@gated-at.bofh.it> <r3tQK-3ZS-7@gated-at.bofh.it> <r3I3o-5VX-11@gated-at.bofh.it> <r3KHU-7NJ-7@gated-at.bofh.it> <r3LaX-822-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On (02/19/16 13:46), Sergey Senozhatsky wrote:
> On (02/19/16 13:16), Sergey Senozhatsky wrote:
> > ok, this sets us on a  "do we need 32 and 48 bytes classes at all"  track?
> > 
> 
> seems that lz4 defines a minimum length to be at least
> 
>  61 #define COPYLENGTH 8
>  67 #define MINMATCH        4
>  70 #define MFLIMIT         (COPYLENGTH + MINMATCH)
>  71 #define MINLENGTH       (MFLIMIT + 1)
> 
> bytes.

hm, on a second look, zsmalloc defines the following macros:

#define ZS_MAX_ZSPAGE_ORDER 2
#define ZS_MAX_PAGES_PER_ZSPAGE (_AC(1, UL) << ZS_MAX_ZSPAGE_ORDER)

#ifndef MAX_PHYSMEM_BITS
#ifdef CONFIG_HIGHMEM64G
#define MAX_PHYSMEM_BITS 36
#else /* !CONFIG_HIGHMEM64G */
/*
 * If this definition of MAX_PHYSMEM_BITS is used, OBJ_INDEX_BITS will just
 * be PAGE_SHIFT
 */
#define MAX_PHYSMEM_BITS BITS_PER_LONG
#endif
#endif

#define _PFN_BITS		(MAX_PHYSMEM_BITS - PAGE_SHIFT)

#define OBJ_ALLOCATED_TAG 1
#define OBJ_TAG_BITS 1
#define OBJ_INDEX_BITS	(BITS_PER_LONG - _PFN_BITS - OBJ_TAG_BITS)
#define OBJ_INDEX_MASK	((_AC(1, UL) << OBJ_INDEX_BITS) - 1)

#define ZS_MIN_ALLOC_SIZE \
	MAX(32, (ZS_MAX_PAGES_PER_ZSPAGE << PAGE_SHIFT >> OBJ_INDEX_BITS))





so let's do some calculations, hopefuly I'm not mistaken anywhere.

with ZS_MAX_ZSPAGE_ORDER 4

-- on 32 bit system, PAGE_SHIFT 12

ZS_MAX_PAGES_PER_ZSPAGE 1 << 4						16
OBJ_INDEX_BITS (32 - (32 - 12) - 1)					11
OBJ_INDEX_MASK ((1 << (32 - (32 - 12) - 1)) - 1)			2047
ZS_MIN_ALLOC_SIZE MAX(32, ((1 << 4) << 12 >> (32 - (32 - 12) - 1)))	32

-- on 64 bit system, PAGE_SHIFT 12

ZS_MAX_PAGES_PER_ZSPAGE 1 << 4						16
OBJ_INDEX_BITS (64 - (64 - 12) - 1)					11
OBJ_INDEX_MASK ((1 << (64 - (64 - 12) - 1)) - 1)			2047
ZS_MIN_ALLOC_SIZE MAX(32, ((1 << 4) << 12 >> (64 - (64 - 12) - 1)))	32

-- on 64 bit system, PAGE_SHIFT 14

ZS_MAX_PAGES_PER_ZSPAGE 1 << 4						16
OBJ_INDEX_BITS (64 - (64 - 14) - 1)					13
OBJ_INDEX_MASK ((1 << (64 - (64 - 14) - 1)) - 1)			8191
ZS_MIN_ALLOC_SIZE MAX(32, ((1 << 4) << 14 >> (64 - (64 - 14) - 1)))	32

-- on 64 bit system, PAGE_SHIFT 16

ZS_MAX_PAGES_PER_ZSPAGE 1 << 4						16
OBJ_INDEX_BITS (64 - (64 - 16) - 1)					15
OBJ_INDEX_MASK ((1 << (64 - (64 - 16) - 1)) - 1)			32767
ZS_MIN_ALLOC_SIZE MAX(32, ((1 << 4) << 16 >> (64 - (64 - 14) - 1)))	128     << bad


so, isn't it enough OBJ_INDEX_BITS bits to even keep 32 bytes class around?

we probably would prefer to lower ZS_MAX_ZSPAGE_ORDER on PAGE_SHIFT 16 systems.
for example to ZS_MAX_PAGES_PER_ZSPAGE 1 << 3, or 1 << 2.
and of course LPAE/PAE enabled systems -- leave ZS_MAX_ZSPAGE_ORDER 2 there.




ZS_MAX_PAGES_PER_ZSPAGE 1 << 4  gives us

# cat /sys/kernel/debug/zsmalloc/zram0/classes 
  class  size  huge almost_full almost_empty obj_allocated   obj_used pages_used pages_per_zspage
     0    32             0            0             0          0          0                1
...
   238  3840             0            0             0          0          0               15
   254  4096 Y           0            0             0          0          0                1


so starting from 3840+ we have huge classes, the rest are 'normal' classes and will
save memory there in theory.

	-ss

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC PATCH 0/3] mm/zsmalloc: increase density and reduce memory wastage Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-02-18 04:10 +0100
  [RFC PATCH 2/3] zram: use zs_get_huge_class_size_watermark() Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-02-18 04:10 +0100
  [RFC PATCH 1/3] mm/zsmalloc: introduce zs_get_huge_class_size_watermark() Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-02-18 04:10 +0100
  [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-02-18 04:10 +0100
    Re: [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-02-18 05:50 +0100
      Re: [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-02-18 05:50 +0100
      Re: [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-02-18 06:10 +0100
    Re: [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE Joonsoo Kim <js1304@gmail.com> - 2016-02-18 09:30 +0100
      Re: [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-02-18 11:00 +0100
        Re: [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-02-18 11:20 +0100
          Re: [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE Joonsoo Kim <js1304@gmail.com> - 2016-02-19 02:30 +0100
            Re: [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-02-19 05:20 +0100
            Re: [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-02-19 05:20 +0100
              Re: [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-02-19 05:50 +0100
                Re: [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-02-19 06:40 +0100
                Re: [RFC PATCH 3/3] mm/zsmalloc: change ZS_MAX_PAGES_PER_ZSPAGE Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-02-19 07:00 +0100

csiph-web