From patchwork Tue Apr 18 20:04:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9686191 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 37BF4602C9 for ; Tue, 18 Apr 2017 20:04:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 258BC28387 for ; Tue, 18 Apr 2017 20:04:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A24C283E2; Tue, 18 Apr 2017 20:04:23 +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=-6.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5593C28387 for ; Tue, 18 Apr 2017 20:04:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757665AbdDRUEV (ORCPT ); Tue, 18 Apr 2017 16:04:21 -0400 Received: from mail-yw0-f195.google.com ([209.85.161.195]:35790 "EHLO mail-yw0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757563AbdDRUET (ORCPT ); Tue, 18 Apr 2017 16:04:19 -0400 Received: by mail-yw0-f195.google.com with SMTP id k13so254637ywk.2 for ; Tue, 18 Apr 2017 13:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=Qsq2U3E13Uc9M+WVscu1Hvyrfbfho9jocU0wUHxMweI=; b=WW6bmzfiRTEcY39VvaYGutiTDPFvue2ueKLaCtMXKh1GmObWcAHPl8fW/KxGPXCcC0 FqwCDZOOGP4ecj9ZDOxJfceONjkPRhlDSXEM/S2gMW3pcLqw6PapqYLQ81482e08+viH Vz7xEsdlU7iGVZh9kcgBhE3CKhiNnuhfLthqyX0tToDHJyRBv6aTLiDBc6xrz6je3W98 gLVO3tIwrYNFmL41R4sbZ9wIpytSl3bVVVG4zQJGrWmJ8mH/e4SVKzQwC3TlAhdAYlAj /H/z9hQH3DW1Fu4uJUtBm3qaLD/Z/SkM4mlv1CqUa4aeS+tAowRLm3TIEaUb8GwMLB/j izGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=Qsq2U3E13Uc9M+WVscu1Hvyrfbfho9jocU0wUHxMweI=; b=G4hWzps+zCx66EqS1fXktmLcFwWKEpOF955UZ5f7NgRLXjytZqMOYC4ohCjDAcNiIn 5EXxHMIzTmSyDzodpUTlit+ZReuZlBrTAZv7XuA1h7d2luCb/nsLF3e5eDmdhzbDo5PS tZVFmnC0U67ypoThu9/lqlSv9OZcRYMRyoS221FZKiPkzeFfipju4z4MuCS5yza3ozRd 0xnlSwhKCfpBo7pI+lWYUpN9Ml1yr9nzI8T8PWm2dz9HSOM5aFPbr7TxjMkmmgIJ5W9W 5JtI1Consv7QDkFpSePNgyaDQUSx/gBv/qXHafI3yIehLj/05jowrU4hDzTZg1Nv7MU/ nOUQ== X-Gm-Message-State: AN3rC/7LHOW7DIFBVEas42EVVd8x37yHn57tYbTnd+JKiBFDl+cI46MO EN5hGAX5CIy1kw== X-Received: by 10.13.235.144 with SMTP id u138mr23406548ywe.322.1492545859057; Tue, 18 Apr 2017 13:04:19 -0700 (PDT) Received: from localhost (cpe-2606-A000-4381-1201-225-22FF-FEB3-E51A.dyn6.twc.com. [2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id v207sm70492ywa.45.2017.04.18.13.04.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 13:04:18 -0700 (PDT) From: Josef Bacik X-Google-Original-From: Josef Bacik To: viro@ZenIV.linux.org.uk, jack@suse.cz, david@fromorbit.com, linux-fsdevel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH] fs: don't set *REFERENCED on single use objects Date: Tue, 18 Apr 2017 16:04:17 -0400 Message-Id: <1492545857-3695-1-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 2.7.4 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP By default we set DCACHE_REFERENCED and I_REFERENCED on any dentry or inode we create. This is problematic as this means that it takes two trips through the LRU for any of these objects to be reclaimed, regardless of their actual lifetime. With enough pressure from these caches we can easily evict our working set from page cache with single use objects. So instead only set *REFERENCED if we've already been added to the LRU list. This means that we've been touched since the first time we were accessed, and so more likely to need to hang out in cache. To illustrate this issue I wrote the following scripts https://github.com/josefbacik/debug-scripts/tree/master/cache-pressure on my test box. It is a single socket 4 core CPU with 16gib of RAM and I tested on an Intel 2tib NVME drive. The cache-pressure.sh script creates a new file system and creates 2 6.5gib files in order to take up 13gib of the 16gib of ram with pagecache. Then it runs a test program that reads these 2 files in a loop, and keeps track of how often it has to read bytes for each loop. On an ideal system with no pressure we should have to read 0 bytes indefinitely. The second thing this script does is start a fs_mark job that creates a ton of 0 length files, putting pressure on the system with slab only allocations. On exit the script prints out how many bytes were read by the read-file program. The results are as follows Without patch: /mnt/btrfs-test/reads/file1: total read during loops 27262988288 /mnt/btrfs-test/reads/file2: total read during loops 27262976000 With patch: /mnt/btrfs-test/reads/file2: total read during loops 18640457728 /mnt/btrfs-test/reads/file1: total read during loops 9565376512 This patch results in a 50% reduction of the amount of pages evicted from our working set. Signed-off-by: Josef Bacik Reviewed-by: Jan Kara --- fs/dcache.c | 4 ++-- fs/inode.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index 95d71ed..cddf397 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -419,6 +419,8 @@ static void dentry_lru_add(struct dentry *dentry) { if (unlikely(!(dentry->d_flags & DCACHE_LRU_LIST))) d_lru_add(dentry); + else if (unlikely(!(dentry->d_flags & DCACHE_REFERENCED))) + dentry->d_flags |= DCACHE_REFERENCED; } /** @@ -779,8 +781,6 @@ void dput(struct dentry *dentry) goto kill_it; } - if (!(dentry->d_flags & DCACHE_REFERENCED)) - dentry->d_flags |= DCACHE_REFERENCED; dentry_lru_add(dentry); dentry->d_lockref.count--; diff --git a/fs/inode.c b/fs/inode.c index 88110fd..9dfa8f1 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -405,6 +405,8 @@ static void inode_lru_list_add(struct inode *inode) { if (list_lru_add(&inode->i_sb->s_inode_lru, &inode->i_lru)) this_cpu_inc(nr_unused); + else + inode->i_state |= I_REFERENCED; } /* @@ -1492,7 +1494,6 @@ static void iput_final(struct inode *inode) drop = generic_drop_inode(inode); if (!drop && (sb->s_flags & MS_ACTIVE)) { - inode->i_state |= I_REFERENCED; inode_add_lru(inode); spin_unlock(&inode->i_lock); return;