From patchwork Wed Aug 7 02:17:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11080915 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 711021709 for ; Wed, 7 Aug 2019 02:18:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FE432879E for ; Wed, 7 Aug 2019 02:18:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52CDE287BF; Wed, 7 Aug 2019 02:18:22 +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 5988328960 for ; Wed, 7 Aug 2019 02:18:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92D8C6B0282; Tue, 6 Aug 2019 22:18:17 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 881C26B0280; Tue, 6 Aug 2019 22:18:17 -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 54DC66B027E; Tue, 6 Aug 2019 22:18:17 -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 1A3686B0280 for ; Tue, 6 Aug 2019 22:18:17 -0400 (EDT) Received: by mail-pg1-f199.google.com with SMTP id t19so56084937pgh.6 for ; Tue, 06 Aug 2019 19:18:17 -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=wKDd6yINnW0YWActj13+KXIn9ppzHTAKH5mNS4QaN/8=; b=L5m1gGG97x5IxnfHCo6fHglwnV/1RjeC5otd4ENTzXfOHEA6i2spYwN+eStrZ4/a5q 9nne0DRSANyXdKl0meGiW8KSwKAMnpoAYt6ZSkZQt1HdHMzefkLjPOpBedfwD1UzXXMP JCWs1kvImA+vNe8AhyBGl0TQJE4Ot3vu8MvWwPGBmvY41JWKvwBuZWJY20Ar9HQ45IO4 IW7x6xmYAawAuplqdw+NUbvbgGeDBfgEAUwHs3ojGiBFdk1n8qiV2fE5aGpV0Sgnluxt gZWHgLihp5japPXbNfh5F36GM4QWhe83wbsjAhu0nt7mqOb+NRYSjw4xVnBeUjPRuI3R cjrQ== 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: APjAAAW5xhKSdI71+nlnv/JNXOX0602CXRMPQ0i8uoiV2wq9xATYC0u6 v5V2tOOrpV/IUoSh1UfGyhQaxiPju5UnXcKGUJBoJBLXr7gmi8y/r6FvYG1Asqyl2D9UrJ48B24 V8Xq+GTVQNclLNzCz2J2OuUpv+vvAEdIUcnSO4kYphB4q1KvJEyTZcmymQ6Fwgv4CTA== X-Received: by 2002:a17:902:324:: with SMTP id 33mr5795043pld.340.1565144296720; Tue, 06 Aug 2019 19:18:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqzRNw7aYsdg+He26eKQe8Ihz085ouc2/5pLxbIjJcw51H0ogu5xw2DVRSxYA7siEV5pFgOi X-Received: by 2002:a17:902:324:: with SMTP id 33mr5794980pld.340.1565144295321; Tue, 06 Aug 2019 19:18:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565144295; cv=none; d=google.com; s=arc-20160816; b=CPIy+kQ7HXBJxmJxhfgTkPNXtkgim/Q8b0YMOsHc8ZrMi8zJ/p3Z6JHerj5Anx4ztA gQeNo9ii4fJf2xLK8TcVNkyx+iTpoyeXiDHiag36NosZzHgxtYATtScl6NwF7b5DQGPw fhZogUoVuZbFMPu/iZ6FSgmivMkldiHRgHrwJ6dJ30vMraLy8QcbpXcsAtfGcBw6EqOZ nJPdP4WXL0zp2EVXY1m2SzUGVhPYkAsUAAwgdQBRRct4HgvtULHMAHqCLEvJkPhJsP2t oAzIu/ZLmZ7UlTwfn3rUwHbgAbZzwwPtiCo5pM+ZGrwbdDnx7tLaar+GOPoh6PUaUH1E j8Ug== 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=wKDd6yINnW0YWActj13+KXIn9ppzHTAKH5mNS4QaN/8=; b=EHvQMCE4YPHqkStAHmat6cguEGb3LW1I5egpLu+e/PNAd5js9c5Eta4ZDCe1HvpN9y 4qIf7cN5TCbi++hg5LoMt/1SApX3c+11e6ENhEmePCUoXeu4vjkS/vzxCvvvDoJlqVEJ m3/eqblT1FQhR29RbcKJGXZLwVZm+zM7oE6pb1fh5Jecrl8DDuSO4XXVmer3KOP88jrQ P6Ol8nScEO5fBvVerY7wVT/pkl+HZkYAo0G2Sr5p+oJa5t2KMZHLcsQY74VH0eDykFxm oLGM7sGe5+1N10vY1r+/M2QGA8QcRdCRntC6wtglUhvp+st0TgL9n5D4Rwn3L47h7Xna 4f7A== 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 a91si8519853pld.254.2019.08.06.19.18.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 19:18:15 -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=e01e01422;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0TYr3obk_1565144286; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TYr3obk_1565144286) by smtp.aliyun-inc.com(127.0.0.1); Wed, 07 Aug 2019 10:18:13 +0800 From: Yang Shi To: kirill.shutemov@linux.intel.com, ktkhai@virtuozzo.com, hannes@cmpxchg.org, mhocko@suse.com, hughd@google.com, shakeelb@google.com, rientjes@google.com, cai@lca.pw, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v5 PATCH 1/4] mm: thp: extract split_queue_* into a struct Date: Wed, 7 Aug 2019 10:17:54 +0800 Message-Id: <1565144277-36240-2-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1565144277-36240-1-git-send-email-yang.shi@linux.alibaba.com> References: <1565144277-36240-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 Cc: Qian Cai Acked-by: Kirill A. Shutemov Signed-off-by: Yang Shi Reviewed-by: Kirill Tkhai --- 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 d77d717..d8ec773 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 1334ede..e0d8e08 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 272c6de..df02a88 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6649,9 +6649,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 Wed Aug 7 02:17:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11080917 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 7646D14DB for ; Wed, 7 Aug 2019 02:18:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 612A22879E for ; Wed, 7 Aug 2019 02:18:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50D4B28960; Wed, 7 Aug 2019 02:18:24 +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 9ED022879E for ; Wed, 7 Aug 2019 02:18:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA4D36B027E; Tue, 6 Aug 2019 22:18:17 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 99AC06B0286; Tue, 6 Aug 2019 22:18:17 -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 817066B0284; Tue, 6 Aug 2019 22:18:17 -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 1AE0E6B0282 for ; Tue, 6 Aug 2019 22:18:17 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id 28so5587966pgm.12 for ; Tue, 06 Aug 2019 19:18:17 -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=RyYon3OQiUuSLM2zAcIH2GtXGSvPnDCExfLydBYxxQw=; b=lxsrbU5Yb0RtlUbluMK62pqah+np6R5VuYvE3G0xHJU1ldNZRTtbJf5WoWB2ciVIOg cy2e6LTfuGUm4JNjEysotqDF/kCU80slbnVWPTGNM4MfPCcQGxKDw9GLimDv9DwGlZQA LdwCLguIAR+CwI1M5ZUpAHUgpypWzZjQXkdueHjV1PG8hE6QJAfueK1i8YT4TbLzZT3H zL7uFdP+K1CwQGAD8kPkW32Tu7y+CfU7lmNAzJPKljkmq9ZikjD8hJavYXeuG7K4vfhD xerDCSJRs0N99GpoVDKy2ihZE5X0udmWBIyBUleudEXAaxB507WcgDvstc5uiUbf4CQc 9y8Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.54 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: APjAAAUBKIvk2GYwt4hMOtVvny+wmwYziTVf3HlMP9z6QcRlfA2s5VZE sZx4nCz8wTMGkhZCZafwezhB/l/3JTZ9tCjtM+xCNSLir657csYzHY8NY9kqzSICPn5tD/zVISG mo2UtAaJvFIjMHTetJUwyFb0OblNijf8XypqNmCU4FDIJbyGGaRzYoibFW8IqVmPAjA== X-Received: by 2002:a17:902:e306:: with SMTP id cg6mr5978224plb.263.1565144296738; Tue, 06 Aug 2019 19:18:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEXgZY4vxvimCuS1O6cS791DlsR0XF9aGYDULHHKLObSqvBwvoVNoUz18MV/eVIj/rHvTY X-Received: by 2002:a17:902:e306:: with SMTP id cg6mr5978169plb.263.1565144295480; Tue, 06 Aug 2019 19:18:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565144295; cv=none; d=google.com; s=arc-20160816; b=VlNG6YjY3yAdskia4wJxm7KYiPo0LGIP/ajsbcXEJwspYBzgF/KnrfMHnjvm8w5tId VV4E5EV9/4RcS0MVVaBBG6rIXz5dwFfEoJjMQXTE+0m47g5RB0mgb70Iuh7Kf/ibPxik gFv9V85FOrmi2ywrknoRn5nWsyqhhh5B7RtMXubGaqT0Ul+OfQUykvO7bkSzOtXKHVfG DrwBDnX4RNzhjRSIjniXI+MpfeqWQ9csJ4ePQ+rWahrzNu7+G6zKTB4aGEXQed1aTOPV OHlNf5S8UiXjNH6SwSZ8+T6o+svpiXoLD+aPaujj98Nhw+vUslSiCPxuLlJzKQe0E0DN PvZA== 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=RyYon3OQiUuSLM2zAcIH2GtXGSvPnDCExfLydBYxxQw=; b=OrM8ruj1Yup0UKl3SOiFRj2BSoJMucRjVuyetevAM/FB5aBQdhIGgXpYhHXUE0BNks WlvZpejlToDI4DA8sYy2bg8kl9sEaZKTGdngzbxH+cYZQ+LF4PMvw16NvNjTrszsLn1g gp3DVPZUmvp+VFkwGIJ33JReLkLA/haDO/cGZhctu7uhlYVBC6MjC1CxmKUoRLSTL0tQ If3Z2if8FZMD0js+NkVGftdq3YC9mwHcV0uRINmyFSiMT5m9UrHju6uKscdxi5OhT0+O x73g5HNpx03wVhm6oZ/EU/QVtR/YqQko2F0lacBL+J7T1KAXGXpWuD3PKpUAay9yUpH6 +qRQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.54 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-54.freemail.mail.aliyun.com (out30-54.freemail.mail.aliyun.com. [115.124.30.54]) by mx.google.com with ESMTPS id ck13si16381222pjb.47.2019.08.06.19.18.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 19:18:15 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.54 as permitted sender) client-ip=115.124.30.54; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.54 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=e01e04394;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0TYr3obk_1565144286; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TYr3obk_1565144286) by smtp.aliyun-inc.com(127.0.0.1); Wed, 07 Aug 2019 10:18:13 +0800 From: Yang Shi To: kirill.shutemov@linux.intel.com, ktkhai@virtuozzo.com, hannes@cmpxchg.org, mhocko@suse.com, hughd@google.com, shakeelb@google.com, rientjes@google.com, cai@lca.pw, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v5 PATCH 2/4] mm: move mem_cgroup_uncharge out of __page_cache_release() Date: Wed, 7 Aug 2019 10:17:55 +0800 Message-Id: <1565144277-36240-3-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1565144277-36240-1-git-send-email-yang.shi@linux.alibaba.com> References: <1565144277-36240-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 later patch would make THP deferred split shrinker memcg aware, but it needs page->mem_cgroup information in THP destructor, which is called after mem_cgroup_uncharge() now. So, move mem_cgroup_uncharge() from __page_cache_release() to compound page destructor, which is called by both THP and other compound pages except HugeTLB. And call it in __put_single_page() for single order page. Suggested-by: "Kirill A . Shutemov" Cc: Kirill Tkhai Cc: Johannes Weiner Cc: Michal Hocko Cc: Hugh Dickins Cc: Shakeel Butt Cc: David Rientjes Cc: Qian Cai Acked-by: Kirill A. Shutemov Signed-off-by: Yang Shi Reviewed-by: Kirill Tkhai --- mm/page_alloc.c | 1 + mm/swap.c | 2 +- mm/vmscan.c | 6 ++---- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index df02a88..1d1c5d3 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -670,6 +670,7 @@ static void bad_page(struct page *page, const char *reason, void free_compound_page(struct page *page) { + mem_cgroup_uncharge(page); __free_pages_ok(page, compound_order(page)); } diff --git a/mm/swap.c b/mm/swap.c index ae30039..d4242c8 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -71,12 +71,12 @@ static void __page_cache_release(struct page *page) spin_unlock_irqrestore(&pgdat->lru_lock, flags); } __ClearPageWaiters(page); - mem_cgroup_uncharge(page); } static void __put_single_page(struct page *page) { __page_cache_release(page); + mem_cgroup_uncharge(page); free_unref_page(page); } diff --git a/mm/vmscan.c b/mm/vmscan.c index dbdc46a..b1b5e5f 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1490,10 +1490,9 @@ static unsigned long shrink_page_list(struct list_head *page_list, * Is there need to periodically free_page_list? It would * appear not as the counts should be low */ - if (unlikely(PageTransHuge(page))) { - mem_cgroup_uncharge(page); + if (unlikely(PageTransHuge(page))) (*get_compound_page_dtor(page))(page); - } else + else list_add(&page->lru, &free_pages); continue; @@ -1914,7 +1913,6 @@ static unsigned noinline_for_stack move_pages_to_lru(struct lruvec *lruvec, if (unlikely(PageCompound(page))) { spin_unlock_irq(&pgdat->lru_lock); - mem_cgroup_uncharge(page); (*get_compound_page_dtor(page))(page); spin_lock_irq(&pgdat->lru_lock); } else From patchwork Wed Aug 7 02:17:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11080921 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 D20BF14DB for ; Wed, 7 Aug 2019 02:19:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFE5B2879E for ; Wed, 7 Aug 2019 02:19:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B33AE28960; Wed, 7 Aug 2019 02:19:27 +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 708562879E for ; Wed, 7 Aug 2019 02:19:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 74AAF6B027E; Tue, 6 Aug 2019 22:19:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6FB616B0282; Tue, 6 Aug 2019 22:19:25 -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 5EB406B0286; Tue, 6 Aug 2019 22:19:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 251906B0282 for ; Tue, 6 Aug 2019 22:19:25 -0400 (EDT) Received: by mail-pl1-f199.google.com with SMTP id y9so49484168plp.12 for ; Tue, 06 Aug 2019 19:19:25 -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=6dehf2KMRb7fhLYD72e0CQZ8EMzXR74e7VbIq3OK2SA=; b=jBdoYc+qgl081gpaQVEQWO7PftiL/EQ/l5VvI3QVIzJMHj2JdBTHm9sB8M2nA2rlF4 NFjY+/1evdc/9CJxXwjCtEEAi2jiBk02UwR00QmSXFnogEW+RkqcNVnZcxU03GDXY1UJ 8Rku4WPa1tl3xjEIYijYYrxyuOaka+aNggBrpELMRON5ILjuhr3fW8kPznPqKAF83F/6 FUXvyhXtOksrw34bV8WsRpOwbKF4Gk61ttHF6MpMaQiTSpq9BJhXyC3rs+PDVp1pMQfc 9WZVpAXbIe834BtThtpkwVBbEPVor2PwPF4wzvv4S9W0ycDu0D2xP6LWQZ/sKZhsCogJ 3msw== 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: APjAAAVaxtZmr+UXz/AE/jCyE42sKPSMxwUTsDiSRkvLuciitA0/gmdO DWq7YcBylCL1f/zYlxAqoqFXRF6FPLPqopLHReaZKrY63YKYzw/cOV1OgN/Bw7IHs1qt4d2aa3a nrVnedcMfGG9vlROWBgxeShvoJzKpNLU6iY75IPv8SL29fDWErhXqh/pXZ6aqkH6/gg== X-Received: by 2002:aa7:8218:: with SMTP id k24mr6618570pfi.221.1565144364792; Tue, 06 Aug 2019 19:19:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+b55mnve/6Xb5IxYFJaJa+4IaAjGlO4crIutgUBwFl3eBzICmlHLGqpn3bJvBTvZbSmis X-Received: by 2002:aa7:8218:: with SMTP id k24mr6618504pfi.221.1565144363480; Tue, 06 Aug 2019 19:19:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565144363; cv=none; d=google.com; s=arc-20160816; b=VGnMHVSVYFNEKC+4/NLApKERtMD9V/YQFkX9tG8sdJY1y1SUtENA4TsHFf7P2uG+g8 artW9qMtejtWt7LgIlrAtelZ4tzKRpRd9lr7Y00rQSJYfsRVIB6FnTQh/tzVsQTWCDpt 88zKz2cNIoIGpDfemcXhXZpPfFveNxXFC1THf7ANLTypsTw+Vu3/qj16mwYnDFL9RQEz 2OAvq88zBHmNHpVojVVQGNA/T64jVMphtmMuyjbcub3pBzVYXKur6Erm7fN+/jiTBveb /URr92bAlqxYYVXyjIIetyMAIzx5qTlz8g5v05fVrdyZtjQP/GScXQDx0orG7UOcqqLH gIfw== 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=6dehf2KMRb7fhLYD72e0CQZ8EMzXR74e7VbIq3OK2SA=; b=OlRN3m9Rn/Fs4NZYc/LbxzjE+Wwc9UF99rcDt/HMsO5fAdL8T4uGBh3NDvNA9X1Ni6 a1haoZZjyxwymGC9hsDHouTGgoW0FQbyEHbRT9KSGX8cy2gac4awvBmKtChixlRqZl6c 7ATWw7+TOjduKslpic+FgnWXl8w2o1k/TBZB/5TvIEk710zNfDdLJ8YYvjOY15whfSaL ePl6CLPM8d8d+bHof4zsi9O/UwlocRGtAI1suCJ1GXaqnQooJ+Q1uo+vk5o6MxZVyjEi qdGw85TtKCdmwVRKRiFk+LgB1ZG6NILDEca7xr7ZhUEzH5tgrZxulqCzC95+QW2ekSuU i62g== 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 x7si534312pfi.257.2019.08.06.19.19.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 19:19:23 -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=01201311R201e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04391;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0TYr3obk_1565144286; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TYr3obk_1565144286) by smtp.aliyun-inc.com(127.0.0.1); Wed, 07 Aug 2019 10:18:13 +0800 From: Yang Shi To: kirill.shutemov@linux.intel.com, ktkhai@virtuozzo.com, hannes@cmpxchg.org, mhocko@suse.com, hughd@google.com, shakeelb@google.com, rientjes@google.com, cai@lca.pw, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v5 PATCH 3/4] mm: shrinker: make shrinker not depend on memcg kmem Date: Wed, 7 Aug 2019 10:17:56 +0800 Message-Id: <1565144277-36240-4-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1565144277-36240-1-git-send-email-yang.shi@linux.alibaba.com> References: <1565144277-36240-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. 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 Cc: Qian Cai Acked-by: Kirill A. Shutemov Signed-off-by: Yang Shi Reviewed-by: Kirill Tkhai --- include/linux/memcontrol.h | 19 ++++++++------- include/linux/shrinker.h | 3 ++- mm/memcontrol.c | 9 +------ mm/vmscan.c | 60 ++++++++++++++++++++++++---------------------- 4 files changed, 45 insertions(+), 46 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 44c4146..5771816 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -128,9 +128,8 @@ struct mem_cgroup_per_node { struct mem_cgroup_reclaim_iter iter[DEF_PRIORITY + 1]; -#ifdef CONFIG_MEMCG_KMEM struct memcg_shrinker_map __rcu *shrinker_map; -#endif + struct rb_node tree_node; /* RB tree node */ unsigned long usage_in_excess;/* Set to the value by which */ /* the soft limit is exceeded*/ @@ -1253,6 +1252,11 @@ static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg) } while ((memcg = parent_mem_cgroup(memcg))); return false; } + +extern int memcg_expand_shrinker_maps(int new_id); + +extern void memcg_set_shrinker_bit(struct mem_cgroup *memcg, + int nid, int shrinker_id); #else #define mem_cgroup_sockets_enabled 0 static inline void mem_cgroup_sk_alloc(struct sock *sk) { }; @@ -1261,6 +1265,11 @@ static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg) { return false; } + +static inline void memcg_set_shrinker_bit(struct mem_cgroup *memcg, + int nid, int shrinker_id) +{ +} #endif struct kmem_cache *memcg_kmem_get_cache(struct kmem_cache *cachep); @@ -1332,10 +1341,6 @@ static inline int memcg_cache_id(struct mem_cgroup *memcg) return memcg ? memcg->kmemcg_id : -1; } -extern int memcg_expand_shrinker_maps(int new_id); - -extern void memcg_set_shrinker_bit(struct mem_cgroup *memcg, - int nid, int shrinker_id); #else static inline int memcg_kmem_charge(struct page *page, gfp_t gfp, int order) @@ -1377,8 +1382,6 @@ static inline void memcg_put_cache_ids(void) { } -static inline void memcg_set_shrinker_bit(struct mem_cgroup *memcg, - int nid, int shrinker_id) { } #endif /* CONFIG_MEMCG_KMEM */ #endif /* _LINUX_MEMCONTROL_H */ diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 9443caf..9e112d6 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -69,7 +69,7 @@ struct shrinker { /* These are for internal use */ struct list_head list; -#ifdef CONFIG_MEMCG_KMEM +#ifdef CONFIG_MEMCG /* ID in shrinker_idr */ int id; #endif @@ -81,6 +81,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/memcontrol.c b/mm/memcontrol.c index cdbb7a8..d90ded1 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -313,6 +313,7 @@ void memcg_put_cache_ids(void) EXPORT_SYMBOL(memcg_kmem_enabled_key); struct workqueue_struct *memcg_kmem_cache_wq; +#endif static int memcg_shrinker_map_size; static DEFINE_MUTEX(memcg_shrinker_map_mutex); @@ -436,14 +437,6 @@ void memcg_set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id) } } -#else /* CONFIG_MEMCG_KMEM */ -static int memcg_alloc_shrinker_maps(struct mem_cgroup *memcg) -{ - return 0; -} -static void memcg_free_shrinker_maps(struct mem_cgroup *memcg) { } -#endif /* CONFIG_MEMCG_KMEM */ - /** * mem_cgroup_css_from_page - css of the memcg associated with a page * @page: page of interest diff --git a/mm/vmscan.c b/mm/vmscan.c index b1b5e5f..093b76d 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -174,11 +174,22 @@ struct scan_control { */ unsigned long vm_total_pages; +static void set_task_reclaim_state(struct task_struct *task, + struct reclaim_state *rs) +{ + /* Check for an overwrite */ + WARN_ON_ONCE(rs && task->reclaim_state); + + /* Check for the nulling of an already-nulled member */ + WARN_ON_ONCE(!rs && !task->reclaim_state); + + task->reclaim_state = rs; +} + static LIST_HEAD(shrinker_list); static DECLARE_RWSEM(shrinker_rwsem); -#ifdef CONFIG_MEMCG_KMEM - +#ifdef CONFIG_MEMCG /* * We allow subsystems to populate their shrinker-related * LRU lists before register_shrinker_prepared() is called @@ -230,30 +241,7 @@ 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 */ - -static void set_task_reclaim_state(struct task_struct *task, - struct reclaim_state *rs) -{ - /* Check for an overwrite */ - WARN_ON_ONCE(rs && task->reclaim_state); - - /* Check for the nulling of an already-nulled member */ - WARN_ON_ONCE(!rs && !task->reclaim_state); - - task->reclaim_state = rs; -} - -#ifdef CONFIG_MEMCG static bool global_reclaim(struct scan_control *sc) { return !sc->target_mem_cgroup; @@ -308,6 +296,15 @@ static bool memcg_congested(pg_data_t *pgdat, } #else +static int prealloc_memcg_shrinker(struct shrinker *shrinker) +{ + return 0; +} + +static void unregister_memcg_shrinker(struct shrinker *shrinker) +{ +} + static bool global_reclaim(struct scan_control *sc) { return true; @@ -594,7 +591,7 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, return freed; } -#ifdef CONFIG_MEMCG_KMEM +#ifdef CONFIG_MEMCG static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, struct mem_cgroup *memcg, int priority) { @@ -602,7 +599,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)) @@ -628,6 +625,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); @@ -664,13 +666,13 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, up_read(&shrinker_rwsem); return freed; } -#else /* CONFIG_MEMCG_KMEM */ +#else /* CONFIG_MEMCG */ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, struct mem_cgroup *memcg, int priority) { return 0; } -#endif /* CONFIG_MEMCG_KMEM */ +#endif /* CONFIG_MEMCG */ /** * shrink_slab - shrink slab caches From patchwork Wed Aug 7 02:17:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11080919 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 141D81709 for ; Wed, 7 Aug 2019 02:18:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01C8D2879E for ; Wed, 7 Aug 2019 02:18:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9B1628960; Wed, 7 Aug 2019 02:18:26 +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 0E30C2879E for ; Wed, 7 Aug 2019 02:18:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D2EE6B0280; Tue, 6 Aug 2019 22:18:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 85BB06B0284; Tue, 6 Aug 2019 22:18:19 -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 6FE7A6B0286; Tue, 6 Aug 2019 22:18:19 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id 2D4EA6B0280 for ; Tue, 6 Aug 2019 22:18:19 -0400 (EDT) Received: by mail-pl1-f200.google.com with SMTP id o6so49468914plk.23 for ; Tue, 06 Aug 2019 19:18:19 -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=P03iVIniDRnjwYMFRK1v6l3BaM3RkiwpwESqD4F+Zp8=; b=lNrwyMVCfwfrPsSS4up6M9+lvrfbrjaeoDs7kM1WK8MDuLPrf9IblotwPvjN5GNOrq Fh0QM6TJShnHE47xV7MSQrN38UccmX97b4Ytxa3FpnXpD7r8Cl/JDarrZkGcVtdUiXr7 +DdSduz72LQVdC4MeGXcRNwufMZq4p26USWektxyj+C4wSWOd/2zCOqpR1rd7/UYP4gY 1n6PGIWa4Q8NShL7+FbU6x86Vm6req995i27hSLcEnTYtAVNUO89TY+ELpWX8jRO5KcA kchH500Z0ZZPcPAM4b254ZC3uVLmIiY/jfMqMKcapkcSIejKL52estlTl8LgE1gjju3Q lBtw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.133 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: APjAAAWKPtRo3eMRNkwKcEW3khhRr270Gfe90h8NcktoPwSo4qftuFqa OI8Rns/6j3rvgZMbNScs+HEHtaFgltzTuowpXyE/ljorslmKDQk90ZhdXE3caNfq8AFZkPTp32t BVBO628+6welL3buGcL76+HXGuGReuVcrww1WTmDCrJ0UGwLA2xPL32XdZ1+TIly3oA== X-Received: by 2002:a17:90a:ca0f:: with SMTP id x15mr5954464pjt.82.1565144298757; Tue, 06 Aug 2019 19:18:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZ0GiDs7XNtaL1eXqgfBhoIJ2Rhtbw6ICAw0c8FQ6RyrA/ziam0293gRV06vdKAzFnGUL/ X-Received: by 2002:a17:90a:ca0f:: with SMTP id x15mr5954342pjt.82.1565144296258; Tue, 06 Aug 2019 19:18:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565144296; cv=none; d=google.com; s=arc-20160816; b=xdQc4IggbE3tdkxy3zZvJ9SjJp/t+SE9ZpjtA4bnd+3KJ7N/Yn5omwlGBpO9sfrMLw k+TTDVkjci46bHfsxx9bxBI3yfWcj+rAO3E81ZbnQ0IPcmZxhLlkHV1QltBZ0TMVBUQ2 zwSVVToJc8YWX4jihXdgubZhnAD20bE6FLj7pm1XkQeErRs44FLfICPBYBIB6lzmNGIx qnnI+Z/uqbSbdVM9nmCeJ92AzfGkNwTtf8WAmvyhD1WkygjWrX+9mKkVfot5UtcdJwiv I2ij2YcQu76tQR0r6qiCJwwB3dlvyGyrTQctW5Z+Z+nfm45noLUnxrizJNenYmqwaU33 wevQ== 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=P03iVIniDRnjwYMFRK1v6l3BaM3RkiwpwESqD4F+Zp8=; b=sNif0GFIw1LsEbaZTt0h7dh/Uu/VGuVNr/Lh6s4Ft/UEu6bQAIwsAbgYVypGio8A5l ZClWvvYj85fiLBShpoPfnUJ+PEZCOrRZ0C4gWh5bE3aIMKUnIwc41xsvgxy5cAGgjDJw /gm/O+WCLLF92P6iS5DCyzmCNt4Qtj0u9JQHpPoWLKHjwxf5lSKE7KW/iasRRc1uk0Mi YhsjCo4zFVYVAc7jAiVIcP5wPD3/5c+RX1hcSPJv88U6A+nGZI+xF8LsAySbAgJ7FhfI 3GRh6XpleCfkl+2Hv7M9OOl9AsqfKmLq4bud7wNpzEWXopydXccn+eerjhbQdhUFLcnp /7tA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.133 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-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com. [115.124.30.133]) by mx.google.com with ESMTPS id o19si34289990pgv.497.2019.08.06.19.18.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 19:18:16 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.133 as permitted sender) client-ip=115.124.30.133; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.133 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=01201311R521e4;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=12;SR=0;TI=SMTPD_---0TYr3obk_1565144286; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TYr3obk_1565144286) by smtp.aliyun-inc.com(127.0.0.1); Wed, 07 Aug 2019 10:18:13 +0800 From: Yang Shi To: kirill.shutemov@linux.intel.com, ktkhai@virtuozzo.com, hannes@cmpxchg.org, mhocko@suse.com, hughd@google.com, shakeelb@google.com, rientjes@google.com, cai@lca.pw, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v5 PATCH 4/4] mm: thp: make deferred split shrinker memcg aware Date: Wed, 7 Aug 2019 10:17:57 +0800 Message-Id: <1565144277-36240-5-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1565144277-36240-1-git-send-email-yang.shi@linux.alibaba.com> References: <1565144277-36240-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. 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 Cc: Qian Cai Acked-by: Kirill A. Shutemov Signed-off-by: Yang Shi Reviewed-by: Kirill Tkhai --- include/linux/huge_mm.h | 9 ++++++ include/linux/memcontrol.h | 4 +++ include/linux/mm_types.h | 1 + mm/huge_memory.c | 76 +++++++++++++++++++++++++++++++++++++++------- mm/memcontrol.c | 24 +++++++++++++++ 5 files changed, 103 insertions(+), 11 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 45ede62..61c9ffd 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -267,6 +267,15 @@ 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; +} + #else /* CONFIG_TRANSPARENT_HUGEPAGE */ #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; }) #define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; }) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 5771816..cace365 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -312,6 +312,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 3a37a89..156640c 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 e0d8e08..c9a596e 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -495,11 +495,25 @@ 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) +#ifdef CONFIG_MEMCG +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; +} +#else +static inline struct deferred_split *get_deferred_split_queue(struct page *page) +{ + struct pglist_data *pgdat = NODE_DATA(page_to_nid(page)); + + return &pgdat->deferred_split_queue; } +#endif void prep_transhuge_page(struct page *page) { @@ -2658,7 +2672,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; @@ -2794,8 +2808,7 @@ 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; + struct deferred_split *ds_queue = get_deferred_split_queue(page); unsigned long flags; spin_lock_irqsave(&ds_queue->split_queue_lock, flags); @@ -2809,17 +2822,37 @@ void free_transhuge_page(struct 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); +#ifdef CONFIG_MEMCG + struct mem_cgroup *memcg = compound_head(page)->mem_cgroup; +#endif unsigned long flags; VM_BUG_ON_PAGE(!PageTransHuge(page), page); + /* + * The try_to_unmap() in page reclaim path might reach here too, + * this may cause a race condition to corrupt deferred split queue. + * And, if page reclaim is already handling the same page, it is + * unnecessary to handle it again in shrinker. + * + * Check PageSwapCache to determine if the page is being + * handled by page reclaim since THP swap would add the page into + * swap cache before calling try_to_unmap(). + */ + if (PageSwapCache(page)) + return; + 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), &ds_queue->split_queue); ds_queue->split_queue_len++; +#ifdef CONFIG_MEMCG + if (memcg) + memcg_set_shrinker_bit(memcg, page_to_nid(page), + deferred_split_shrinker.id); +#endif } spin_unlock_irqrestore(&ds_queue->split_queue_lock, flags); } @@ -2827,8 +2860,19 @@ void deferred_split_huge_page(struct page *page) static unsigned long deferred_split_count(struct shrinker *shrink, struct shrink_control *sc) { + struct deferred_split *ds_queue; struct pglist_data *pgdata = NODE_DATA(sc->nid); - struct deferred_split *ds_queue = &pgdata->deferred_split_queue; + +#ifdef CONFIG_MEMCG + if (!sc->memcg) { + ds_queue = &pgdata->deferred_split_queue; + return READ_ONCE(ds_queue->split_queue_len); + } + + ds_queue = &sc->memcg->deferred_split_queue; +#else + ds_queue = &pgdata->deferred_split_queue; +#endif return READ_ONCE(ds_queue->split_queue_len); } @@ -2836,12 +2880,21 @@ 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; +#ifdef CONFIG_MEMCG + if (sc->memcg) + ds_queue = &sc->memcg->deferred_split_queue; + else + ds_queue = &pgdata->deferred_split_queue; +#else + ds_queue = &pgdata->deferred_split_queue; +#endif + 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 +2941,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, + .flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE | + SHRINKER_NONSLAB, }; #ifdef CONFIG_DEBUG_FS diff --git a/mm/memcontrol.c b/mm/memcontrol.c index d90ded1..da4a411 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4698,6 +4698,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: @@ -5071,6 +5076,14 @@ 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_init(page_deferred_list(page)); + from->deferred_split_queue.split_queue_len--; + spin_unlock(&from->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 @@ -5079,6 +5092,17 @@ static int mem_cgroup_move_account(struct page *page, /* caller should have done css_get */ page->mem_cgroup = to; + +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + if (compound && list_empty(page_deferred_list(page))) { + 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 + spin_unlock_irqrestore(&from->move_lock, flags); ret = 0;