From patchwork Fri Jun 7 06:07:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10980801 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C7FC6C5 for ; Fri, 7 Jun 2019 06:08:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AB2B28B04 for ; Fri, 7 Jun 2019 06:08:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 748CA28B12; Fri, 7 Jun 2019 06:08:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1BF328B04 for ; Fri, 7 Jun 2019 06:08:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0DB26B026B; Fri, 7 Jun 2019 02:08:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BC6A36B0271; Fri, 7 Jun 2019 02:08:26 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A854E6B0272; Fri, 7 Jun 2019 02:08:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 6CA8F6B0271 for ; Fri, 7 Jun 2019 02:08:26 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id e69so737527pgc.7 for ; Thu, 06 Jun 2019 23:08:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=kobkxat34d1e9l/huh9zUhqEVZBstZvmQBkA4UmXIeg=; b=IvFydUUd56Os7BfSmmO1wUQM4AKC+FF+lRY1tpw9wTqHK6/1tBR2PB2fXoBxcTFYyP Om8d1cKmuq/e10KqM/wjbSucZLZgg99RxTkw66DPaXdm+smw4TN+IjoA87Sv3Hvw+9RU z4um/miaWIV0bybcCtTOwRqIVRRNye0FySHVH2PvoMrv1HuNZlbzVxQoev2IN+c+LlMU V55d6Mtcq+R4BONo5QMGOyAZxhFLv+HCiaJXesahA4ncWCH9C6LJDtVJe4SFYdNUnGhW 11VTxxT+BPjH1f2rCrgbDYriKWu7XJppbap2E9RfqoIpcdaH2amIKOOpcdGBM/CCpxLl 9rpQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.37 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: APjAAAX3DS0OFb1wX7R39DZv4m53eH6VhraO2svaoP2ya5JlXLTBeqsL lG+8BWItzcxUPbz9C997aKigD2amsOoZ9iQaYlT7Vudavb3wl0SQD9NAcLsgKuPNW63hdOwqWfV Tf61CqaFiF22dJuYfEPrmjDii8uvOb6L3qJbu/icEWvuNdyZuVKvljY6fsehIoz1r/Q== X-Received: by 2002:a62:2c8e:: with SMTP id s136mr12418487pfs.3.1559887705947; Thu, 06 Jun 2019 23:08:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqz8Td262Zpr78K3Q7MGb+4jdse42uZe2ZwnC3yJzH+bVOV9OE6WZNHQhwz8CYIbTciEo63H X-Received: by 2002:a62:2c8e:: with SMTP id s136mr12418406pfs.3.1559887705063; Thu, 06 Jun 2019 23:08:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559887705; cv=none; d=google.com; s=arc-20160816; b=Tz9dR7M7YDGEbxVkech/fUIqQEVwiEpI3oFzL8bY+T2/CKXAGLSa594wn2JVSERKHB jS1zcBp9tcgvS5Xe6FXTaQClNv9P4CQPCrJfw2puyVGsDbnsxW0qHLmmTJBp26LMFaKV E/rz0xoq7oL7oTK3Itn22dIdD8FQOwOpYYWT40376bL4a6M+L0TygOV99JqCxeGE2AAf JiL/9gwpgcXZq4CIDBc6+nhtgqI9FxMmHuI05nGLd8tQ+UXaBwQqdcjVEWru7W/gBwF5 CBsLxpAWWt2P2b3nkROvyFEG/5UXEES1Y1SVENQjfY71+9fszPWKeDK6q52synaGwHQ+ 5c3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=kobkxat34d1e9l/huh9zUhqEVZBstZvmQBkA4UmXIeg=; b=YPlUpHTn1WaJ2StO/T1PFjxJ6dqFTnnkYfWM66C097WtAX4U8TYW28lF7769fHkTS7 dW16StqxmjD3pACLGpXVmVqmPVMd2ylBxP0JX+otgMv9JjS5qNdewx67IxJqG2BBeztf 1ZQv3I8h6zHwuayOQGhI6ueFk3yMB4ue8/Dcl1fDlt+3D5QEJKSWRPZrXKSjYtZ/Wghj xaHqS4O5APz/HzBVXSCLbSi8B4ml/smB7S7wJZO51RKIMj3JLPa2UfSw365kFIuWKVAL HDIHNBGGqi4wMbKNI98cJJJpmdbT6xJxdrxq1BdeZgF0h2zHb5X7KF2QRCF0OJIf91+M ymeA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.37 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out4437.biz.mail.alibaba.com (out4437.biz.mail.alibaba.com. [47.88.44.37]) by mx.google.com with ESMTPS id l6si929299pjq.81.2019.06.06.23.08.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Jun 2019 23:08:25 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.37 as permitted sender) client-ip=47.88.44.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.37 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01422;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0TTcZLUN_1559887677; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TTcZLUN_1559887677) by smtp.aliyun-inc.com(127.0.0.1); Fri, 07 Jun 2019 14:08:09 +0800 From: Yang Shi To: ktkhai@virtuozzo.com, kirill.shutemov@linux.intel.com, hannes@cmpxchg.org, mhocko@suse.com, hughd@google.com, shakeelb@google.com, rientjes@google.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v2 PATCH 0/4] Make deferred split shrinker memcg aware Date: Fri, 7 Jun 2019 14:07:35 +0800 Message-Id: <1559887659-23121-1-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 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: X-Virus-Scanned: ClamAV using ClamSMTP Currently THP deferred split shrinker is not memcg aware, this may cause premature OOM with some configuration. For example the below test would run into premature OOM easily: $ cgcreate -g memory:thp $ echo 4G > /sys/fs/cgroup/memory/thp/memory/limit_in_bytes $ cgexec -g memory:thp transhuge-stress 4000 transhuge-stress comes from kernel selftest. It is easy to hit OOM, but there are still a lot THP on the deferred split queue, memcg direct reclaim can't touch them since the deferred split shrinker is not memcg aware. Convert deferred split shrinker memcg aware by introducing per memcg deferred split queue. The THP should be on either per node or per memcg deferred split queue if it belongs to a memcg. When the page is immigrated to the other memcg, it will be immigrated to the target memcg's deferred split queue too. And, move deleting THP from deferred split queue in page free before memcg uncharge so that the page's memcg information is available. Reuse the second tail page's deferred_list for per memcg list since the same THP can't be on multiple deferred split queues. Remove THP specific destructor since it is not used anymore with memcg aware THP shrinker (Please see the commit log of patch 3/4 for the details). Make deferred split shrinker not depend on memcg kmem since it is not slab. It doesn't make sense to not shrink THP even though memcg kmem is disabled. With the above change the test demonstrated above doesn't trigger OOM even though with cgroup.memory=nokmem. Changelog: v2: * Adopted the suggestion from Krill Shutemov to extract deferred split fields into a struct to reduce code duplication (patch 1/4). With this change, the lines of change is shrunk down to 198 from 278. * Removed memcg_deferred_list. Use deferred_list for both global and memcg. With the code deduplication, it doesn't make too much sense to keep it. Kirill Tkhai also suggested so. * Fixed typo for SHRINKER_NONSLAB. Yang Shi (4): mm: thp: extract split_queue_* into a struct mm: thp: make deferred split shrinker memcg aware mm: thp: remove THP destructor mm: shrinker: make shrinker not depend on memcg kmem include/linux/huge_mm.h | 15 +++++++++++ include/linux/memcontrol.h | 4 +++ include/linux/mm.h | 3 --- include/linux/mm_types.h | 1 + include/linux/mmzone.h | 12 ++++++--- include/linux/shrinker.h | 3 +-- mm/huge_memory.c | 99 ++++++++++++++++++++++++++++++++++++++++++++------------------------ mm/memcontrol.c | 19 +++++++++++++ mm/page_alloc.c | 11 ++++---- mm/swap.c | 4 +++ mm/vmscan.c | 27 +++++-------------- 11 files changed, 129 insertions(+), 69 deletions(-)