From patchwork Thu Sep 20 05:50:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 972141 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 42G5Sj6dlfz9sBy; Thu, 20 Sep 2018 15:51:17 +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 1g2rrq-0006qL-Ng; Thu, 20 Sep 2018 05:51:10 +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 1g2rro-0006pn-OX for kernel-team@lists.canonical.com; Thu, 20 Sep 2018 05:51:08 +0000 Received: from mail-qk1-f199.google.com ([209.85.222.199]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1g2rro-0002sn-EF for kernel-team@lists.canonical.com; Thu, 20 Sep 2018 05:51:08 +0000 Received: by mail-qk1-f199.google.com with SMTP id p192-v6so5045340qke.13 for ; Wed, 19 Sep 2018 22:51:08 -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=+8bXC+KAMD+LvgL+FKkWzGr65cyD0/0yUSa86MGLId4=; b=RVBBORVPVaF6A12zU/mth1eau0NIIb1Kfmx64oNFN5tT4dVH1s9JxvtMBOW/lSIe0i qGX9eXxp8DPVljAM3vtpbDxLe9N/5ANeddAULT+wbLpRCw1I/CiNHWA9sUxTT2P9b7aM z5dKmKo+W5K0zy05n/N812GBE+vNbVxh8QCR7JDdBb+XccHFM0TdMjqR3BiJZrX7iu+9 rO1t7PvGvhKqAe73wPtMNzx2pJ0iiNtJB2J5GHw6vvlV/BzsgiSe30tkb9N4OKJlwguM RNhISxAIEAHhY9XjPvZME4yBjOudaGD9/a+B0mJNoSJpsB+t9dULZqZI3PwweEDNrDAl GQjw== X-Gm-Message-State: APzg51ARsjxQpya/32Ypt6MeqfN2hs2gaczg/y//ASo0m1l4thzNCxyC rNCKvg694TnmVT8o+mMl0rmcTJxzysI8LNbAoO93zHTQloYc4N62IrrgTEScrmpV6e2Ngd7Cnxq fgpKJO3gbfu9/p+LSGfoZdb0HDDbXHUQxcVwjGEcIRCtBSwOv X-Received: by 2002:a0c:937b:: with SMTP id e56-v6mr26701576qve.4.1537422667360; Wed, 19 Sep 2018 22:51:07 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYcE0eKkEImpFgqNVpr356na4OnDSqjqQRYvB63FLy+W+DrXGPvEDquxCwpcVoPhLZhKcfV4g== X-Received: by 2002:a0c:937b:: with SMTP id e56-v6mr26701572qve.4.1537422667150; Wed, 19 Sep 2018 22:51:07 -0700 (PDT) Received: from linkitivity.iinet.net.au ([2001:67c:1562:8007::aac:4356]) by smtp.gmail.com with ESMTPSA id 127-v6sm12828398qke.94.2018.09.19.22.51.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Sep 2018 22:51:06 -0700 (PDT) From: Daniel Axtens To: kernel-team@lists.canonical.com Subject: [SRU B][C][PATCH 1/1] UBUNTU: SAUCE: cachefiles: Page leaking in cachefiles_read_backing_file while vmscan is active Date: Thu, 20 Sep 2018 15:50:57 +1000 Message-Id: <20180920055057.3121-2-daniel.axtens@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180920055057.3121-1-daniel.axtens@canonical.com> References: <20180920055057.3121-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-August/msg00007.html This is v2 of the patch. It 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 --- fs/cachefiles/rdwr.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c index e09438612607..54d11248910c 100644 --- a/fs/cachefiles/rdwr.c +++ b/fs/cachefiles/rdwr.c @@ -274,6 +274,8 @@ static int cachefiles_read_backing_file_one(struct cachefiles_object *object, goto installed_new_backing_page; if (ret != -EEXIST) goto nomem_page; + put_page(newpage); + newpage = NULL; } /* we've installed a new backing page, so now we need to start @@ -511,6 +513,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 +539,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,6 +615,8 @@ 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); fscache_retrieval_complete(op, 1); continue;