From patchwork Mon Sep 24 02:11:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 973812 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42JSPw6KyHz9sBZ; Mon, 24 Sep 2018 12:12:04 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1g4GLs-0000yJ-6j; Mon, 24 Sep 2018 02:11:56 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1g4GLq-0000yA-Da for kernel-team@lists.canonical.com; Mon, 24 Sep 2018 02:11:54 +0000 Received: from mail-pg1-f198.google.com ([209.85.215.198]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1g4GLq-0007eW-28 for kernel-team@lists.canonical.com; Mon, 24 Sep 2018 02:11:54 +0000 Received: by mail-pg1-f198.google.com with SMTP id v186-v6so6370027pgb.14 for ; Sun, 23 Sep 2018 19:11:53 -0700 (PDT) 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=wDSOMrBuumLrgHEVsGwDlD77QjoTbR7Phx8K5Gb35Ls=; b=BTGGzEy0sjXr8PAGWmdUMDP+99/3vKPzHeK2G0/jchE7UVBiWCXYPksBGFUbpMRRQl u/gcA2utFLnj/0ChkG+bB/6HDfvcHCOVdXfBTeCuHSmhw/CT3ct/jYvDgyC9Lhha8OyD vLA52u679N8luzX38+C2emvLKtYof5otsXUE6Iw0eaFTNaFmcjia68oql8zvQQiY8RiU Cipdalk650zmwhU5iz4UKw0XWbS5J44wyuVuCmcyJUHYgSuXO1WENPoRvWwh+aPkEE1W zsPYUtl8aur4sjVSl6L4I1URSws7vhL6YfM3D+VfNsmTZJExLjMp56nSK5FDwpw2HKlP z+lA== X-Gm-Message-State: ABuFfog65SyZRezMhqGaM5hTsQkSnV3YJdW3V1UL8CUUch6m6CRfF37e fVGuBleXj517Q3oUKT22TBvzmW9lsLmeFAnwcRnvyFd+qnvfYiUwjB+wgfg2INGLcmz61e18S3T CNZLHgjWyCEDOZWg5cAE/i3pz/RZ57+2I0+V5My0GGCIjaBgL X-Received: by 2002:a17:902:3a5:: with SMTP id d34-v6mr8463034pld.98.1537755112550; Sun, 23 Sep 2018 19:11:52 -0700 (PDT) X-Google-Smtp-Source: ACcGV63W8/M1ZCqVW6EU3oRV0xWzYOtHGgUTxqbEYPBXm6qCt4BUjD2L8m7B0F8mOoOk8OKZyEo9PA== X-Received: by 2002:a17:902:3a5:: with SMTP id d34-v6mr8463025pld.98.1537755112321; Sun, 23 Sep 2018 19:11:52 -0700 (PDT) Received: from linkitivity.iinet.net.au (dip-220-235-51-100.wa.westnet.com.au. [220.235.51.100]) by smtp.gmail.com with ESMTPSA id p64-v6sm51061408pfa.47.2018.09.23.19.11.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Sep 2018 19:11:51 -0700 (PDT) From: Daniel Axtens To: kernel-team@lists.canonical.com Subject: [SRU B][C][PATCH v2 1/1] UBUNTU: SAUCE: cachefiles: Page leaking in cachefiles_read_backing_file while vmscan is active Date: Mon, 24 Sep 2018 12:11:43 +1000 Message-Id: <20180924021143.555-2-daniel.axtens@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180924021143.555-1-daniel.axtens@canonical.com> References: <20180924021143.555-1-daniel.axtens@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kiran.modukuri@gmail.com MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Kiran Kumar Modukuri BugLink: https://bugs.launchpad.net/bugs/1793430 [Description] In a heavily loaded system where the system pagecache is nearing memory limits and fscache is enabled, pages can be leaked by fscache while trying read pages from cachefiles backend. This can happen because two applications can be reading same page from a single mount, two threads can be trying to read the backing page at same time. This results in one of the thread finding that a page for the backing file or netfs file is already in the radix tree. During the error handling cachefiles does not cleanup the reference on backing page, leading to page leak. [Fix] The fix is straightforward, to decrement the reference when error is encounterd. [Testing] I have tested the fix using following method for 12+ hrs. 1) mkdir -p /mnt/nfs ; mount -o vers=3,fsc :/export /mnt/nfs 2) create 10000 files of 2.8MB in a NFS mount. 3) start a thread to simulate heavy VM presssure (while true ; do echo 3 > /proc/sys/vm/drop_caches ; sleep 1 ; done)& 4) start multiple parallel reader for data set at same time find /mnt/nfs -type f | xargs -P 80 cat > /dev/null & find /mnt/nfs -type f | xargs -P 80 cat > /dev/null & find /mnt/nfs -type f | xargs -P 80 cat > /dev/null & .. .. find /mnt/nfs -type f | xargs -P 80 cat > /dev/null & find /mnt/nfs -type f | xargs -P 80 cat > /dev/null & 5) finally check using cat /proc/fs/fscache/stats | grep -i pages ; free -h , cat /proc/meminfo and page-types -r -b lru to ensure all pages are freed. Reviewed-by: Daniel Axtens Signed-off-by: Shantanu Goel Signed-off-by: Kiran Kumar Modukuri [dja: forward ported to current upstream] Signed-off-by: Daniel Axtens [applied from https://www.redhat.com/archives/linux-cachefs/2018-September/msg00002.html This is v3 of the patch. v2 has sat on the list for weeks without any response or forward progress. v1 was first posted in 2014 and was reposted this August.] Signed-off-by: Daniel Axtens --- Canonical v2/Upstream v3: Clean up per Seth's feedback. --- fs/cachefiles/rdwr.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c index e09438612607..4d03a0c93eda 100644 --- a/fs/cachefiles/rdwr.c +++ b/fs/cachefiles/rdwr.c @@ -511,6 +511,8 @@ static int cachefiles_read_backing_file(struct cachefiles_object *object, goto installed_new_backing_page; if (ret != -EEXIST) goto nomem; + put_page(newpage); + newpage = NULL; } /* we've installed a new backing page, so now we need @@ -535,7 +537,10 @@ static int cachefiles_read_backing_file(struct cachefiles_object *object, netpage->index, cachefiles_gfp); if (ret < 0) { if (ret == -EEXIST) { + put_page(backpage); + backpage = NULL; put_page(netpage); + netpage = NULL; fscache_retrieval_complete(op, 1); continue; } @@ -608,7 +613,10 @@ static int cachefiles_read_backing_file(struct cachefiles_object *object, netpage->index, cachefiles_gfp); if (ret < 0) { if (ret == -EEXIST) { + put_page(backpage); + backpage = NULL; put_page(netpage); + netpage = NULL; fscache_retrieval_complete(op, 1); continue; }