From patchwork Fri Jun 7 06:07:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10980803 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 062DB6C5 for ; Fri, 7 Jun 2019 06:08:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E933328B04 for ; Fri, 7 Jun 2019 06:08:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD0A928B0F; Fri, 7 Jun 2019 06:08:32 +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 1723028B04 for ; Fri, 7 Jun 2019 06:08:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A11B6B0271; Fri, 7 Jun 2019 02:08:27 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 703BD6B0272; Fri, 7 Jun 2019 02:08:27 -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 507E26B0273; Fri, 7 Jun 2019 02:08:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id 071256B0272 for ; Fri, 7 Jun 2019 02:08:27 -0400 (EDT) Received: by mail-pg1-f199.google.com with SMTP id g9so720552pgd.17 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:in-reply-to:references; bh=lrPPZ8NiUUMLO+yAkhLtS4Iy/Ao4Mc5vCsF4KS5LBdo=; b=GmsPyUZUmxtSSPpn07sjYxWCj0ysIiLqQ+nzeu7+t7hJ3dO0xQYNlm24Cih4p/E9EX WReSltq209K5WK8wJHv+y+mOvceInh4DVH28WqTC9WDEEAe+fx0mAishzS+/fRwZ3Bpv ANybiyfmBbPeUdLaj4edXwq47dmoICUEXaNOCQDZhXEnQnHCYbZiUg99s+yyTKE0MbM+ ud+JO4t8yt684HH4sxyIcweVdbvEhptJJhPrqtos7vZXc4fE+IXWHCzMB9L6kjM6tf8x 5lvSpxeaJim0aNzEFqwQ64UOV2WZTm0JJ7U5hLOM6Ugyv52n+obT+Fu1ksle2OoiQXDY mn5A== 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: APjAAAWxtcqMNjPgoR9txIAO1zwF1W+7sWJ3pOqRluOIY7P4Yrzsbs7J lnPOeTK15CEL848D+KZUz+tmh0uzpi3iJGXjzbl7OsPl68brg8bgz1wkHNmSX1DBe62o5fgthu2 7uVIKFQG1ry0FSvt5q6kX0L5WxTxdOlTdvT3Ir5fWtWTWBmfLnKdzauZK7WTJeAjHrw== X-Received: by 2002:a17:90a:9503:: with SMTP id t3mr3687944pjo.47.1559887706476; Thu, 06 Jun 2019 23:08:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVOH5UALYMJZeL+FfL0bYWNAOPl09kno2cfi2gTjYjsIp3l49ulvYfDlGPG18339dRu8px X-Received: by 2002:a17:90a:9503:: with SMTP id t3mr3687876pjo.47.1559887705243; 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=OwPF5QIGAsGs6nyfn/WItj8vUOkrX/vLfTPaYmU7/yucsYzG8VaQjuk+YveRBqstme hCsJ3koxIDGhoMX/J2QIjbjPgqbPaETk/S4/dP0kGOybFSRLMC0x3+T7n6k93RuIYIpF jHeUaNxaGZxstgSR9riQ4tSsbpao3/espT6kp5rraXLjaVX7AWL+agIMoPBSEfWf2hrh bD6nGKInz7JIM8z+CvZsX3N2g3JobXOCzS8BZ678SpkJUWgRBF3o7nnw0WTrui25gUq4 0ASji/mtbwoEgQ2upU3RrIMMyE4yXd7wudCT85K3VPzvYiOJ/5o5as0HzW6j3z02h8L4 aRiA== 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=lrPPZ8NiUUMLO+yAkhLtS4Iy/Ao4Mc5vCsF4KS5LBdo=; b=G90nTwCAioNPGmFmmYcDogGwlTHpUf87PWKYaUKYmkZJfLL1MvG4T4HDCEbXehGB72 DsnSOPRY9BajWUPUtU4QwGOnRWEtQbS1u/0+iybkhMfylE2ZofXJf8huklKi3MGH/nRF a1Kvp+aUs6F6uvbtA/FsDfawJC/vOStOIpwDHK7q94qB9XpDvpoOOekVeZV/b2KFAzPK PcmapmEZmVkaOS2TiTRF8DAG81wmW/6o0f3l3CeV8ksbnc0SYg0ZwqahUiTMQogKRxcT JVmlrrfWsD9gbwltg68/EneF7HzCcyaHRnZHC53htkdPcq58U63fTJULIwWP7aN/AZF7 amGw== 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 q189si1013925pga.156.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.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=01201311R161e4;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=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:10 +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: [PATCH 1/4] mm: thp: extract split_queue_* into a struct Date: Fri, 7 Jun 2019 14:07:36 +0800 Message-Id: <1559887659-23121-2-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1559887659-23121-1-git-send-email-yang.shi@linux.alibaba.com> References: <1559887659-23121-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 Put split_queue, split_queue_lock and split_queue_len into a struct in order to reduce code duplication when we convert deferred_split to memcg aware in the later patches. Suggested-by: "Kirill A . Shutemov" Cc: Kirill Tkhai Cc: Johannes Weiner Cc: Michal Hocko Cc: Hugh Dickins Cc: Shakeel Butt Cc: David Rientjes Signed-off-by: Yang Shi --- include/linux/mmzone.h | 12 +++++++++--- mm/huge_memory.c | 45 +++++++++++++++++++++++++-------------------- mm/page_alloc.c | 8 +++++--- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 70394ca..7799166 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -676,6 +676,14 @@ struct zonelist { extern struct page *mem_map; #endif +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +struct deferred_split { + spinlock_t split_queue_lock; + struct list_head split_queue; + unsigned long split_queue_len; +}; +#endif + /* * On NUMA machines, each NUMA node would have a pg_data_t to describe * it's memory layout. On UMA machines there is a single pglist_data which @@ -755,9 +763,7 @@ struct zonelist { #endif /* CONFIG_DEFERRED_STRUCT_PAGE_INIT */ #ifdef CONFIG_TRANSPARENT_HUGEPAGE - spinlock_t split_queue_lock; - struct list_head split_queue; - unsigned long split_queue_len; + struct deferred_split deferred_split_queue; #endif /* Fields commonly accessed by the page reclaim scanner */ diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 9f8bce9..81cf759 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2658,6 +2658,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) { struct page *head = compound_head(page); struct pglist_data *pgdata = NODE_DATA(page_to_nid(head)); + struct deferred_split *ds_queue = &pgdata->deferred_split_queue; struct anon_vma *anon_vma = NULL; struct address_space *mapping = NULL; int count, mapcount, extra_pins, ret; @@ -2744,17 +2745,17 @@ 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); + spin_lock(&ds_queue->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--; + ds_queue->split_queue_len--; list_del(page_deferred_list(head)); } if (mapping) __dec_node_page_state(page, NR_SHMEM_THPS); - spin_unlock(&pgdata->split_queue_lock); + spin_unlock(&ds_queue->split_queue_lock); __split_huge_page(page, list, end, flags); if (PageSwapCache(head)) { swp_entry_t entry = { .val = page_private(head) }; @@ -2771,7 +2772,7 @@ 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); + spin_unlock(&ds_queue->split_queue_lock); fail: if (mapping) xa_unlock(&mapping->i_pages); spin_unlock_irqrestore(&pgdata->lru_lock, flags); @@ -2794,52 +2795,56 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) void free_transhuge_page(struct page *page) { struct pglist_data *pgdata = NODE_DATA(page_to_nid(page)); + struct deferred_split *ds_queue = &pgdata->deferred_split_queue; unsigned long flags; - spin_lock_irqsave(&pgdata->split_queue_lock, flags); + spin_lock_irqsave(&ds_queue->split_queue_lock, flags); if (!list_empty(page_deferred_list(page))) { - pgdata->split_queue_len--; + ds_queue->split_queue_len--; list_del(page_deferred_list(page)); } - spin_unlock_irqrestore(&pgdata->split_queue_lock, flags); + spin_unlock_irqrestore(&ds_queue->split_queue_lock, flags); free_compound_page(page); } void deferred_split_huge_page(struct page *page) { struct pglist_data *pgdata = NODE_DATA(page_to_nid(page)); + struct deferred_split *ds_queue = &pgdata->deferred_split_queue; unsigned long flags; VM_BUG_ON_PAGE(!PageTransHuge(page), page); - spin_lock_irqsave(&pgdata->split_queue_lock, flags); + spin_lock_irqsave(&ds_queue->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++; + list_add_tail(page_deferred_list(page), &ds_queue->split_queue); + ds_queue->split_queue_len++; } - spin_unlock_irqrestore(&pgdata->split_queue_lock, flags); + spin_unlock_irqrestore(&ds_queue->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); + struct deferred_split *ds_queue = &pgdata->deferred_split_queue; + return READ_ONCE(ds_queue->split_queue_len); } static unsigned long deferred_split_scan(struct shrinker *shrink, struct shrink_control *sc) { struct pglist_data *pgdata = NODE_DATA(sc->nid); + struct deferred_split *ds_queue = &pgdata->deferred_split_queue; unsigned long flags; LIST_HEAD(list), *pos, *next; struct page *page; int split = 0; - spin_lock_irqsave(&pgdata->split_queue_lock, flags); + spin_lock_irqsave(&ds_queue->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) { + list_for_each_safe(pos, next, &ds_queue->split_queue) { page = list_entry((void *)pos, struct page, mapping); page = compound_head(page); if (get_page_unless_zero(page)) { @@ -2847,12 +2852,12 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, } else { /* We lost race with put_compound_page() */ list_del_init(page_deferred_list(page)); - pgdata->split_queue_len--; + ds_queue->split_queue_len--; } if (!--sc->nr_to_scan) break; } - spin_unlock_irqrestore(&pgdata->split_queue_lock, flags); + spin_unlock_irqrestore(&ds_queue->split_queue_lock, flags); list_for_each_safe(pos, next, &list) { page = list_entry((void *)pos, struct page, mapping); @@ -2866,15 +2871,15 @@ 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); + spin_lock_irqsave(&ds_queue->split_queue_lock, flags); + list_splice_tail(&list, &ds_queue->split_queue); + spin_unlock_irqrestore(&ds_queue->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)) + if (!split && list_empty(&ds_queue->split_queue)) return SHRINK_STOP; return split; } diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 3b13d39..a82104a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6581,9 +6581,11 @@ static unsigned long __init calc_memmap_size(unsigned long spanned_pages, #ifdef CONFIG_TRANSPARENT_HUGEPAGE static void pgdat_init_split_queue(struct pglist_data *pgdat) { - spin_lock_init(&pgdat->split_queue_lock); - INIT_LIST_HEAD(&pgdat->split_queue); - pgdat->split_queue_len = 0; + struct deferred_split *ds_queue = &pgdat->deferred_split_queue; + + spin_lock_init(&ds_queue->split_queue_lock); + INIT_LIST_HEAD(&ds_queue->split_queue); + ds_queue->split_queue_len = 0; } #else static void pgdat_init_split_queue(struct pglist_data *pgdat) {} From patchwork Fri Jun 7 06:07:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10980805 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 252B392A for ; Fri, 7 Jun 2019 06:09:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1341C28B04 for ; Fri, 7 Jun 2019 06:09:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0509828B0F; Fri, 7 Jun 2019 06:09:10 +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 2137E28B04 for ; Fri, 7 Jun 2019 06:09:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ECAA06B0266; Fri, 7 Jun 2019 02:09:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E7CE96B026E; Fri, 7 Jun 2019 02:09:07 -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 D6A7B6B026F; Fri, 7 Jun 2019 02:09:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id 998D46B0266 for ; Fri, 7 Jun 2019 02:09:07 -0400 (EDT) Received: by mail-pg1-f199.google.com with SMTP id w31so714889pgk.23 for ; Thu, 06 Jun 2019 23:09:07 -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=CvrhcwgLx+DQPTH553w/C/afgsBJvl+XQRhtjmQXj30=; b=UPsH4y+0UZ1AKYExmpzMNX8IUZ57OV4F87KVZDz+vBjlBwzCFhbh4cyKeNt4E0sZaP APA5n135RdMTJaLomslQIw0rJSXjgzoZrtzVOUTChsPCsqMXsfG0Oy7KVGu+4d4t/ED0 ACy0PNChQTZkfxFolTyGEaPgU4KvhldSGF/mYWLyooy6tEbOERfSuC8fX/C9apyVvw/v xCNi6ZDWqwc5FrA8z9yBYReuLjxHX4CTYMSpvpCmWu1sZJ6cQBz/TL0I3hfC1x4AvyYi OYXZEEPeJh2ICgGNa5HAnJbZIHrXxUJ+sILbrNfsdPvCtJFgLbbybXDI/vhvgjmjvbZa ZzCg== 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: APjAAAXUzXnANkwzh7e/O3DgTbzN4lhIyO4xtEuhqeJ41cejb1FChmay N9BgwAFW0OGVepqpCOKSgpQTPMv0GxRHwyrcMxzaJgx+uXQmDpxh6JQGj4RU7YGn+e/yqUrcLUw pwV5It6/WGo1YgxT6xUxEu7VNGehcCUKLqpc7dwJ5VeFQZx/RbBnW6ze6OLzvunXwxQ== X-Received: by 2002:a17:90a:9289:: with SMTP id n9mr3744546pjo.35.1559887747076; Thu, 06 Jun 2019 23:09:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqz8oL8uPfLB7HdC0kP6mMPGrs9RGImOGAQGpeS7j/IFfugV7s9Qpec2sGkv5tyxyahiTQvi X-Received: by 2002:a17:90a:9289:: with SMTP id n9mr3744459pjo.35.1559887745567; Thu, 06 Jun 2019 23:09:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559887745; cv=none; d=google.com; s=arc-20160816; b=DEpvD8tw9ApAg8Qk1VAM90IrKbJPiB1ohjfWR7zzlouN+EMrdpLXfhTwmps8qk4NuY 3ugcLOEUCTEbgh45y4XiTpLGABPsRCw4lEkSXmZf7GNIiNaFwzMgoBT2YLTYFW2YJRLi bDm2kNyMjVqF4c69ghJsK6EkirflykjMHUbt6Qi9yZM9d49co8rSPp8z0zUIBRYz7N1d Hq57lk5EyR04ESx9cBj3Pe0FRc+pUPFTkWy6QWhnrYoIf1mk9Z9VYrAzMQHOZ4/WJPfv E5NIXwmx6cMs72JY8sZseri4wr8r2JjXM6p7JzUq+s+R6ncrt8lLIRGejkaRHSvkhQzC UnPw== 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=CvrhcwgLx+DQPTH553w/C/afgsBJvl+XQRhtjmQXj30=; b=G1o7amFHHCwjmu69Y217iO/EsptuzjRNKaf874w8hjL5+I9Fw/U7JPtxrek2nd84Lr gelseklJyaafPM+r2Gu1QtTmRFJD2LuhtUYWvzir1GTZ4/LlbzG/5dIZJUxz37rfK5i/ KuClHxR5WCthjWWP8va/Ja/FogWydM6YXbIfFLWtoOLwZ8xxUfMVlNHD0cxs67cqxu9s Gd29rBWlBb/6fVK88Bs3jKwF3cR7pB8UXz0XR0Wa6hzGbj3/Q+CJgRQJXN2FYD9zPkwD nGZ19Z/7026eOh6b2OXIs6DrPE2MAmB58K04JOVRfXERv/BnAyjwz53NdEjjo7CNG5Hb 4/aA== 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 j23si930246pfh.215.2019.06.06.23.09.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Jun 2019 23:09:05 -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=01201311R631e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07486;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:10 +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: [PATCH 2/4] mm: thp: make deferred split shrinker memcg aware Date: Fri, 7 Jun 2019 14:07:37 +0800 Message-Id: <1559887659-23121-3-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1559887659-23121-1-git-send-email-yang.shi@linux.alibaba.com> References: <1559887659-23121-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 Cc: David Rientjes Signed-off-by: Yang Shi --- include/linux/huge_mm.h | 15 ++++++++++ include/linux/memcontrol.h | 4 +++ include/linux/mm_types.h | 1 + mm/huge_memory.c | 71 +++++++++++++++++++++++++++++++++------------- mm/memcontrol.c | 19 +++++++++++++ mm/swap.c | 4 +++ 6 files changed, 94 insertions(+), 20 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 7cd5c15..8137c3a 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -250,6 +250,17 @@ 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 or memcg deferred list in the second tail pages is + * occupied by compound_head. + */ + return &page[2].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 +379,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..5d3c10c 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -316,6 +316,10 @@ struct mem_cgroup { struct list_head event_list; spinlock_t event_list_lock; +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + struct deferred_split deferred_split_queue; +#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..4eabf80 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -139,6 +139,7 @@ struct page { struct { /* Second tail page of compound page */ unsigned long _compound_pad_1; /* compound_head */ unsigned long _compound_pad_2; + /* For both global and memcg */ struct list_head deferred_list; }; struct { /* Page table pages */ diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 81cf759..3307697 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -492,10 +492,15 @@ 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) +static inline struct deferred_split *get_deferred_split_queue(struct page *page) { - /* ->lru in the tail pages is occupied by compound_head. */ - return &page[2].deferred_list; + struct mem_cgroup *memcg = compound_head(page)->mem_cgroup; + struct pglist_data *pgdat = NODE_DATA(page_to_nid(page)); + + if (memcg) + return &memcg->deferred_split_queue; + else + return &pgdat->deferred_split_queue; } void prep_transhuge_page(struct page *page) @@ -2658,7 +2663,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) { struct page *head = compound_head(page); struct pglist_data *pgdata = NODE_DATA(page_to_nid(head)); - struct deferred_split *ds_queue = &pgdata->deferred_split_queue; + struct deferred_split *ds_queue = get_deferred_split_queue(page); struct anon_vma *anon_vma = NULL; struct address_space *mapping = NULL; int count, mapcount, extra_pins, ret; @@ -2792,25 +2797,36 @@ 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)); - struct deferred_split *ds_queue = &pgdata->deferred_split_queue; - unsigned long flags; - - spin_lock_irqsave(&ds_queue->split_queue_lock, flags); - if (!list_empty(page_deferred_list(page))) { - ds_queue->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) { + struct deferred_split *ds_queue = get_deferred_split_queue(page); + unsigned long flags; + spin_lock_irqsave(&ds_queue->split_queue_lock, flags); + if (!list_empty(page_deferred_list(page))) { + ds_queue->split_queue_len--; + list_del(page_deferred_list(page)); + } + spin_unlock_irqrestore(&ds_queue->split_queue_lock, flags); } - spin_unlock_irqrestore(&ds_queue->split_queue_lock, flags); +} + +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)); - struct deferred_split *ds_queue = &pgdata->deferred_split_queue; + struct deferred_split *ds_queue = get_deferred_split_queue(page); + struct mem_cgroup *memcg = compound_head(page)->mem_cgroup; unsigned long flags; VM_BUG_ON_PAGE(!PageTransHuge(page), page); @@ -2820,6 +2836,9 @@ void deferred_split_huge_page(struct page *page) count_vm_event(THP_DEFERRED_SPLIT_PAGE); list_add_tail(page_deferred_list(page), &ds_queue->split_queue); ds_queue->split_queue_len++; + if (memcg) + memcg_set_shrinker_bit(memcg, page_to_nid(page), + deferred_split_shrinker.id); } spin_unlock_irqrestore(&ds_queue->split_queue_lock, flags); } @@ -2827,8 +2846,15 @@ void deferred_split_huge_page(struct page *page) static unsigned long deferred_split_count(struct shrinker *shrink, struct shrink_control *sc) { - struct pglist_data *pgdata = NODE_DATA(sc->nid); - struct deferred_split *ds_queue = &pgdata->deferred_split_queue; + struct deferred_split *ds_queue; + + if (!sc->memcg) { + struct pglist_data *pgdata = NODE_DATA(sc->nid); + ds_queue = &pgdata->deferred_split_queue; + return READ_ONCE(ds_queue->split_queue_len); + } + + ds_queue = &sc->memcg->deferred_split_queue; return READ_ONCE(ds_queue->split_queue_len); } @@ -2836,12 +2862,17 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, struct shrink_control *sc) { struct pglist_data *pgdata = NODE_DATA(sc->nid); - struct deferred_split *ds_queue = &pgdata->deferred_split_queue; + struct deferred_split *ds_queue; unsigned long flags; LIST_HEAD(list), *pos, *next; struct page *page; int split = 0; + if (sc->memcg) + ds_queue = &sc->memcg->deferred_split_queue; + else + ds_queue = &pgdata->deferred_split_queue; + spin_lock_irqsave(&ds_queue->split_queue_lock, flags); /* Take pin on all head pages to avoid freeing them under us */ list_for_each_safe(pos, next, &ds_queue->split_queue) { @@ -2888,7 +2919,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..fe7e544 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->deferred_split_queue.split_queue_lock); + INIT_LIST_HEAD(&memcg->deferred_split_queue.split_queue); + memcg->deferred_split_queue.split_queue_len = 0; +#endif idr_replace(&mem_cgroup_idr, memcg, memcg->id.id); return memcg; fail: @@ -4949,6 +4954,20 @@ 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_deferred_list(page))) { + spin_lock(&from->deferred_split_queue.split_queue_lock); + list_del(page_deferred_list(page)); + from->deferred_split_queue.split_queue_len--; + spin_unlock(&from->deferred_split_queue.split_queue_lock); + + spin_lock(&to->deferred_split_queue.split_queue_lock); + list_add_tail(page_deferred_list(page), + &to->deferred_split_queue.split_queue); + to->deferred_split_queue.split_queue_len++; + spin_unlock(&to->deferred_split_queue.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 Fri Jun 7 06:07:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10980807 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 C7DCB6C5 for ; Fri, 7 Jun 2019 06:09:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B56B928B04 for ; Fri, 7 Jun 2019 06:09:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A828C28B0F; Fri, 7 Jun 2019 06:09:16 +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 B7E4428B04 for ; Fri, 7 Jun 2019 06:09:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFA256B026E; Fri, 7 Jun 2019 02:09:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AD32A6B026F; Fri, 7 Jun 2019 02:09:13 -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 972626B0274; Fri, 7 Jun 2019 02:09:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by kanga.kvack.org (Postfix) with ESMTP id 69ED96B026E for ; Fri, 7 Jun 2019 02:09:13 -0400 (EDT) Received: by mail-ot1-f70.google.com with SMTP id v1so472853otj.23 for ; Thu, 06 Jun 2019 23:09:13 -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=YO/B0XIPUrcta3UGb7HueTim6Go09O/U69ZQrtX4kec=; b=WrPANRxFDogr13mRFEb79X6e2A5SSqCaUwooQhsWdpg0bIUu7x6/y71Tt2KDpZOLGK 13OXPveX+dync2aG6q9LRH4KBZfeifaK6W8M5hU0Lvt4QW0ENWjbHnYIVKFKSYZ3mKZO Io7iyQPRTc31rcxsHSLEr5mgjsJMFR2lbUhGbCiQzNpPDkBndRgPeVfHbAwFpqyOxSjv EQMX9Vpo2SUjYqmcbvdEVqwilUHw4aTLT0Ef5qskmKPlbHGCncxVCgpiYGzfgJuWCTPg 1JJ9irTTx/dVMkoJbVbNm+d2iguhGs/L/BvRNnM/6utOkFDejpp4C1EbWM1hghp5vits RLVg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.132 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: APjAAAXuQwM/1NFq79ABiLnNU7a4ihGWprRr5N3xLgPmjyEHinuo7mgr IKxiEX0KZyEtb88LIYurw8aLhevcOqkl2qO7t9DC+6INHnEi5mAhjaj9qk+AAAHjhdBPU8QudEi vZWgT6g3JN+KsNT4N0lOcgieCYYyjG2zzFD/LJ3jYef3BMKRrjr9mrWOxX6xji6xpgA== X-Received: by 2002:aca:c48b:: with SMTP id u133mr2600032oif.95.1559887752990; Thu, 06 Jun 2019 23:09:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqy0LC4sQmfMlEk/PAS1epwbCEbLZ6iHbobfKY9lsWFmV4OScQMFtiLr2ag+2zD5nnrwAS5e X-Received: by 2002:aca:c48b:: with SMTP id u133mr2599989oif.95.1559887751859; Thu, 06 Jun 2019 23:09:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559887751; cv=none; d=google.com; s=arc-20160816; b=IgGPRGNFdj6A1JCDmQopzntqCZ/WRvQ214MGDIATc04Vr66YQpfQAjhtasik7THqoj huUuZ08mwy8QzGUGcN6R3qRj1ubFygKIC0zQY+5klmcM14lhNBgbwEJkVeYJp+tDU/EO MfSk211xf77Dt/tquO3fUJDlvWOZXf1octKMl0Ym1dSI+Gjxx5CNUgPcCaylk0A/GL/s 8UkCqJ7dYom6LlRNs3ACKh74ChSTrIlsyLWdi9qdbehN5r5ruOGQLor7SGo0Uz4lgvj+ LRCQc8W8whCg6Q7kyn9kZC6CbfvnfAIlFQPTPTI1Lz/AX+OGIIrM+MCicCUfiw/+mwai j1dg== 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=YO/B0XIPUrcta3UGb7HueTim6Go09O/U69ZQrtX4kec=; b=NhBQ+pDAGu6Sz5XnF4HqtsY/3ISeHjX2HPcwxkVhkW+0nO+UtK6Jl7dsYv+wS3+V6a +yYbPwk2NzuPFmY0sJPSFcupG3kvjqCwM/OjwPapiGKxHQ3Pr2smHSSdYd5ImBf7afob 5MOLYnRZZJLtKCqAmVAI84hyBskqcaoneBXvupUSlQxpnbuwBXaYqvfDU1a9UcEXev7N 4DieISZne0UhXhZKe66mmbFQH/iv6Ep5v5L7aRfRjUAnTDWfuCWMCuaG7nn83qmJwjX2 r9npItCqEIBwWHlgLCR5D5M8XDEE/SbvcZnDQ3xqn7J9CrbHA67qvYF8pgPJQ2HFCmpb jphg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.132 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-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com. [115.124.30.132]) by mx.google.com with ESMTPS id e132si800033oia.44.2019.06.06.23.09.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Jun 2019 23:09:11 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.132 as permitted sender) client-ip=115.124.30.132; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.132 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=01201311R181e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07487;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:10 +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: [PATCH 3/4] mm: thp: remove THP destructor Date: Fri, 7 Jun 2019 14:07:38 +0800 Message-Id: <1559887659-23121-4-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1559887659-23121-1-git-send-email-yang.shi@linux.alibaba.com> References: <1559887659-23121-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 Cc: David Rientjes 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 3307697..50f4720 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -511,7 +511,6 @@ void prep_transhuge_page(struct page *page) */ INIT_LIST_HEAD(page_deferred_list(page)); - set_compound_page_dtor(page, TRANSHUGE_PAGE_DTOR); } static unsigned long __thp_get_unmapped_area(struct file *filp, unsigned long len, @@ -2818,11 +2817,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 deferred_split *ds_queue = get_deferred_split_queue(page); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a82104a..6009214 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 Fri Jun 7 06:07:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10980799 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 B670792A for ; Fri, 7 Jun 2019 06:08:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A295128B04 for ; Fri, 7 Jun 2019 06:08:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 961DC28B0F; Fri, 7 Jun 2019 06:08:28 +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 812AD28B04 for ; Fri, 7 Jun 2019 06:08:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6672C6B0269; 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 5F0F36B026B; 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 492056B0271; 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-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by kanga.kvack.org (Postfix) with ESMTP id 1EBD66B0269 for ; Fri, 7 Jun 2019 02:08:26 -0400 (EDT) Received: by mail-ot1-f72.google.com with SMTP id n19so481557ota.14 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:in-reply-to:references; bh=OSZbGRf8RBV4JTgqy0gdidlw7WRQWqllwVVjoDAu5fQ=; b=e22Kr1VijA+ybxC9uTwzVv5yUzby/7QvjrmLf3d6IvmTih/WnelxxiJFMSQTZR18JZ +a0Ya3txUcBvVTbt2R17sONeqxEwHCtiT3geMIrx2+vUqJBcGdtV+HjZOAsPja0M4FnW Gg4686BbmcCG+WBs38Byl9oYopfT6NL/t1jtOtrqG3FBGnwxCIVij2zbHdZKMRi+UHag RZB/ET7R8qy1GXqpc/OjvkcIjKsyUWUUL1t9BFQIph8VJsVg5fjMkY9HViJPzPNOls44 +Nmva9cY6RAAqVH2EcKNdW3q43TtNW4z6RxkR36beWWlKEvo5uJhDGFl9IeCx/4+v7pI 2xyQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.44 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: APjAAAUnrBsK6frCt2mAZ6FiI8Q96yyu54X0EbLfhNcLGfHWKyMf5rDL PgId1eg/C5rt9p+jUET0f/CDTTrgPbgLYpyx8+uqaXtw2bfXgg2ZoN9gdR/KnlNV460Vv8a6g1R 4hnoQZkZp9iHEmw5A4I/uFpGVijsKksGkd8sFJVxr1WbxEAgYvQVk/GRdbr9Rl5mzzw== X-Received: by 2002:a05:6830:1597:: with SMTP id i23mr12288499otr.281.1559887705689; Thu, 06 Jun 2019 23:08:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyN1DbOUSfBqBJH5333PHe2mxQIdDmdZsUTCI1QFb5FxJKmA1nIzYX7K3m9oVFryV1jR5WV X-Received: by 2002:a05:6830:1597:: with SMTP id i23mr12288442otr.281.1559887704411; Thu, 06 Jun 2019 23:08:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559887704; cv=none; d=google.com; s=arc-20160816; b=OOf05wQNh3iwMEsnjfRPjjAx9n9uj/w5pvGqEMzUqjzJkbA3poeN6juLI8v2o4JUjs JvxX0Z+dzMdyBRLtBb7h9j1WXJoi+S4FuR+pqviC7WX1zuDTYe13fI39gY/Q54p9M6rg 9sbpNCyXg+JUStzVaCrKEcQ+Iv7GRUDIDk6DfGDpAhD6fIT1/txrDi1qUOsrqc/AWwQ3 kknnZnn7mtrfHAoYTfM3th5zPp3vvOt9hJ8EkKqkbY1NzU7htL7A+FZCkQtWtbmmqKa+ z6f1Fa3WDdJQI7v/F7Vm1g30ISSnV+OxAnvQmie4i0IS7hW1HCfgTffCucNlLvEg1upe 4fsw== 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=OSZbGRf8RBV4JTgqy0gdidlw7WRQWqllwVVjoDAu5fQ=; b=Muhr6PeBq9MPj4+ZJW60c68/sf34EiXVvh/Z2mT0PIplQZuMtaDglj8pFZBat4aHLA +khoMYY6zHbkPybQH1b9ZayI2gPV8h8U1bkQ9NGG0p1XUceI/jQ96v8d/1NED0V4sMst F3rQktw/4UWQ5jhwfDiGloqBQzA0c1KoNP9zRSUIZjZIjUzgDHk8gmZH11MlAoKnJLVe FV+6n+xTG5uNj/Lou8wemafhVgY7qusT3Z1W7uez2zuYbQ5Ekmeisc6E8iVY6m7RBSmw 4y501/GhupsZERO2ks/4+NnWEP1LSXkATpYhP5fCiD3gcQ/fHrbs3ulTxPvLnqekTshm SHKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.44 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-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com. [115.124.30.44]) by mx.google.com with ESMTPS id k83si796892oia.270.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:24 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.44 as permitted sender) client-ip=115.124.30.44; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.44 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=01201311R751e4;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=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:11 +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: [PATCH 4/4] mm: shrinker: make shrinker not depend on memcg kmem Date: Fri, 7 Jun 2019 14:07:39 +0800 Message-Id: <1559887659-23121-5-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1559887659-23121-1-git-send-email-yang.shi@linux.alibaba.com> References: <1559887659-23121-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 Cc: David Rientjes 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..e14f68e 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 << 2) 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 50f4720..e77a9fc 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2913,7 +2913,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