Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2025813ybh; Fri, 13 Mar 2020 11:35:46 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsDBIkNJ6YDdU2CxfzTmP61ouQVUFmTlx71NlkSsoDhvCWwDTjjw9lG+gYH5Yzae82qymIf X-Received: by 2002:a9d:4b01:: with SMTP id q1mr11816141otf.168.1584124546512; Fri, 13 Mar 2020 11:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584124546; cv=none; d=google.com; s=arc-20160816; b=pv0Qvjx+nkrrPF/sZz0za3UM2aytEM2C1SW98Zlsgeq+vTif4oafaVylQ4H2iY4gxx PvgWp9GNAuO6M+ypRL7Epi08jiFZicd2h6+2HDEo4JYCARIXAKPkLJiUDOJbRt7Gn6gL hQm/U03eIxnTb95udjZIoQRau4V9NTF1V2F7URwI1SGN0/hoZX2HJptkD5ftMdPBIKcd +4Bz+8UqFT1HFjYi3acu5vSMwFlmdWn7RbhUFq6vJvX26Q2c+21Ak1ypl5sXsFvVLrvD hSvrUjNqAuHyL1R50XzPf8SM3V6bZFhkNpXc7/NyOOnvC0oT86woVJFqhyWAn8y/YP+P wxhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=srAyWadjt2gbrs5GtpE5AkG+3jWV5KT4vZyowAOBoWI=; b=VFJPNczR0iQMcEH+7qIjDFGdFCl3beWvvaMM2KprbkEUsICIbIYWiGxd5fCyieQxxG oAFg+CM77xbiuxYEQsW5mD3Y9R7u+gXBuWgKf28S+8nx0fXY8ZeSW//v/s7GtRcI/GgT 6vkID0PxKYFgWafstkpuw0cyMs93gJuC5+Bi0/JuNqjr7KPzFV3Y3DlYqInM03RcRKrg kzC0hQMVZCd+V1MaIiVJWHQHfK9hw/6rSGOsYhfsK5FdfuYdhE5OjNNSk7W2VbXffJ5z H6n1YglSEGZmrzVPE3OcsoBOmeBBeVFDWCxehYMEwQeaJt8bxYQ+XomYU/0QgQ4HpcmV JHvg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c85si4943490oig.225.2020.03.13.11.35.34; Fri, 13 Mar 2020 11:35:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727459AbgCMSe4 (ORCPT + 99 others); Fri, 13 Mar 2020 14:34:56 -0400 Received: from out30-57.freemail.mail.aliyun.com ([115.124.30.57]:45552 "EHLO out30-57.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727383AbgCMSet (ORCPT ); Fri, 13 Mar 2020 14:34:49 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04455;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0TsV0Vh4_1584124476; Received: from localhost(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TsV0Vh4_1584124476) by smtp.aliyun-inc.com(127.0.0.1); Sat, 14 Mar 2020 02:34:45 +0800 From: Yang Shi To: shakeelb@google.com, vbabka@suse.cz, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] mm: swap: make page_evictable() inline Date: Sat, 14 Mar 2020 02:34:35 +0800 Message-Id: <1584124476-76534-1-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When backporting commit 9c4e6b1a7027 ("mm, mlock, vmscan: no more skipping pagevecs") to our 4.9 kernel, our test bench noticed around 10% down with a couple of vm-scalability's test cases (lru-file-readonce, lru-file-readtwice and lru-file-mmap-read). I didn't see that much down on my VM (32c-64g-2nodes). It might be caused by the test configuration, which is 32c-256g with NUMA disabled and the tests were run in root memcg, so the tests actually stress only one inactive and active lru. It sounds not very usual in mordern production environment. That commit did two major changes: 1. Call page_evictable() 2. Use smp_mb to force the PG_lru set visible It looks they contribute the most overhead. The page_evictable() is a function which does function prologue and epilogue, and that was used by page reclaim path only. However, lru add is a very hot path, so it sounds better to make it inline. However, it calls page_mapping() which is not inlined either, but the disassemble shows it doesn't do push and pop operations and it sounds not very straightforward to inline it. Other than this, it sounds smp_mb() is not necessary for x86 since SetPageLRU is atomic which enforces memory barrier already, replace it with smp_mb__after_atomic() in the following patch. With the two fixes applied, the tests can get back around 5% on that test bench and get back normal on my VM. Since the test bench configuration is not that usual and I also saw around 6% up on the latest upstream, so it sounds good enough IMHO. The below is test data (lru-file-readtwice throughput) against the v5.6-rc4: mainline w/ inline fix 150MB 154MB With this patch the throughput gets 2.67% up. The data with using smp_mb__after_atomic() is showed in the following patch. Fixes: 9c4e6b1a7027 ("mm, mlock, vmscan: no more skipping pagevecs") Cc: Shakeel Butt Cc: Vlastimil Babka Signed-off-by: Yang Shi --- include/linux/swap.h | 24 +++++++++++++++++++++++- mm/vmscan.c | 23 ----------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 1e99f7a..297eb66 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -374,7 +374,29 @@ extern unsigned long mem_cgroup_shrink_node(struct mem_cgroup *mem, #define node_reclaim_mode 0 #endif -extern int page_evictable(struct page *page); +/* + * page_evictable - test whether a page is evictable + * @page: the page to test + * + * Test whether page is evictable--i.e., should be placed on active/inactive + * lists vs unevictable list. + * + * Reasons page might not be evictable: + * (1) page's mapping marked unevictable + * (2) page is part of an mlocked VMA + * + */ +static inline int page_evictable(struct page *page) +{ + int ret; + + /* Prevent address_space of inode and swap cache from being freed */ + rcu_read_lock(); + ret = !mapping_unevictable(page_mapping(page)) && !PageMlocked(page); + rcu_read_unlock(); + return ret; +} + extern void check_move_unevictable_pages(struct pagevec *pvec); extern int kswapd_run(int nid); diff --git a/mm/vmscan.c b/mm/vmscan.c index 8763705..855c395 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4277,29 +4277,6 @@ int node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, unsigned int order) } #endif -/* - * page_evictable - test whether a page is evictable - * @page: the page to test - * - * Test whether page is evictable--i.e., should be placed on active/inactive - * lists vs unevictable list. - * - * Reasons page might not be evictable: - * (1) page's mapping marked unevictable - * (2) page is part of an mlocked VMA - * - */ -int page_evictable(struct page *page) -{ - int ret; - - /* Prevent address_space of inode and swap cache from being freed */ - rcu_read_lock(); - ret = !mapping_unevictable(page_mapping(page)) && !PageMlocked(page); - rcu_read_unlock(); - return ret; -} - /** * check_move_unevictable_pages - check pages for evictability and move to * appropriate zone lru list -- 1.8.3.1