From patchwork Tue May 28 12:44:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10964853 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 7F98B1575 for ; Tue, 28 May 2019 12:45:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DEB728844 for ; Tue, 28 May 2019 12:45:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 626B328857; Tue, 28 May 2019 12:45:03 +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 126E428844 for ; Tue, 28 May 2019 12:45:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7737B6B0276; Tue, 28 May 2019 08:44:59 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 727396B027C; Tue, 28 May 2019 08:44:59 -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 4B4DF6B027E; Tue, 28 May 2019 08:44:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 01DD56B0276 for ; Tue, 28 May 2019 08:44:59 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id f8so13948256pgp.9 for ; Tue, 28 May 2019 05:44:58 -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:in-reply-to:references; bh=FF8PtXCBZjUwZN9MncBHEp3PSXjlhKJu5GvSn2I51OE=; b=PSBx0XnKo8gfO0k1fxJ4AYgfswgQBO4VRnlhk6S8CjzzGRJiz8TXlgFSKr/9S5WNgC 04tbqzvQ5vU+aHVRKmVJ/yhgmSIx5GFDpS8KjB8lS/puTykmwoQlTw+Gw3no9uhzUSSu 5TjSuzFI1P7K5IDFLRQLSg2eKP3IrUj2GG6Fb/IzdnkfrHE/SV7JXwqW9QpRzCW0iwQC ScdL7gaNt8RdN/Yq/n0q7sKJ8BHZgNMHdgYcbqnOzwnin81197hoSEiH7zasY6DVctcg blYw77V9Iy6Vhno5LsMMD9BtSL1syB+WyXrJN68quxtsIptlB6tYZpxUz3iD8FOTBMka rhKw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 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: APjAAAUBFneW2lnuBGr7GQTU5N3WLID9/tX/nHvwoeUlu36Tg8R4xBSV QhKadkIuZ7sjhXILM/pq/c+7gPPTaRkKqs6xW7ukDDYFShyM2dn6kMgdTM4Tmq1HgfAI03J3LK0 sjd++RlIIhEYVOVsca4w8357f+/tz/5Wkj5PborlclnUxNSajr+DCerDReYTIBVzXXw== X-Received: by 2002:a63:cc4e:: with SMTP id q14mr129600560pgi.84.1559047498589; Tue, 28 May 2019 05:44:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqyW78vS6F40StZqYGtQZ7Pnw+OID5lAkgZvhcg4e7ufepSi3Q8GIV0r0Yk8BuwU+QMkNtu6 X-Received: by 2002:a63:cc4e:: with SMTP id q14mr129600407pgi.84.1559047497040; Tue, 28 May 2019 05:44:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559047497; cv=none; d=google.com; s=arc-20160816; b=g/Y5kki90vcMHrchSaivIBW9/gEEbxmINslHrYyLfECVZdVstJKr0LZpdpyzphrFYo oXqeNbKT1iN0n9FFBDQiSyJqMSlEiueihpulIFYia0cmsXG1lDq9MHenqH9THCgHY6Tc AoOXytlp05O+frh7jNwjhfN1ZSb8kMjICTt1NtqApdgZo6MReKZKLUUVq/HBlAzfcW7x 24PfezHM+ULBpMFazjaP7t9nDydkkw/Myqh5MXijXdRbzbU9AybTPvIaClqEPUrCPNt3 1hWPa+iOPrIge511bVpdMLanP9YXsuyLoeJH/g68znW+j6LEwRhjcT3Icoamcu1kXiNl qlrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=FF8PtXCBZjUwZN9MncBHEp3PSXjlhKJu5GvSn2I51OE=; b=xU1nuGSsqpZGC4lShBn33YVLXdga5QSEYN0d4vLRlVD3Hws8bJRQjTcA4YtSvGzYOw +DvVi9YLGY36T1VHf5Jch5t275nao4nxW/znC83ThsbqqTBUfU1PMVIUAkQ5itOFhw9v XNZZyzcY0NCj9f7/CXWUerolv271VCM7k/ReJ032l6dmvaBwtvskvYFShY8sFOpn6Fq+ NfkagLBFZqL7CCW7OdSWp/emO3Nr3OK51Suozk1FGYOgj6i2OT0ouaeJPoQU1EC5xEDR yMZHz7M3B1J2CM/7B0voIbL34rbVrb12fwcn43vdK4wUVAZs9X1ukC1ZpuIoq81ud/NC c3/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out4436.biz.mail.alibaba.com (out4436.biz.mail.alibaba.com. [47.88.44.36]) by mx.google.com with ESMTPS id y1si21288026pgf.211.2019.05.28.05.44.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 May 2019 05:44:57 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) client-ip=47.88.44.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 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=01201311R111e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04420;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0TStMl0v_1559047475; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TStMl0v_1559047475) by smtp.aliyun-inc.com(127.0.0.1); Tue, 28 May 2019 20:44:42 +0800 From: Yang Shi To: ktkhai@virtuozzo.com, hannes@cmpxchg.org, mhocko@suse.com, kirill.shutemov@linux.intel.com, hughd@google.com, shakeelb@google.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] mm: thp: make deferred split shrinker memcg aware Date: Tue, 28 May 2019 20:44:22 +0800 Message-Id: <1559047464-59838-2-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1559047464-59838-1-git-send-email-yang.shi@linux.alibaba.com> References: <1559047464-59838-1-git-send-email-yang.shi@linux.alibaba.com> 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. Cc: Kirill Tkhai Cc: Johannes Weiner Cc: Michal Hocko Cc: "Kirill A . Shutemov" Cc: Hugh Dickins Cc: Shakeel Butt Signed-off-by: Yang Shi --- include/linux/huge_mm.h | 24 ++++++ include/linux/memcontrol.h | 6 ++ include/linux/mm_types.h | 7 +- mm/huge_memory.c | 182 +++++++++++++++++++++++++++++++++------------ mm/memcontrol.c | 20 +++++ mm/swap.c | 4 + 6 files changed, 194 insertions(+), 49 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 7cd5c15..f6d1cde 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -250,6 +250,26 @@ static inline bool thp_migration_supported(void) return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION); } +static inline struct list_head *page_deferred_list(struct page *page) +{ + /* + * Global deferred list in the second tail pages is occupied by + * compound_head. + */ + return &page[2].deferred_list; +} + +static inline struct list_head *page_memcg_deferred_list(struct page *page) +{ + /* + * Memcg deferred list in the second tail pages is occupied by + * compound_head. + */ + return &page[2].memcg_deferred_list; +} + +extern void del_thp_from_deferred_split_queue(struct page *); + #else /* CONFIG_TRANSPARENT_HUGEPAGE */ #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; }) #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; }) @@ -368,6 +388,10 @@ static inline bool thp_migration_supported(void) { return false; } + +static inline void del_thp_from_deferred_split_queue(struct page *page) +{ +} #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif /* _LINUX_HUGE_MM_H */ diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index bc74d6a..9ff5fab 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -316,6 +316,12 @@ struct mem_cgroup { struct list_head event_list; spinlock_t event_list_lock; +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + struct list_head split_queue; + unsigned long split_queue_len; + spinlock_t split_queue_lock; +#endif + struct mem_cgroup_per_node *nodeinfo[0]; /* WARNING: nodeinfo must be the last member here */ }; diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 8ec38b1..405f5e6 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -139,7 +139,12 @@ struct page { struct { /* Second tail page of compound page */ unsigned long _compound_pad_1; /* compound_head */ unsigned long _compound_pad_2; - struct list_head deferred_list; + union { + /* Global THP deferred split list */ + struct list_head deferred_list; + /* Memcg THP deferred split list */ + struct list_head memcg_deferred_list; + }; }; struct { /* Page table pages */ unsigned long _pt_pad_1; /* compound_head */ diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 9f8bce9..0b9cfe1 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -492,12 +492,6 @@ pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma) return pmd; } -static inline struct list_head *page_deferred_list(struct page *page) -{ - /* ->lru in the tail pages is occupied by compound_head. */ - return &page[2].deferred_list; -} - void prep_transhuge_page(struct page *page) { /* @@ -505,7 +499,10 @@ void prep_transhuge_page(struct page *page) * as list_head: assuming THP order >= 2 */ - INIT_LIST_HEAD(page_deferred_list(page)); + if (mem_cgroup_disabled()) + INIT_LIST_HEAD(page_deferred_list(page)); + else + INIT_LIST_HEAD(page_memcg_deferred_list(page)); set_compound_page_dtor(page, TRANSHUGE_PAGE_DTOR); } @@ -2664,6 +2661,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) bool mlocked; unsigned long flags; pgoff_t end; + struct mem_cgroup *memcg = head->mem_cgroup; VM_BUG_ON_PAGE(is_huge_zero_page(page), page); VM_BUG_ON_PAGE(!PageLocked(page), page); @@ -2744,17 +2742,30 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) } /* Prevent deferred_split_scan() touching ->_refcount */ - spin_lock(&pgdata->split_queue_lock); + if (!memcg) + spin_lock(&pgdata->split_queue_lock); + else + spin_lock(&memcg->split_queue_lock); count = page_count(head); mapcount = total_mapcount(head); if (!mapcount && page_ref_freeze(head, 1 + extra_pins)) { - if (!list_empty(page_deferred_list(head))) { - pgdata->split_queue_len--; - list_del(page_deferred_list(head)); + if (!memcg) { + if (!list_empty(page_deferred_list(head))) { + pgdata->split_queue_len--; + list_del(page_deferred_list(head)); + } + } else { + if (!list_empty(page_memcg_deferred_list(head))) { + memcg->split_queue_len--; + list_del(page_memcg_deferred_list(head)); + } } if (mapping) __dec_node_page_state(page, NR_SHMEM_THPS); - spin_unlock(&pgdata->split_queue_lock); + if (!memcg) + spin_unlock(&pgdata->split_queue_lock); + else + spin_unlock(&memcg->split_queue_lock); __split_huge_page(page, list, end, flags); if (PageSwapCache(head)) { swp_entry_t entry = { .val = page_private(head) }; @@ -2771,7 +2782,10 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) dump_page(page, "total_mapcount(head) > 0"); BUG(); } - spin_unlock(&pgdata->split_queue_lock); + if (!memcg) + spin_unlock(&pgdata->split_queue_lock); + else + spin_unlock(&memcg->split_queue_lock); fail: if (mapping) xa_unlock(&mapping->i_pages); spin_unlock_irqrestore(&pgdata->lru_lock, flags); @@ -2791,17 +2805,40 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) return ret; } -void free_transhuge_page(struct page *page) +void del_thp_from_deferred_split_queue(struct page *page) { struct pglist_data *pgdata = NODE_DATA(page_to_nid(page)); unsigned long flags; + struct mem_cgroup *memcg = compound_head(page)->mem_cgroup; - spin_lock_irqsave(&pgdata->split_queue_lock, flags); - if (!list_empty(page_deferred_list(page))) { - pgdata->split_queue_len--; - list_del(page_deferred_list(page)); + /* + * The THP may be not on LRU at this point, e.g. the old page of + * NUMA migration. And PageTransHuge is not enough to distinguish + * with other compound page, e.g. skb, THP destructor is not used + * anymore and will be removed, so the compound order sounds like + * the only choice here. + */ + if (PageTransHuge(page) && compound_order(page) == HPAGE_PMD_ORDER) { + if (!memcg) { + spin_lock_irqsave(&pgdata->split_queue_lock, flags); + if (!list_empty(page_deferred_list(page))) { + pgdata->split_queue_len--; + list_del(page_deferred_list(page)); + } + spin_unlock_irqrestore(&pgdata->split_queue_lock, flags); + } else { + spin_lock_irqsave(&memcg->split_queue_lock, flags); + if (!list_empty(page_memcg_deferred_list(page))) { + memcg->split_queue_len--; + list_del(page_memcg_deferred_list(page)); + } + spin_unlock_irqrestore(&memcg->split_queue_lock, flags); + } } - spin_unlock_irqrestore(&pgdata->split_queue_lock, flags); +} + +void free_transhuge_page(struct page *page) +{ free_compound_page(page); } @@ -2809,23 +2846,41 @@ void deferred_split_huge_page(struct page *page) { struct pglist_data *pgdata = NODE_DATA(page_to_nid(page)); unsigned long flags; + struct mem_cgroup *memcg; VM_BUG_ON_PAGE(!PageTransHuge(page), page); - spin_lock_irqsave(&pgdata->split_queue_lock, flags); - if (list_empty(page_deferred_list(page))) { - count_vm_event(THP_DEFERRED_SPLIT_PAGE); - list_add_tail(page_deferred_list(page), &pgdata->split_queue); - pgdata->split_queue_len++; + memcg = compound_head(page)->mem_cgroup; + if (!memcg) { + spin_lock_irqsave(&pgdata->split_queue_lock, flags); + if (list_empty(page_deferred_list(page))) { + count_vm_event(THP_DEFERRED_SPLIT_PAGE); + list_add_tail(page_deferred_list(page), &pgdata->split_queue); + pgdata->split_queue_len++; + } + spin_unlock_irqrestore(&pgdata->split_queue_lock, flags); + } else { + spin_lock_irqsave(&memcg->split_queue_lock, flags); + if (list_empty(page_memcg_deferred_list(page))) { + count_vm_event(THP_DEFERRED_SPLIT_PAGE); + list_add_tail(page_memcg_deferred_list(page), + &memcg->split_queue); + memcg->split_queue_len++; + memcg_set_shrinker_bit(memcg, page_to_nid(page), + deferred_split_shrinker.id); + } + spin_unlock_irqrestore(&memcg->split_queue_lock, flags); } - spin_unlock_irqrestore(&pgdata->split_queue_lock, flags); } static unsigned long deferred_split_count(struct shrinker *shrink, struct shrink_control *sc) { - struct pglist_data *pgdata = NODE_DATA(sc->nid); - return READ_ONCE(pgdata->split_queue_len); + if (!sc->memcg) { + struct pglist_data *pgdata = NODE_DATA(sc->nid); + return READ_ONCE(pgdata->split_queue_len); + } else + return READ_ONCE(sc->memcg->split_queue_len); } static unsigned long deferred_split_scan(struct shrinker *shrink, @@ -2837,22 +2892,40 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, struct page *page; int split = 0; - spin_lock_irqsave(&pgdata->split_queue_lock, flags); - /* Take pin on all head pages to avoid freeing them under us */ - list_for_each_safe(pos, next, &pgdata->split_queue) { - page = list_entry((void *)pos, struct page, mapping); - page = compound_head(page); - if (get_page_unless_zero(page)) { - list_move(page_deferred_list(page), &list); - } else { - /* We lost race with put_compound_page() */ - list_del_init(page_deferred_list(page)); - pgdata->split_queue_len--; + if (!sc->memcg) { + spin_lock_irqsave(&pgdata->split_queue_lock, flags); + /* Take pin on all head pages to avoid freeing them under us */ + list_for_each_safe(pos, next, &pgdata->split_queue) { + page = list_entry((void *)pos, struct page, mapping); + page = compound_head(page); + if (get_page_unless_zero(page)) { + list_move(page_deferred_list(page), &list); + } else { + /* We lost race with put_compound_page() */ + list_del_init(page_deferred_list(page)); + pgdata->split_queue_len--; + } + if (!--sc->nr_to_scan) + break; } - if (!--sc->nr_to_scan) - break; + spin_unlock_irqrestore(&pgdata->split_queue_lock, flags); + } else { + spin_lock_irqsave(&sc->memcg->split_queue_lock, flags); + list_for_each_safe(pos, next, &sc->memcg->split_queue) { + page = list_entry((void *)pos, struct page, mapping); + page = compound_head(page); + if (get_page_unless_zero(page)) { + list_move(page_memcg_deferred_list(page), &list); + } else { + /* We lost race with put_compound_page() */ + list_del_init(page_memcg_deferred_list(page)); + sc->memcg->split_queue_len--; + } + if (!--sc->nr_to_scan) + break; + } + spin_unlock_irqrestore(&sc->memcg->split_queue_lock, flags); } - spin_unlock_irqrestore(&pgdata->split_queue_lock, flags); list_for_each_safe(pos, next, &list) { page = list_entry((void *)pos, struct page, mapping); @@ -2866,16 +2939,29 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, put_page(page); } - spin_lock_irqsave(&pgdata->split_queue_lock, flags); - list_splice_tail(&list, &pgdata->split_queue); - spin_unlock_irqrestore(&pgdata->split_queue_lock, flags); - + if (!sc->memcg) { + spin_lock_irqsave(&pgdata->split_queue_lock, flags); + list_splice_tail(&list, &pgdata->split_queue); + spin_unlock_irqrestore(&pgdata->split_queue_lock, flags); + } else { + spin_lock_irqsave(&sc->memcg->split_queue_lock, flags); + list_splice_tail(&list, &sc->memcg->split_queue); + spin_unlock_irqrestore(&sc->memcg->split_queue_lock, flags); + } /* * Stop shrinker if we didn't split any page, but the queue is empty. * This can happen if pages were freed under us. */ - if (!split && list_empty(&pgdata->split_queue)) - return SHRINK_STOP; + if (!split) { + if (!sc->memcg) { + if (list_empty(&pgdata->split_queue)) + return SHRINK_STOP; + } else { + if (list_empty(&sc->memcg->split_queue)) + return SHRINK_STOP; + } + } + return split; } @@ -2883,7 +2969,7 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, .count_objects = deferred_split_count, .scan_objects = deferred_split_scan, .seeks = DEFAULT_SEEKS, - .flags = SHRINKER_NUMA_AWARE, + .flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE, }; #ifdef CONFIG_DEBUG_FS diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e50a2db..6418fa0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4579,6 +4579,11 @@ static struct mem_cgroup *mem_cgroup_alloc(void) #ifdef CONFIG_CGROUP_WRITEBACK INIT_LIST_HEAD(&memcg->cgwb_list); #endif +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + spin_lock_init(&memcg->split_queue_lock); + INIT_LIST_HEAD(&memcg->split_queue); + memcg->split_queue_len = 0; +#endif idr_replace(&mem_cgroup_idr, memcg, memcg->id.id); return memcg; fail: @@ -4949,6 +4954,21 @@ static int mem_cgroup_move_account(struct page *page, __mod_memcg_state(to, NR_WRITEBACK, nr_pages); } +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + if (compound && !list_empty(page_memcg_deferred_list(page))) { + spin_lock(&from->split_queue_lock); + list_del(page_memcg_deferred_list(page)); + from->split_queue_len--; + spin_unlock(&from->split_queue_lock); + + spin_lock(&to->split_queue_lock); + list_add_tail(page_memcg_deferred_list(page), + &to->split_queue); + to->split_queue_len++; + spin_unlock(&to->split_queue_lock); + } +#endif + /* * It is safe to change page->mem_cgroup here because the page * is referenced, charged, and isolated - we can't race with diff --git a/mm/swap.c b/mm/swap.c index 3a75722..3348295 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -69,6 +69,10 @@ static void __page_cache_release(struct page *page) del_page_from_lru_list(page, lruvec, page_off_lru(page)); spin_unlock_irqrestore(&pgdat->lru_lock, flags); } + + /* Delete THP from deferred split queue before memcg uncharge */ + del_thp_from_deferred_split_queue(page); + __ClearPageWaiters(page); mem_cgroup_uncharge(page); } From patchwork Tue May 28 12:44:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10964855 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 294AA1575 for ; Tue, 28 May 2019 12:46:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13C6428479 for ; Tue, 28 May 2019 12:46:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 062B5287F5; Tue, 28 May 2019 12:46:00 +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 79A5D28479 for ; Tue, 28 May 2019 12:45:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A09406B026E; Tue, 28 May 2019 08:45:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9BA226B027C; Tue, 28 May 2019 08:45:58 -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 8D0616B027E; Tue, 28 May 2019 08:45:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 5877B6B026E for ; Tue, 28 May 2019 08:45:58 -0400 (EDT) Received: by mail-pf1-f197.google.com with SMTP id i8so15633094pfo.21 for ; Tue, 28 May 2019 05:45:58 -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:in-reply-to:references; bh=Tr6OFS5Oxvi0s6GjNtS1zQPYLjHYXXZZYXHV57erJ6I=; b=gXobagwunNLR/UXisUs6Uw/ZMceXSPjVRBJFxllts71d6nmwu75xYg8MN5um2nhh3S BcE7lHFbsmTdm8jd8B+DCk76nOwdeEuumaEzq6AeFXqvpPvvUOk0TI6TTjiIPx/2mMcY 6Y/bgCa4DxzzUjH0wam/GoKBlDROWJh1M6xi6MNkcnzy7TKVIR8p0F81b4QJQcTl91pt 1rFqDB6E5+f/6e0CDkNVVBAqQ4zFh/g1wwcOKfZS7KuTh+U1doUTU1zoCIKnkyk8vwXO ppxh0/A4XkRCSuSx4H8niMqbwPA/SIY3yI/8F8RRecdJ36Ynk22nATPQ5iW0ID4HZc5i G+Iw== 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: APjAAAVoHZvsiNp+HKKg5S3xMmwzL6i2MqybbixWnT1Y0yuCVJn4X6se JXo/cVW3b41uDMIWtLESP7I0i2MmtSI52hyzwic9wp95fEvrq37ECfadg5hT4YHrZrAgZefVVRf sZDF1jWctjyFd9ZQUd8hj6cXGsJ6o2R2OpTLRx0/9yGRcO2PgcZntdM3Uc6g2aCIung== X-Received: by 2002:a65:5785:: with SMTP id b5mr96895666pgr.252.1559047558008; Tue, 28 May 2019 05:45:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4YU2tJnQiro+/4kA56TJdYGXFZL+Hb05ivwo5Ps8QGJM5KKpe9fXY7VV0ZsZSeYk+/j+X X-Received: by 2002:a65:5785:: with SMTP id b5mr96895542pgr.252.1559047556906; Tue, 28 May 2019 05:45:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559047556; cv=none; d=google.com; s=arc-20160816; b=fJEw4ZlVqxcdKxX1jTqAAk5k2HyPGrJQTdixQaK6n1EbBmODPTf9dIFO7kljkfPLzS fCM9w924oe0xzV0HdozWDk37i1WVMEdLar1hGZPG60A606jJ3iPjjVQ1ytcC6FAI3VLi yGOYDuy1xM8LrsYNVQyPyE9OWRLm3KkxVbJiZr14taR0mUrlSFtUfeVlPLmdDStU8hRA DY8eenUoqlRazDaL6Ma7oGv9gm3CVYzprtToSi4SUq+I6BccMLwr8VCJFMz40bw6Bb6c U6iw+rvN0fOJKHW4irgTwWXfIvzNH9tykzkYCX89GvnEHiPVVdEyIFLSMaWr9dnG/aSu LOyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=Tr6OFS5Oxvi0s6GjNtS1zQPYLjHYXXZZYXHV57erJ6I=; b=vmWw+TvA1mk+cSOd8/2z02gVb/RtXu3bl3dJNlL2wFnuErbnk+eAXK9hA/yX3LTKm2 CbYIYETvPNpAgg98Y90VX9pHHxfz9l7cixa4slKXK6P9kKi3pEa0SwyU8pzn0NJEk0BX p1Rwgp84gFpp40RS41Gc9HL1qLchkLYMhc7W5lzqIib1ISN514nyUlMPchQshbh1FLVN 0PAldvXkrAyqVuU2inpvRITGe7YQM+gn5FfRsh6oz2s6g2M4YRoFqxeBj6xFF/r+hbX5 cDAevzgWwSHEHUhR21aSSjq5IiVe6TrA5R+xyhcuM2RtOp11AAK/wRHWXErpzdHsGc0x dlkg== 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 k15si22885591pfi.61.2019.05.28.05.45.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 May 2019 05:45:56 -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=01201311R361e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07417;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0TStMl0v_1559047475; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TStMl0v_1559047475) by smtp.aliyun-inc.com(127.0.0.1); Tue, 28 May 2019 20:44:42 +0800 From: Yang Shi To: ktkhai@virtuozzo.com, hannes@cmpxchg.org, mhocko@suse.com, kirill.shutemov@linux.intel.com, hughd@google.com, shakeelb@google.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] mm: thp: remove THP destructor Date: Tue, 28 May 2019 20:44:23 +0800 Message-Id: <1559047464-59838-3-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1559047464-59838-1-git-send-email-yang.shi@linux.alibaba.com> References: <1559047464-59838-1-git-send-email-yang.shi@linux.alibaba.com> 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 The THP destructor is used to delete THP from per node deferred split queue, now the operation is moved out of it, so the destructor is not used anymore, remove it. Cc: Kirill Tkhai Cc: Johannes Weiner Cc: Michal Hocko Cc: "Kirill A . Shutemov" Cc: Hugh Dickins Cc: Shakeel Butt Signed-off-by: Yang Shi --- include/linux/mm.h | 3 --- mm/huge_memory.c | 6 ------ mm/page_alloc.c | 3 --- 3 files changed, 12 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 0e8834a..e543984 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -740,9 +740,6 @@ enum compound_dtor_id { #ifdef CONFIG_HUGETLB_PAGE HUGETLB_PAGE_DTOR, #endif -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - TRANSHUGE_PAGE_DTOR, -#endif NR_COMPOUND_DTORS, }; extern compound_page_dtor * const compound_page_dtors[]; diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 0b9cfe1..91a709e 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -503,7 +503,6 @@ void prep_transhuge_page(struct page *page) INIT_LIST_HEAD(page_deferred_list(page)); else INIT_LIST_HEAD(page_memcg_deferred_list(page)); - set_compound_page_dtor(page, TRANSHUGE_PAGE_DTOR); } static unsigned long __thp_get_unmapped_area(struct file *filp, unsigned long len, @@ -2837,11 +2836,6 @@ void del_thp_from_deferred_split_queue(struct page *page) } } -void free_transhuge_page(struct page *page) -{ - free_compound_page(page); -} - void deferred_split_huge_page(struct page *page) { struct pglist_data *pgdata = NODE_DATA(page_to_nid(page)); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 3b13d39..7d39b91 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -261,9 +261,6 @@ bool pm_suspended_storage(void) #ifdef CONFIG_HUGETLB_PAGE free_huge_page, #endif -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - free_transhuge_page, -#endif }; int min_free_kbytes = 1024; From patchwork Tue May 28 12:44:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10964849 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 18DC7112C for ; Tue, 28 May 2019 12:44:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08885287C9 for ; Tue, 28 May 2019 12:44:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F091B287F5; Tue, 28 May 2019 12:44:49 +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 EA74D287C9 for ; Tue, 28 May 2019 12:44:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E7C46B026E; Tue, 28 May 2019 08:44:47 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 797876B0274; Tue, 28 May 2019 08:44:47 -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 688E26B0276; Tue, 28 May 2019 08:44:47 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 320A06B026E for ; Tue, 28 May 2019 08:44:47 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id s3so4133423pgv.12 for ; Tue, 28 May 2019 05:44:47 -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:in-reply-to:references; bh=EL3WaUojtEFSPLnxz76NTYB+H5mCq7+P+XAJiuAKjzY=; b=nux4LhS+c048DPp3BjIchGzuNK/66BnadcEXRW9MTeutmpRA79fmw5/4a0fac++XPR BwPcSV4bmiGu58pQ/iREbcGxNaSEKLgsJfknNTT6xXqdX/4frUkKbdfqEG2lW6H6AT3Y zij4owFn7YGi4tRo37oHn6f8MnXGe8Q1nVLxDY3T6O29ZBea26par5sOFNHyGAARbLTn Sdfn8ECL0TC/3Jc54A49ySOp+HdrwNKKwfF3N7L/csbPEluBgBjDI/7QKI5o4IDb1dhj BE5US6reMv/AabFVkYFK3ce/QCUPCtayjOHp7fTfRsxClxfnKkbRloHqZ4gyCSGJ8gyt dICQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.42 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: APjAAAX1u9uGcl1jPgwmcA+PrPj7/DE4mZMiSYVDJ2MLJF51O15RZnJw OfkrFmDFnsivN8fnyklApknGNf+c/hOyUd4k9qlzMqgCXxe9GTAbFUKfeS3G/8vt3T54syjTYql ZpLh3QbIrOiSpLLiSQACpu+ouo6y4/YwOKvot88exFv8seH5UeJh927RetII6mrtWcQ== X-Received: by 2002:a62:1cd5:: with SMTP id c204mr104882853pfc.205.1559047486823; Tue, 28 May 2019 05:44:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWEgLbFV0HCKZrS0m7/cq0EDWDkKtbpw4irjVTT9txs3jeOuStnZy0LUxL71lxEJ3TPSjz X-Received: by 2002:a62:1cd5:: with SMTP id c204mr104882691pfc.205.1559047485438; Tue, 28 May 2019 05:44:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559047485; cv=none; d=google.com; s=arc-20160816; b=IqlI/Iqfxciu8M8fcdnFb9K7SERG9T8GS1MB/9zF4HiQx2IjYEgVbnr2uWWFGs1cSs R430lrccm5Q8uZN6dInOqH+HUd0IN5U2tODQPF8QjF1pQKQz0+wqs7qoUqBdgjJEy0c8 ugFhYlm0E6/6j5Pt79esjgrnyPgFBPltNbGAhjZ79hjdbmEifgR6wd4Fcr7ByBNgUBYT JwKcUQqORWpp5FuLYpNQ0+hwfli5PWsDB9u4m9NgcSKNgirSCjrquPgnGUYfGYlcNEQD 529Kt98nRB49qqdCh4HowxPQSLVzntoqPDmt7Q764z21CCnx3dBQtopInNhlh9qs51QU 2Zjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=EL3WaUojtEFSPLnxz76NTYB+H5mCq7+P+XAJiuAKjzY=; b=WgbigMj5l5Fw3we9j2boah5Wd5ZXATseoTlBCaxKUqSDCfwyEjNiribDq4J4LvVAoo nxhzn5h6HtNQ8REfExrUT1m4ziWcHpVQ98fOkB04p/Hu+n+m3LBc7x5uVqwi/7GK+BEl Aw/e+9CEgCAjCGr41S4RP69Oi6zQS4QpTPuPEF6P3Ao206/yavt8lwroKass5kS+pDqO dsvRtU6ey27dWf7QiQmCt5p9a+p4bpUHNpNwQ6/HvfCq3k5BG45whryF4AyUgFrrgsIn A591AT6NTeSKyjw+ykSt3c5t+6OHUW4fAvB1b3aieY51w9a6siV4zQce0pNrYrJDhxhN bmGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.42 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com. [115.124.30.42]) by mx.google.com with ESMTPS id 19si21122550pga.249.2019.05.28.05.44.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 May 2019 05:44:45 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.42 as permitted sender) client-ip=115.124.30.42; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.42 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=01201311R141e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04446;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0TStMl0v_1559047475; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TStMl0v_1559047475) by smtp.aliyun-inc.com(127.0.0.1); Tue, 28 May 2019 20:44:42 +0800 From: Yang Shi To: ktkhai@virtuozzo.com, hannes@cmpxchg.org, mhocko@suse.com, kirill.shutemov@linux.intel.com, hughd@google.com, shakeelb@google.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] mm: shrinker: make shrinker not depend on memcg kmem Date: Tue, 28 May 2019 20:44:24 +0800 Message-Id: <1559047464-59838-4-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1559047464-59838-1-git-send-email-yang.shi@linux.alibaba.com> References: <1559047464-59838-1-git-send-email-yang.shi@linux.alibaba.com> 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 shrinker is just allocated and can work when memcg kmem is enabled. But, THP deferred split shrinker is not slab shrinker, it doesn't make too much sense to have such shrinker depend on memcg kmem. It should be able to reclaim THP even though memcg kmem is disabled. Introduce a new shrinker flag, SHRINKER_NONSLAB, for non-slab shrinker, i.e. THP deferred split shrinker. When memcg kmem is disabled, just such shrinkers can be called in shrinking memcg slab. Cc: Kirill Tkhai Cc: Johannes Weiner Cc: Michal Hocko Cc: "Kirill A . Shutemov" Cc: Hugh Dickins Cc: Shakeel Butt Signed-off-by: Yang Shi --- include/linux/shrinker.h | 3 +-- mm/huge_memory.c | 3 ++- mm/vmscan.c | 27 ++++++--------------------- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 9443caf..e18dc00 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -69,10 +69,8 @@ struct shrinker { /* These are for internal use */ struct list_head list; -#ifdef CONFIG_MEMCG_KMEM /* ID in shrinker_idr */ int id; -#endif /* objs pending delete, per node */ atomic_long_t *nr_deferred; }; @@ -81,6 +79,7 @@ struct shrinker { /* Flags */ #define SHRINKER_NUMA_AWARE (1 << 0) #define SHRINKER_MEMCG_AWARE (1 << 1) +#define SHRINKER_NONSLAB (1 << 3) extern int prealloc_shrinker(struct shrinker *shrinker); extern void register_shrinker_prepared(struct shrinker *shrinker); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 91a709e..b01fdc3 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2963,7 +2963,8 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, .count_objects = deferred_split_count, .scan_objects = deferred_split_scan, .seeks = DEFAULT_SEEKS, - .flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE, + .flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE | + SHRINKER_NONSLAB, }; #ifdef CONFIG_DEBUG_FS diff --git a/mm/vmscan.c b/mm/vmscan.c index 7acd0af..62000ae 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -174,8 +174,6 @@ struct scan_control { static LIST_HEAD(shrinker_list); static DECLARE_RWSEM(shrinker_rwsem); -#ifdef CONFIG_MEMCG_KMEM - /* * We allow subsystems to populate their shrinker-related * LRU lists before register_shrinker_prepared() is called @@ -227,16 +225,6 @@ static void unregister_memcg_shrinker(struct shrinker *shrinker) idr_remove(&shrinker_idr, id); up_write(&shrinker_rwsem); } -#else /* CONFIG_MEMCG_KMEM */ -static int prealloc_memcg_shrinker(struct shrinker *shrinker) -{ - return 0; -} - -static void unregister_memcg_shrinker(struct shrinker *shrinker) -{ -} -#endif /* CONFIG_MEMCG_KMEM */ #ifdef CONFIG_MEMCG static bool global_reclaim(struct scan_control *sc) @@ -579,7 +567,6 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, return freed; } -#ifdef CONFIG_MEMCG_KMEM static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, struct mem_cgroup *memcg, int priority) { @@ -587,7 +574,7 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, unsigned long ret, freed = 0; int i; - if (!memcg_kmem_enabled() || !mem_cgroup_online(memcg)) + if (!mem_cgroup_online(memcg)) return 0; if (!down_read_trylock(&shrinker_rwsem)) @@ -613,6 +600,11 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, continue; } + /* Call non-slab shrinkers even though kmem is disabled */ + if (!memcg_kmem_enabled() && + !(shrinker->flags & SHRINKER_NONSLAB)) + continue; + ret = do_shrink_slab(&sc, shrinker, priority); if (ret == SHRINK_EMPTY) { clear_bit(i, map->map); @@ -649,13 +641,6 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, up_read(&shrinker_rwsem); return freed; } -#else /* CONFIG_MEMCG_KMEM */ -static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, - struct mem_cgroup *memcg, int priority) -{ - return 0; -} -#endif /* CONFIG_MEMCG_KMEM */ /** * shrink_slab - shrink slab caches