From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 042F1C11F68 for ; Fri, 2 Jul 2021 06:21:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA957613FA for ; Fri, 2 Jul 2021 06:21:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230087AbhGBGXd (ORCPT ); Fri, 2 Jul 2021 02:23:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbhGBGX1 (ORCPT ); Fri, 2 Jul 2021 02:23:27 -0400 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D756C061762; Thu, 1 Jul 2021 23:20:55 -0700 (PDT) Received: by mail-qv1-xf30.google.com with SMTP id dj3so4178374qvb.11; Thu, 01 Jul 2021 23:20:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hYWXH12CqnZMtZW0pOGnma+92SUvIYhPgYiicHyCps0=; b=pQwNRlKTGjy2M9pBSmsG0ces2zrOqUET4rUf+IEl0L7cNrn2VJv4Pz6h6LBQq/qszl 9fIV2kKFNq1/p8cadqBFJS9bAVNN2MAW5csSy4ud9gcPd+MV+qgZBEb7Jhklbf5RtxGk IEcVOea8EflMh3hi74fxCd+Js2P2j+0YAHCcA3hER/ZtY39t/NYfQx81miuURjYoBXAq 8Db2CXKtvbemUNRtQG2ZhmwVvHY5vLwf/pZhbyA/gYbHL6FyBxlIVIw21Yn8uyb+cUgC PtaeVkTK+F9ks2tNpRffQWQ2RI8cmnSGqWoDXFJvUJK3viyr1ygpb6BxMvazsccG1p0p IPag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hYWXH12CqnZMtZW0pOGnma+92SUvIYhPgYiicHyCps0=; b=XYsTdwZOSkwVT/1uujfy9Y2XSbHJNh6faYI59/DSA5O3j/9c4Wf9DJ27N0uGNc1/As bSX9fgJ2WqlNdaXaABTPB8H8rjxzPjd/DcykWwm9gszEGO0QmP00RVBGhHWPwzaHX15p JV7EZ17KZyBqaXNTZYM7hURJj7D/rJU2TMf8rdD7rExSUYP4pdNZxvo5rJV4Xyx0OB9U +sFy79u8TzTBQXy773zMgvb3rN9vq6P7S0bEl8B/KcekAe2gLMONGKxwbzgknipNfe/2 qkr9I57VcKG2F/nFpxAq8wbaa0WesDp4lHtUfjHtXJPxMpXaSnc2Hds4hLUWiRJx4P6m A6vg== X-Gm-Message-State: AOAM531E9u/T8hk/SHVJ1UfhQRMgvf/NKYxl+B+3ahu4ZkovPNP9UPY/ cS4FDiMXMBy7xUc5lr8ttL5axNH4Eh7KfROscfs= X-Google-Smtp-Source: ABdhPJyWdolrUsVPXoxZQ8ujjBZfyvsIfNOIUdm2Vus8RIEkG9WhT2mnr8LlKu3AUn45rS7CCoMmr1t4VDIBdj/4nQY= X-Received: by 2002:a05:6214:1244:: with SMTP id q4mr3424052qvv.50.1625206854038; Thu, 01 Jul 2021 23:20:54 -0700 (PDT) MIME-Version: 1.0 References: <20210630184624.9ca1937310b0dd5ce66b30e7@linux-foundation.org> <20210701015258.BrxjIzdE1%akpm@linux-foundation.org> In-Reply-To: From: Zhaoyang Huang Date: Fri, 2 Jul 2021 14:20:42 +0800 Message-ID: Subject: Re: [patch 108/192] mm: zram: amend SLAB_RECLAIM_ACCOUNT on zspage_cachep To: Minchan Kim Cc: LKML , Andrew Morton , "open list:MEMORY MANAGEMENT" , mm-commits@vger.kernel.org, Sergey Senozhatsky , torvalds@linux-foundation.org, Zhaoyang Huang Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 2, 2021 at 1:47 PM Minchan Kim wrote: > > On Fri, Jul 02, 2021 at 10:45:09AM +0800, Zhaoyang Huang wrote: > > On Thu, Jul 1, 2021 at 10:56 PM Minchan Kim wrote: > > > > > > On Wed, Jun 30, 2021 at 06:52:58PM -0700, Andrew Morton wrote: > > > > From: Zhaoyang Huang > > > > Subject: mm: zram: amend SLAB_RECLAIM_ACCOUNT on zspage_cachep > > > > > > > > Zspage_cachep is found be merged with other kmem cache during test, which > > > > is not good for debug things (zs_pool->zspage_cachep present to be another > > > > kmem cache in memory dumpfile). It is also neccessary to do so as > > > > shrinker has been registered for zspage. > > > > > > > > Amending this flag can help kernel to calculate SLAB_RECLAIMBLE correctly. > > > > > > > > Link: https://lkml.kernel.org/r/1623137297-29685-1-git-send-email-huangzhaoyang@gmail.com > > > > Signed-off-by: Zhaoyang Huang > > > > Cc: Minchan Kim > > > > Cc: Sergey Senozhatsky > > > > Signed-off-by: Andrew Morton > > > > > > Sorry for the late. I don't think this is correct. > > > > > > It's true "struct zspage" can be freed by zsmalloc's compaction registerred > > > by slab shrinker so tempted to make it SLAB_RECLAIM_ACCOUNT. However, it's > > > quite limited to work only when objects in the zspage are heavily fragmented. > > > Once the compaction is done, zspage are never discardable until objects are > > > fragmented again. It means it could hurt other reclaimable slab page reclaiming > > > since the zspage slab object pins the page. > > IMHO, kmem cache's reclaiming is NOT affected by SLAB_RECLAIM_ACCOUNT > > . This flag just affects kmem cache merge[1], the slab page's migrate > > type[2] and the page's statistics. Actually, zspage's cache DO merged > > with others even without SLAB_RECLAIM_ACCOUNT currently, which maybe > > cause zspage's object will NEVER be discarded.(SLAB_MERGE_SAME > > introduce confusions as people believe the cache will merge with > > others when it set and vice versa) > > > > [1] > > struct kmem_cache *find_mergeable(size_t size, size_t align, unsigned > > long flags, const char *name, void (*ctor)(void *)) > > ... > > if ((flags & SLAB_MERGE_SAME) != (s->flags & SLAB_MERGE_SAME)) > > continue; > > > > [2] > > if (s->flags & SLAB_RECLAIM_ACCOUNT) > > s->allocflags |= __GFP_RECLAIMABLE; > > That's the point here. With SLAB_RECLAIM_ACCOUNT, page allocator > try to allocate pages from MIGRATE_RECLAIMABLE with belief those > objects are easily reclaimable. Say a page has object A, B, C, D > and E. A-D are easily reclaimable but E is hard. What happens is > VM couldn't reclaim the page in the end due to E even though it > already reclaimed A-D. And the such fragmenation could be spread > out entire MIGRATE_RECLAIMABLE pageblocks over time. > That's why I'd like to put zspage into MIGRATE_UNMOVALBE from the > beginning since I don't think it's easily reclaimble once compaction > is done. The slab page could fallback to any migrate type even allocating with __GFP_RECLAIMABLE, and there is only one page per slab within zspage's cache, which will not be affected by compaction, so I think that doesn't make sense. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E0F9C11F68 for ; Fri, 2 Jul 2021 06:20:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2D1A0613FA for ; Fri, 2 Jul 2021 06:20:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D1A0613FA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9680D6B0011; Fri, 2 Jul 2021 02:20:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 917516B0036; Fri, 2 Jul 2021 02:20:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B7FC6B005D; Fri, 2 Jul 2021 02:20:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id 52E166B0011 for ; Fri, 2 Jul 2021 02:20:55 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 057C7824C741 for ; Fri, 2 Jul 2021 06:20:55 +0000 (UTC) X-FDA: 78316649670.12.C7D5A36 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) by imf09.hostedemail.com (Postfix) with ESMTP id B42B7300036E for ; Fri, 2 Jul 2021 06:20:54 +0000 (UTC) Received: by mail-qv1-f42.google.com with SMTP id cn9so2526554qvb.3 for ; Thu, 01 Jul 2021 23:20:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hYWXH12CqnZMtZW0pOGnma+92SUvIYhPgYiicHyCps0=; b=pQwNRlKTGjy2M9pBSmsG0ces2zrOqUET4rUf+IEl0L7cNrn2VJv4Pz6h6LBQq/qszl 9fIV2kKFNq1/p8cadqBFJS9bAVNN2MAW5csSy4ud9gcPd+MV+qgZBEb7Jhklbf5RtxGk IEcVOea8EflMh3hi74fxCd+Js2P2j+0YAHCcA3hER/ZtY39t/NYfQx81miuURjYoBXAq 8Db2CXKtvbemUNRtQG2ZhmwVvHY5vLwf/pZhbyA/gYbHL6FyBxlIVIw21Yn8uyb+cUgC PtaeVkTK+F9ks2tNpRffQWQ2RI8cmnSGqWoDXFJvUJK3viyr1ygpb6BxMvazsccG1p0p IPag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hYWXH12CqnZMtZW0pOGnma+92SUvIYhPgYiicHyCps0=; b=MfiAT0FmT3FHSv3mkpIp5q++qF/tpYNCarK4DeZtIy/ACn+E4Ad1FGeaG8QXj4QQg+ gx4md4Yp8xiB8qcgD0XSP+ROhFBagY72zK72ki+rdqN2lfEQT3LW5R951pFvgskmdsgI 1V9vrF8dn8czd1Mz7Vwpj+FipKyvrZ23OtSKkS9lvWKPxKHVhTPT6bcBbWM6gtwnoh6S 6ulEI5Af//phXghDUN8pdzNMd6RWA+Te3wPigWL8XSrcueKarE8ekuNwoRLxrW1td+DL c0DHsMadH3IHsu5N+kcXncQe95xn7o0RpX7B3iFOfi8gs8KKYdiNw+T6AwY3hqN/JBhm UL0w== X-Gm-Message-State: AOAM5307rSawM3AniDoZqR7MFpjDyfC3vg3i6EjcVfoAOfdSVus8sBTC SIhTixleaaNBqiM8LUY8fl4U+vXadJrEPcKU7Fc= X-Google-Smtp-Source: ABdhPJyWdolrUsVPXoxZQ8ujjBZfyvsIfNOIUdm2Vus8RIEkG9WhT2mnr8LlKu3AUn45rS7CCoMmr1t4VDIBdj/4nQY= X-Received: by 2002:a05:6214:1244:: with SMTP id q4mr3424052qvv.50.1625206854038; Thu, 01 Jul 2021 23:20:54 -0700 (PDT) MIME-Version: 1.0 References: <20210630184624.9ca1937310b0dd5ce66b30e7@linux-foundation.org> <20210701015258.BrxjIzdE1%akpm@linux-foundation.org> In-Reply-To: From: Zhaoyang Huang Date: Fri, 2 Jul 2021 14:20:42 +0800 Message-ID: Subject: Re: [patch 108/192] mm: zram: amend SLAB_RECLAIM_ACCOUNT on zspage_cachep To: Minchan Kim Cc: LKML , Andrew Morton , "open list:MEMORY MANAGEMENT" , mm-commits@vger.kernel.org, Sergey Senozhatsky , torvalds@linux-foundation.org, Zhaoyang Huang Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=pQwNRlKT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of huangzhaoyang@gmail.com designates 209.85.219.42 as permitted sender) smtp.mailfrom=huangzhaoyang@gmail.com X-Stat-Signature: rg3pqwkkdxn1x4zizuw8hk4cchnuotan X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B42B7300036E X-HE-Tag: 1625206854-509716 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Jul 2, 2021 at 1:47 PM Minchan Kim wrote: > > On Fri, Jul 02, 2021 at 10:45:09AM +0800, Zhaoyang Huang wrote: > > On Thu, Jul 1, 2021 at 10:56 PM Minchan Kim wrote: > > > > > > On Wed, Jun 30, 2021 at 06:52:58PM -0700, Andrew Morton wrote: > > > > From: Zhaoyang Huang > > > > Subject: mm: zram: amend SLAB_RECLAIM_ACCOUNT on zspage_cachep > > > > > > > > Zspage_cachep is found be merged with other kmem cache during test, which > > > > is not good for debug things (zs_pool->zspage_cachep present to be another > > > > kmem cache in memory dumpfile). It is also neccessary to do so as > > > > shrinker has been registered for zspage. > > > > > > > > Amending this flag can help kernel to calculate SLAB_RECLAIMBLE correctly. > > > > > > > > Link: https://lkml.kernel.org/r/1623137297-29685-1-git-send-email-huangzhaoyang@gmail.com > > > > Signed-off-by: Zhaoyang Huang > > > > Cc: Minchan Kim > > > > Cc: Sergey Senozhatsky > > > > Signed-off-by: Andrew Morton > > > > > > Sorry for the late. I don't think this is correct. > > > > > > It's true "struct zspage" can be freed by zsmalloc's compaction registerred > > > by slab shrinker so tempted to make it SLAB_RECLAIM_ACCOUNT. However, it's > > > quite limited to work only when objects in the zspage are heavily fragmented. > > > Once the compaction is done, zspage are never discardable until objects are > > > fragmented again. It means it could hurt other reclaimable slab page reclaiming > > > since the zspage slab object pins the page. > > IMHO, kmem cache's reclaiming is NOT affected by SLAB_RECLAIM_ACCOUNT > > . This flag just affects kmem cache merge[1], the slab page's migrate > > type[2] and the page's statistics. Actually, zspage's cache DO merged > > with others even without SLAB_RECLAIM_ACCOUNT currently, which maybe > > cause zspage's object will NEVER be discarded.(SLAB_MERGE_SAME > > introduce confusions as people believe the cache will merge with > > others when it set and vice versa) > > > > [1] > > struct kmem_cache *find_mergeable(size_t size, size_t align, unsigned > > long flags, const char *name, void (*ctor)(void *)) > > ... > > if ((flags & SLAB_MERGE_SAME) != (s->flags & SLAB_MERGE_SAME)) > > continue; > > > > [2] > > if (s->flags & SLAB_RECLAIM_ACCOUNT) > > s->allocflags |= __GFP_RECLAIMABLE; > > That's the point here. With SLAB_RECLAIM_ACCOUNT, page allocator > try to allocate pages from MIGRATE_RECLAIMABLE with belief those > objects are easily reclaimable. Say a page has object A, B, C, D > and E. A-D are easily reclaimable but E is hard. What happens is > VM couldn't reclaim the page in the end due to E even though it > already reclaimed A-D. And the such fragmenation could be spread > out entire MIGRATE_RECLAIMABLE pageblocks over time. > That's why I'd like to put zspage into MIGRATE_UNMOVALBE from the > beginning since I don't think it's easily reclaimble once compaction > is done. The slab page could fallback to any migrate type even allocating with __GFP_RECLAIMABLE, and there is only one page per slab within zspage's cache, which will not be affected by compaction, so I think that doesn't make sense.