From patchwork Mon Mar 23 05:52:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonsoo Kim X-Patchwork-Id: 11452385 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E4F9B92A for ; Mon, 23 Mar 2020 05:52:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A820120714 for ; Mon, 23 Mar 2020 05:52:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b0fCVVFF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A820120714 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B08C66B000D; Mon, 23 Mar 2020 01:52:51 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ADFB16B000E; Mon, 23 Mar 2020 01:52:51 -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 9D0558E0003; Mon, 23 Mar 2020 01:52:51 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0165.hostedemail.com [216.40.44.165]) by kanga.kvack.org (Postfix) with ESMTP id 860DD6B000D for ; Mon, 23 Mar 2020 01:52:51 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id BE2728248047 for ; Mon, 23 Mar 2020 05:52:51 +0000 (UTC) X-FDA: 76625558142.07.girls62_70420511dd803 X-Spam-Summary: 2,0,0,99a4d90700136eb9,d41d8cd98f00b204,js1304@gmail.com,,RULES_HIT:41:355:379:541:800:960:966:968:973:988:989:1260:1345:1359:1437:1535:1544:1711:1730:1747:1777:1792:2196:2199:2393:2553:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3868:3871:4119:4321:4385:4605:5007:6261:6653:7576:7903:8957:9413:9707:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:12986:13161:13229:14181:14394:14721:21080:21324:21444:21451:21627:21666:21740:21990:30003:30054:30090,0,RBL:209.85.215.193:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: girls62_70420511dd803 X-Filterd-Recvd-Size: 8051 Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Mon, 23 Mar 2020 05:52:51 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id x7so6647792pgh.5 for ; Sun, 22 Mar 2020 22:52:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PA58IeGELp7GsoJt+UjQP9iD9gs1mWgVhDSyVyxp9eY=; b=b0fCVVFFvGUde3UoRxe5Hn/eOXfRswcrwmv5eQI0g7DBF3RqDkmM8/wMGHKhToO4BO VALj/+Np3QDwTxyxi5hpGau0EIq2dKJvTg5SSuxYvrV45nT12HKGTRQIiw7LFWI99AoH xoMN6RwQp9a9aGchGQ7kJDqDk+rM9GGLCFIzphcojz/HmIN3h6LD27NMLSX5o2I4uKZL qQK+1qAiQiEeFY6i+1uuQLJ4eoWuQeBpZpHg6ovlWoBqIcP0G4EzUFHvjw9eRwclzN7w +NUEwSQFa48scVZ7ZQZiyjlg53+viYmtgG1bEFcU2FaGG90iVaB0XE+62qexHT03Inv1 GBtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PA58IeGELp7GsoJt+UjQP9iD9gs1mWgVhDSyVyxp9eY=; b=YbGEt6m6noxnlMPTKjL+zS70GW+t4Jk5qIaJXvKTfIARz0idF/aqVT4l/IAI4UT+jX cpSbxZcKOn+uN33K0cakPQD7bwJANPeDPqhByJuPPkKkOBjIUDvx8QLfy/2F1FOtwnhv fQtH/cEYTVkmHEFwJiE3pOIAHom4cy+y+I0VJc9qK+6Fyz3s7X1Cfj4dbZUkDWxZ3D2S 3HcgV/oiaWt7h0jXZRuMLZ4r1O73IXxHDukNfO/7x/My4zfLxHSIyd4e/OLBsWwkw0PZ e7KnTdzujJp2UIvTjbQSEYYndlD/rWMvDqRTDHJQ39CDFR90qyh7h7ge9qlwXwjnRsQM 0yvg== X-Gm-Message-State: ANhLgQ37QAZsi7Q8dKKsk/8yp+QUSuun6WB03Q3/qkgPbf+S3OPkTUXo if8TKObXYA9TwvF5omO0PjA3paT//DU= X-Google-Smtp-Source: ADFU+vuGliCxHPs66TbnySCtCClvxORBH+oMz63p8tvjnSznatR+XfNrRr0tDX/2ia3Rivrmbn7xOQ== X-Received: by 2002:a62:8247:: with SMTP id w68mr23302803pfd.146.1584942769827; Sun, 22 Mar 2020 22:52:49 -0700 (PDT) Received: from localhost.localdomain ([114.206.198.176]) by smtp.gmail.com with ESMTPSA id y30sm12563058pff.67.2020.03.22.22.52.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Mar 2020 22:52:49 -0700 (PDT) From: js1304@gmail.com X-Google-Original-From: iamjoonsoo.kim@lge.com To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Johannes Weiner , Michal Hocko , Hugh Dickins , Minchan Kim , Vlastimil Babka , Mel Gorman , kernel-team@lge.com, Joonsoo Kim Subject: [PATCH v4 6/8] mm/swap: implement workingset detection for anonymous LRU Date: Mon, 23 Mar 2020 14:52:10 +0900 Message-Id: <1584942732-2184-7-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1584942732-2184-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1584942732-2184-1-git-send-email-iamjoonsoo.kim@lge.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: From: Joonsoo Kim This patch implements workingset detection for anonymous LRU. All the infrastructure is implemented by the previous patches so this patch just activates the workingset detection by installing/retrieving the shadow entry. Signed-off-by: Joonsoo Kim --- include/linux/swap.h | 6 ++++++ mm/memory.c | 7 ++++++- mm/swap_state.c | 20 ++++++++++++++++++-- mm/vmscan.c | 7 +++++-- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 273de48..fb4772e 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -408,6 +408,7 @@ extern struct address_space *swapper_spaces[]; extern unsigned long total_swapcache_pages(void); extern void show_swap_cache_info(void); extern int add_to_swap(struct page *page); +extern void *get_shadow_from_swap_cache(swp_entry_t entry); extern int add_to_swap_cache(struct page *page, swp_entry_t entry, gfp_t gfp, void **shadowp); extern int __add_to_swap_cache(struct page *page, swp_entry_t entry); @@ -566,6 +567,11 @@ static inline int add_to_swap(struct page *page) return 0; } +static inline void *get_shadow_from_swap_cache(swp_entry_t entry) +{ + return NULL; +} + static inline int add_to_swap_cache(struct page *page, swp_entry_t entry, gfp_t gfp_mask, void **shadowp) { diff --git a/mm/memory.c b/mm/memory.c index 5f7813a..91a2097 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2925,10 +2925,15 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address); if (page) { + void *shadow; + __SetPageLocked(page); __SetPageSwapBacked(page); set_page_private(page, entry.val); - lru_cache_add_anon(page); + shadow = get_shadow_from_swap_cache(entry); + if (shadow) + workingset_refault(page, shadow); + lru_cache_add(page); swap_readpage(page, true); } } else { diff --git a/mm/swap_state.c b/mm/swap_state.c index f06af84..f996455 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -107,6 +107,18 @@ void show_swap_cache_info(void) printk("Total swap = %lukB\n", total_swap_pages << (PAGE_SHIFT - 10)); } +void *get_shadow_from_swap_cache(swp_entry_t entry) +{ + struct address_space *address_space = swap_address_space(entry); + pgoff_t idx = swp_offset(entry); + struct page *page; + + page = find_get_entry(address_space, idx); + if (xa_is_value(page)) + return page; + return NULL; +} + /* * add_to_swap_cache resembles add_to_page_cache_locked on swapper_space, * but sets SwapCache flag and private instead of mapping and index. @@ -376,6 +388,7 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, struct page *found_page = NULL, *new_page = NULL; struct swap_info_struct *si; int err; + void *shadow; *new_page_allocated = false; do { @@ -431,12 +444,15 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, /* May fail (-ENOMEM) if XArray node allocation failed. */ __SetPageLocked(new_page); __SetPageSwapBacked(new_page); + shadow = NULL; err = add_to_swap_cache(new_page, entry, - gfp_mask & GFP_KERNEL, NULL); + gfp_mask & GFP_KERNEL, &shadow); if (likely(!err)) { /* Initiate read into locked page */ SetPageWorkingset(new_page); - lru_cache_add_anon(new_page); + if (shadow) + workingset_refault(new_page, shadow); + lru_cache_add(new_page); *new_page_allocated = true; return new_page; } diff --git a/mm/vmscan.c b/mm/vmscan.c index 9871861..b37cc26 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -867,6 +867,7 @@ static int __remove_mapping(struct address_space *mapping, struct page *page, { unsigned long flags; int refcount; + void *shadow = NULL; BUG_ON(!PageLocked(page)); BUG_ON(mapping != page_mapping(page)); @@ -909,12 +910,13 @@ static int __remove_mapping(struct address_space *mapping, struct page *page, if (PageSwapCache(page)) { swp_entry_t swap = { .val = page_private(page) }; mem_cgroup_swapout(page, swap); - __delete_from_swap_cache(page, swap, NULL); + if (reclaimed && !mapping_exiting(mapping)) + shadow = workingset_eviction(page, target_memcg); + __delete_from_swap_cache(page, swap, shadow); xa_unlock_irqrestore(&mapping->i_pages, flags); put_swap_page(page, swap); } else { void (*freepage)(struct page *); - void *shadow = NULL; freepage = mapping->a_ops->freepage; /* @@ -1476,6 +1478,7 @@ static unsigned long shrink_page_list(struct list_head *page_list, SetPageActive(page); stat->nr_activate[type] += nr_pages; count_memcg_page_event(page, PGACTIVATE); + workingset_activation(page); } keep_locked: unlock_page(page);