From patchwork Wed Jun 12 21:56:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10990895 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 948651398 for ; Wed, 12 Jun 2019 21:57:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81A0628846 for ; Wed, 12 Jun 2019 21:57:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 757E928A6D; Wed, 12 Jun 2019 21:57: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 A2D2D28846 for ; Wed, 12 Jun 2019 21:57:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82A196B0010; Wed, 12 Jun 2019 17:57:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7B3CC6B0266; Wed, 12 Jun 2019 17:57:18 -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 5B6956B026A; Wed, 12 Jun 2019 17:57:18 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 0A7686B0010 for ; Wed, 12 Jun 2019 17:57:18 -0400 (EDT) Received: by mail-pf1-f197.google.com with SMTP id x18so12951922pfj.4 for ; Wed, 12 Jun 2019 14:57:18 -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=AaRyVqbeEmeUBcpH+irFZSuQpqpdQ0qZVD0YYYixAT3n9jhU5hO8bFshyNIGJMYgc2 1jx0RLF7G3b1A5BDXC0Z2UxoNFLd9t5AM/NdTLmo3UpTUiSlp4/5tEdP3xH6Hg1suoCU PEBMYFn01DcR3DQH7gL7aw4jZbH9PGRcezL1UFcchEJcSjOtm0IzImv7oEhl8erS7lVp 05UChgo0/Ws+fz20ueNkDlshRM9N6NzugAlor0qzNoD8r/LMsZBQZDpV0dgyRvkE7ui4 lA6LjGc8DmfjEsygNnOq96iw/hVEKVzWygM47H2TeNgZd5YYDTrkqmrGu/39pBHMcmyb UbPw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.56 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: APjAAAVVKX+FilXhmp0AEzgqdU+1AeaDA+XoU3vY101ggOxzqrxFwfxj 4gE2UrVO9RLjz9L4LGqC+zlkJysWwGHHyZDT/1pkpfuDB1rEkL0orT986G91QqqHZ1fLodImzFS cDY5SnjS4rBIHzGYWe2/VXtSgLk1hyxzT0bzIX2p8vNNpRdLyhiUwB5K/xZ8+3L08lw== X-Received: by 2002:aa7:8ac9:: with SMTP id b9mr78530703pfd.260.1560376637578; Wed, 12 Jun 2019 14:57:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxN7sqxDwYvIfmFNNTbGpE4Gq2zHXAzFnCI+dwrKWVhNdA3rU5I+WCyh2OXg2pm/z1e293v X-Received: by 2002:aa7:8ac9:: with SMTP id b9mr78530642pfd.260.1560376636097; Wed, 12 Jun 2019 14:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560376636; cv=none; d=google.com; s=arc-20160816; b=HlE/xr9Bkpy5f5Bia3yTt8OjjP/UyFX4aubFFUUhFq9S+6KHMUtfAe5Qe1h4j6DT3c 83H30s07dcwG9fnl8RxPzds8OcVpU6Gq0+GyggX/GE2Gh6yXsfiRdt7iZefWqBXxFKe3 Tjq9DiMTmGSC8eu66QvXmzPK9B/Iij99dkqQZ888if+YQlrYQ114jBY/0Oikzv0XklPl QJ02l7pyCQMf9G8slaJW3gzQ/f6qMBNs4bsjcjF/jBK5sxJLsqjaYGUz/Sv+3PdGuh/1 pa61MDje9gODHLIxPy0MlIUYZO5c8vqYL5OmFmoWYru7JOI6icPBh2Hw09xIHaczzgMZ kS/Q== 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=QNdX5vleGeOZcIodoVW2VJc4Q8d4XSPfl0+yLFrmpExiUIG/sr2aPj179FJsHqiGee 38autqigT43NC4ohXVl9Pumg0r8pR24k6wLx7H5wQhsvVzZVydCL2ApyY7VNyR0ml+D5 UK2snqMEflgLvgwgrsd7wllvv/20++y9Gw1FnIL0k3hW9xuDiauj3YdSG3JCzTH9q+v5 LcmnDHsRWDheEAl1y8ywzgJUVNsKb8gNVW68/hTagPSkdiz6mbQ1cbFfQzocwmR+DEPH Hc2ZXF/DySXzEMbXLgFNuKFsUYVIIRdGtro8XyGYia57RSv5/J2gbrJHRWDOYsuhAYj8 nkNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.56 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-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com. [115.124.30.56]) by mx.google.com with ESMTPS id i124si103259pfe.139.2019.06.12.14.57.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jun 2019 14:57:16 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.56 as permitted sender) client-ip=115.124.30.56; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.56 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=01201311R121e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0TU0Hbt._1560376624; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TU0Hbt._1560376624) by smtp.aliyun-inc.com(127.0.0.1); Thu, 13 Jun 2019 05:57:13 +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: [v3 PATCH 1/4] mm: thp: extract split_queue_* into a struct Date: Thu, 13 Jun 2019 05:56:46 +0800 Message-Id: <1560376609-113689-2-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1560376609-113689-1-git-send-email-yang.shi@linux.alibaba.com> References: <1560376609-113689-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 Wed Jun 12 21:56:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10990893 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 4100C14BB for ; Wed, 12 Jun 2019 21:57:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BBE328846 for ; Wed, 12 Jun 2019 21:57:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D77528A6D; Wed, 12 Jun 2019 21:57: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 280EF28846 for ; Wed, 12 Jun 2019 21:57:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E5E26B000D; Wed, 12 Jun 2019 17:57:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 31E826B0266; Wed, 12 Jun 2019 17:57:18 -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 197B76B0269; Wed, 12 Jun 2019 17:57:18 -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 CCF746B000D for ; Wed, 12 Jun 2019 17:57:17 -0400 (EDT) Received: by mail-pl1-f199.google.com with SMTP id b24so10578214plz.20 for ; Wed, 12 Jun 2019 14:57: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=4kJ5Q4DCdZWctI1HwEx678LwDtYH2kVuCUx2wAqJGFE=; b=L3CAou3SVWOXgXb0Sz9Sl9Y//bqaft3bSfQeFubcI5Lbx6Rx4h6jrGYAS/ArPQ1JNn I7JpNPqNIQyIJOyy1hpP7aBpxruprx7YxWUy4KyqeRIJe20jQVNIiKtK5lsFP7PtFAw2 YdVPlyMh45q0r1e+WCcYO0vZNHJcdMZJnUJ011hhqTJfgmxXQuBL6Ftizk62eykfmqOe 8Rtet7p9bSs3FL9Z6LP+INGsHAAfpnx8/tceD299Puw+s/Tn6cRYxmPcAeO22FbnMHRY VXN6YhKOakJ10Txul+DZexW9Fd50bUZh6IUZeoYAmOxnBvSQx8KqQJtNYB92zt9B0BY+ y5Zg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.57 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: APjAAAWV84FQC0SOX+cL8X5kArrtNJaQXFPW4DwNH0P6ER9mRJ+t7SGs Bs/SmT8eAPGeBrsp78QmSUIMyKL+tbIcMLwr1CMBJntv39M+RDdIVznOaREK3zYG188evfvi2ur cVin6bk8z1TPWFKmUEwv+wDv4pRLKC0o+vLxhUGL1liS0ukCW6Yq+WFjB0HUYwWyctA== X-Received: by 2002:a17:90a:5d15:: with SMTP id s21mr1290373pji.126.1560376637467; Wed, 12 Jun 2019 14:57:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVfRQxhJ7pSepqggSIW2uiOA1I3JE/aBEBOCdIakKFmal7aWT7YumS5TXPiHQzbcIQ8ds/ X-Received: by 2002:a17:90a:5d15:: with SMTP id s21mr1290321pji.126.1560376636386; Wed, 12 Jun 2019 14:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560376636; cv=none; d=google.com; s=arc-20160816; b=Y1towDrZB69ow/w+Ifg6YcMhhNFyI39RkJvVMURLU8nYQcFFdvc8cijR62Hh8rdqhG nBo1Rcf8H0f4TrkHeTWMlRKwHhDPx+c1S/pIdKQDaLFreVWiWk8Fws7zW4xbrvOuo1hn qO9E3VFdNmnZFLRiBbtmSyL1Z4Y8XYtLy5bbeBt+7YtDjquOVle5T2rcB/GQZ/hAZ4MM ZsGXSk0SZOoRVi8ycSIp9eAtCdUSw1MvYz5rv2jYpMWf65oR+ButSxaHXfwr5GwlFsh+ wXdFHY6py3SZLqbdhW2I7x2mHEqARUPcpjr1w9iN/cUlhM+ELAXHiRBSKiKRJjumvUiK DrYg== 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=4kJ5Q4DCdZWctI1HwEx678LwDtYH2kVuCUx2wAqJGFE=; b=YV2LOHQQ0RWURgI3czPSwL1iljsKq5QIfwqccY56/KzZGA6k+28Y/z6nfLcO23TFgi ZWdEwuObgSQE2b3i7FaBKllwnnfVMCLNslvbuaXn1JaFUTSbKPcSR5g8n13RCPGXh2o9 W5DDH0E0umx7Q5Mxg+tU600B0D66mynr5nG8s1AszNBRy+qaQermSRPdeaIiompDBSDe Fj1/KnRNJsFVlbSqY7L8gSzEBKl8C0xR9dUnautlCTSG9Jdvf/+okjyBugxCEWtPFNd3 rsJLC1Ede4NuKjXSa6XoeHUSu5zy5C4JinuK7jMs3RoM1xMxJy8Y0h6AYTJHdlUocOgM HVXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.57 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-57.freemail.mail.aliyun.com (out30-57.freemail.mail.aliyun.com. [115.124.30.57]) by mx.google.com with ESMTPS id c14si806317pjr.51.2019.06.12.14.57.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jun 2019 14:57:16 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.57 as permitted sender) client-ip=115.124.30.57; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.57 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=e01e07487;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0TU0Hbt._1560376624; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TU0Hbt._1560376624) by smtp.aliyun-inc.com(127.0.0.1); Thu, 13 Jun 2019 05:57:14 +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: [v3 PATCH 2/4] mm: move mem_cgroup_uncharge out of __page_cache_release() Date: Thu, 13 Jun 2019 05:56:47 +0800 Message-Id: <1560376609-113689-3-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1560376609-113689-1-git-send-email-yang.shi@linux.alibaba.com> References: <1560376609-113689-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 Signed-off-by: Yang Shi Acked-by: Kirill A. Shutemov --- mm/page_alloc.c | 1 + mm/swap.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a82104a..7f27f4e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -623,6 +623,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 3a75722..982bd79 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -70,12 +70,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); } From patchwork Wed Jun 12 21:56:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10990899 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 8E7151398 for ; Wed, 12 Jun 2019 21:58:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B0CB28846 for ; Wed, 12 Jun 2019 21:58:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F70B28A6D; Wed, 12 Jun 2019 21:58:13 +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 3F2A528846 for ; Wed, 12 Jun 2019 21:58:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5691A6B0269; Wed, 12 Jun 2019 17:58:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4F29C6B026A; Wed, 12 Jun 2019 17:58:11 -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 3945C6B026B; Wed, 12 Jun 2019 17:58:11 -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 012456B0269 for ; Wed, 12 Jun 2019 17:58:11 -0400 (EDT) Received: by mail-pg1-f199.google.com with SMTP id a21so12263166pgh.11 for ; Wed, 12 Jun 2019 14:58:10 -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=WYt88mczFbUWrzsWgFnx+WWVMyrL7TRO/qmUk0eA2zI=; b=WGbgDwrYMWEMzvoxfu1b4WPnD9JmOuAcLbAtHGlvukZVY92V5wgjjzQpUZb2QW6Le3 zerZ3UEJ/riMw16VNKulr8MfEeC0wHKETEoCVI8NQFl4WabP0Gg6kDEEWDve5zVG2mwk Eb7dxTaNIwlJT8f8sTChOhz+p8VKhE/hQZqE+c+nEgrfZZxxXToMYtWWzOa5w9UNzR5S 4hBSQZJO+AxmsQobpHpNFVjW5WhEwonVwlsk/o/t4y0liarP3bug/Xu94Dlwo2M7lfZ8 IG9/dn2OJAHuZaKsu+MMBZqMGDx+NEhlUYIL+gEOcSptjzpWe7S8fbQpKoogQf/TZM1h cruA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.37 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: APjAAAVlI+S4c+8y1RQLiBfAD2UfVs0nZ0gByM3b8HEjh5fwSb264wed gizgXBbMw0YkyUqknrzGokWKyuNeugx7cU7kBqaL2NH07hblrkPtpr+dIMvj+gDOuGSHCvjc4d3 IsX9dQ+BaAiJGPp7MzvDSK2K979PzhBYbLNrN7oJmdmXBdsEJHyUJLvekHy9uUQu3XA== X-Received: by 2002:a62:ac11:: with SMTP id v17mr26591936pfe.236.1560376690646; Wed, 12 Jun 2019 14:58:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyeFIpFKSDajOOk5TIMpfeNGQntn8T8l9mL5B1MoGvq2DGqJ4IuoE50Icxt7ANldPZW5Wgt X-Received: by 2002:a62:ac11:: with SMTP id v17mr26591877pfe.236.1560376689524; Wed, 12 Jun 2019 14:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560376689; cv=none; d=google.com; s=arc-20160816; b=bXDs2W/aTDEw2xEMnFiHGlcG5zSmO6pR+A5YotXe3FrmfzRKLnVo755HyAMSK+1khm aXA6PVsSoNtlicSoNJdM/eKWZ+azSqR3Talu+niHjaWBKGJl3iKKBKtKRDAT+OpHYmw4 OwXUziMXVQz3myuuIDEeMgYWTEWXormSk8NYUKPg0N7eTHbsccfOG69ZbjjTDjQiky9W J8sjs4gT1mNqQnYFiRwmsqJc8ywoMMZCBI/hlZnekCFp0jf0154cIeb1sQA2Sr2H4TOw 2Ym3kRp0xrkBt4ynyN8vVFzHYtLoJfwFa1+p8Qm09V0kPVZj4jJisyS8f4TcaP0Bx6Vc bVsw== 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=WYt88mczFbUWrzsWgFnx+WWVMyrL7TRO/qmUk0eA2zI=; b=oJ/zytpsST4UyzCCJ8nQm/KtnmDGTl+W7Bg/3NJA3Bj8iWUYW575EncsAP2Qoonseu b25pr00JngMQkJY606AjCw5W1tZ1PDxTLa7Y8oYthsskizJkOV+QCVbfMtFR4T343/o+ XhSqepgWwNexLrdtUQQ/G3ccySpcIBYlv3vsth+ZLa4vWohJi6ZOTbGnkBQN0FSqDGC6 hIxb5nb9VQbKVugJUmWJ0SQR7s8XwusEAeqSZGfbIp1Y3knuvXBlk8tCVb4DCMNwEEhl wyUlYrVBMGTy7mDL3NhRA6uWv7XEEb4tEyjka3WZAH0WLxlD/h/E3AdLydUdNws/upDQ NxUA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.37 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out4437.biz.mail.alibaba.com (out4437.biz.mail.alibaba.com. [47.88.44.37]) by mx.google.com with ESMTPS id n11si739700plp.361.2019.06.12.14.58.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jun 2019 14:58:09 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.37 as permitted sender) client-ip=47.88.44.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.37 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0TU0Hbt._1560376624; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TU0Hbt._1560376624) by smtp.aliyun-inc.com(127.0.0.1); Thu, 13 Jun 2019 05:57:14 +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: [v3 PATCH 3/4] mm: shrinker: make shrinker not depend on memcg kmem Date: Thu, 13 Jun 2019 05:56:48 +0800 Message-Id: <1560376609-113689-4-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1560376609-113689-1-git-send-email-yang.shi@linux.alibaba.com> References: <1560376609-113689-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 Signed-off-by: Yang Shi --- include/linux/shrinker.h | 3 +-- mm/vmscan.c | 27 ++++++--------------------- 2 files changed, 7 insertions(+), 23 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/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 From patchwork Wed Jun 12 21:56:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10990897 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 4603F14BB for ; Wed, 12 Jun 2019 21:58:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FA5428846 for ; Wed, 12 Jun 2019 21:58:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22A6228A6D; Wed, 12 Jun 2019 21:58:07 +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 4266C28846 for ; Wed, 12 Jun 2019 21:58:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51B4A6B0266; Wed, 12 Jun 2019 17:58:05 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4A3FE6B0269; Wed, 12 Jun 2019 17:58:05 -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 36D496B026A; Wed, 12 Jun 2019 17:58:05 -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 EB32C6B0266 for ; Wed, 12 Jun 2019 17:58:04 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id v62so12292472pgb.0 for ; Wed, 12 Jun 2019 14:58:04 -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=oyfSUr/qs4itN9a8Doaf0h56i341o2Ux5qwPG29PNOY=; b=lgKAxARRMQEbDDU0FDHsfUuKEMwTEO9VTc8PY4UqRQJTSdjmsT/8sl2M/CshN/AYP4 Ur9OVg2ClVP9efDwhBi4IquW9EzEfXa3mUmJyOQFFKAm7YPypkKOaLd9XUqbGD3M2ZLd 3urar8rxVldPoikcCbRsmtySI2y5Cg8s3Ha4tY5bNkJOWiZCopCxnRgaMnCiE+cOy/YT A73V2kA0kSTmAxX+gj2mos0BdA+7x+W3PEDSZWHmkeYrJRDOLDeYXYL8KJ7iLpfLwtST 9tE372ia3sUfB+LsiduQvDk/lWDDBzCiujlL8zXZCC0PxGmMojyfTKgBH0KIQGYpzeog sQvw== 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: APjAAAW36WWoQVFQyEtbPvDaD0eUK37tTgvUj4dilOg7RNic9PSYtWWd pX+YEQfnFgn4fiKfNFUE6wuvRta8h542KKQEjuQejkHTq2qOweulvWbZlOjpqKB7Tj9z9/RH/oB i6CvjSyrSEHy4+kGC9vSvwYKA7CaGQxUSBYHQm1n6hBYlfihSzUYQKL9nwI7cmR+C5g== X-Received: by 2002:a63:7709:: with SMTP id s9mr11246139pgc.347.1560376684456; Wed, 12 Jun 2019 14:58:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4rrSBHLAglBpjQXSgCSatE3f3uufrWpK4cMTjUMlSXqc/+BJFqiSe8HcPHrgJJqLd4ohR X-Received: by 2002:a63:7709:: with SMTP id s9mr11246077pgc.347.1560376682974; Wed, 12 Jun 2019 14:58:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560376682; cv=none; d=google.com; s=arc-20160816; b=hAumoFLL5F0w36Trd0hunI+cUsXicQdBS0HJwbT2qEay+8TmjYuMcCMNToPTqJBV4C SB8+BjUufuTYdtB5OS8uyDRfpog1/XFRulCKVxAtLb7IMzogpD1Ur0KiU9ED9xHGt6/p dBvVgYrSCwzpYsrmZuNrwQPWRP1rW0MSW0NgLEI+potI3yqHDGonNFk0nf+TV5fh7Aip lx2IJn/UT5VG6lNtohHb+h4Dfm96IUeLRLziph7K9GkfiqngiDtZNFHIhDs6ueI3ixuA 54mtLWUNqQ7M00zcb7Iid2WjezDxUgy+AtJD3upZmyBGn4Z+72WjsZ2Te7sYE2oZ1jqD wo6Q== 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=oyfSUr/qs4itN9a8Doaf0h56i341o2Ux5qwPG29PNOY=; b=cz76GkL6HueNAn+copMQPJTNc7MEjY2kY3JhtQJalPzAJNYqKlkhdXIB1EE8X0sIat XmZFPa/b35VpwDAKL9GyLHFOJfKtZjrMrzg2wREvbLfQ+Jo73TBzYNQe9clqLtxnR6W/ UOQampOSM0gKlYy0r4N2leU6K9HplNfAavTF69BFk1mGi9suVp6A4hAWGmqThAfCgle3 DRwGKaWouvAOAv/J1m5l6R8LHUHhGdql9xD/BbDggnJQwx6hvsbxvYEIsLH5u3jtGmlc a8YavENAATjvxgFH6/JmMiwfTME7shMwxzqe5wOcQ0e1k/aW0nmjegiNZehyj7OA9DG5 ozog== 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 k5si822657pfi.16.2019.06.12.14.58.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jun 2019 14:58:02 -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=01201311R151e4;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_---0TU0Hbt._1560376624; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TU0Hbt._1560376624) by smtp.aliyun-inc.com(127.0.0.1); Thu, 13 Jun 2019 05:57:14 +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: [v3 PATCH 4/4] mm: thp: make deferred split shrinker memcg aware Date: Thu, 13 Jun 2019 05:56:49 +0800 Message-Id: <1560376609-113689-5-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1560376609-113689-1-git-send-email-yang.shi@linux.alibaba.com> References: <1560376609-113689-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 Signed-off-by: Yang Shi --- include/linux/huge_mm.h | 9 +++++++++ include/linux/memcontrol.h | 4 ++++ include/linux/mm_types.h | 1 + mm/huge_memory.c | 45 +++++++++++++++++++++++++++++++++------------ mm/memcontrol.c | 24 ++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 12 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 7cd5c15..7738509 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -250,6 +250,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 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..4f20273 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; @@ -2794,8 +2799,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,8 +2813,8 @@ 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); + struct mem_cgroup *memcg = compound_head(page)->mem_cgroup; unsigned long flags; VM_BUG_ON_PAGE(!PageTransHuge(page), page); @@ -2820,6 +2824,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 +2834,16 @@ 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 +2851,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 +2908,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 e50a2db..16f9390 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,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(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 @@ -4957,6 +4970,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;