From patchwork Sat Mar 25 07:49:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Kozik X-Patchwork-Id: 9644451 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 A320C6020B for ; Sat, 25 Mar 2017 07:49:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B307228C9 for ; Sat, 25 Mar 2017 07:49:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5DFBE265B9; Sat, 25 Mar 2017 07:49:13 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 C01B9228C9 for ; Sat, 25 Mar 2017 07:49:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751197AbdCYHtL (ORCPT ); Sat, 25 Mar 2017 03:49:11 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:34509 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751159AbdCYHtK (ORCPT ); Sat, 25 Mar 2017 03:49:10 -0400 Received: by mail-pf0-f179.google.com with SMTP id p189so5034478pfp.1 for ; Sat, 25 Mar 2017 00:49:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ludios.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=xfvoZBHJNmgtIL+ogLEgrSWjpKrTUogaHKqrE9+Y/vs=; b=BxTTXrf3L0UrNubSygzTFQ9eJ2dcMTZSlCcGJlzk/z/db5jLKpjtfYTbqEO3xUegdh dhL/QvzgSSdj8Yag38Bdz12mm0wMjC0G5OpfnPYvUpy25vSyIkCWctfqCC+qCMrFUepa 1vkF2CMVOVYK/1UnYt+y45xE6Bbj8w5hCdPsw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=xfvoZBHJNmgtIL+ogLEgrSWjpKrTUogaHKqrE9+Y/vs=; b=JPrTu42SBU+cDUKasacMhrq/IoeCG+QRInlEHWovAKcq2i/0sl8sGgAizm77utJxlp mf9bZJg1KGF1hNvjPJ9Z4XFRNsLRpbndZxWbuKDgHf/NDcrOSsXUMIYWd1bsFFm9BS4m SfnWHqkBjAiYpyBhwYpgiYYQ3NilZwOFvK42pGIaqsEYnunKlZQoDN/z0U5FJ3Cpd8JC YFgeDkxU8F7MApeBGVDGSHRbm8asKMeuY+VLQQgSLRrn5iiuMbEs2TpH/91i/xQv5hfk cKTOcmOVr1dvZkfinXSTJr0mixyhHVwOZ/M4Bydy44AfvDN+3YXo7ly7b6Lqeam3MiBw i60Q== X-Gm-Message-State: AFeK/H3VkAdYt02CcVokHwX5z3Ahcyl7jBKrGUaDYna/UF5Z+bU9wwqY79qdGZkzSfE+tw== X-Received: by 10.99.64.4 with SMTP id n4mr13383122pga.71.1490428148871; Sat, 25 Mar 2017 00:49:08 -0700 (PDT) Received: from localhost ([138.197.221.17]) by smtp.gmail.com with ESMTPSA id z62sm8649353pff.88.2017.03.25.00.49.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Mar 2017 00:49:04 -0700 (PDT) Date: Sat, 25 Mar 2017 07:49:00 +0000 From: Ivan Kozik To: stable@vger.kernel.org Cc: linux-xfs@vger.kernel.org, darrick.wong@oracle.com, bfoster@redhat.com, david@fromorbit.com Subject: Request 2aa6ba7b5ad3 ("clear _XBF_PAGES from buffers when readahead page") for 4.4 stable inclusion Message-ID: <20170325074856.GA20773@localhost> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, I would like to request that this patch be included in the 4.4 stable tree. It fixes the Bad page state issue discovered at http://oss.sgi.com/archives/xfs/2016-08/msg00617.html ('"Bad page state" errors when calling BULKSTAT under memory pressure?') I tested the patch (no changes needed) by applying it to 4.4.52, running a program to use almost all of my free memory, then running xfs_fsr on a filesystem with > 1.5M files. Before patch: kernel screams with Bad page state / "count:-1" within a minute. After patch: no complaints from the kernel. I repeated the test several times and on another machine that was affected. I have not seen any problems five days later. Thanks, Ivan >From 2aa6ba7b5ad3189cc27f14540aa2f57f0ed8df4b Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Wed, 25 Jan 2017 20:24:57 -0800 Subject: [PATCH] xfs: clear _XBF_PAGES from buffers when readahead page If we try to allocate memory pages to back an xfs_buf that we're trying to read, it's possible that we'll be so short on memory that the page allocation fails. For a blocking read we'll just wait, but for readahead we simply dump all the pages we've collected so far. Unfortunately, after dumping the pages we neglect to clear the _XBF_PAGES state, which means that the subsequent call to xfs_buf_free thinks that b_pages still points to pages we own. It then double-frees the b_pages pages. This results in screaming about negative page refcounts from the memory manager, which xfs oughtn't be triggering. To reproduce this case, mount a filesystem where the size of the inodes far outweighs the availalble memory (a ~500M inode filesystem on a VM with 300MB memory did the trick here) and run bulkstat in parallel with other memory eating processes to put a huge load on the system. The "check summary" phase of xfs_scrub also works for this purpose. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen Acked-by: Darrick J. Wong --- fs/xfs/xfs_buf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index 7f0a01f7b592..ac3b4db519df 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -422,6 +422,7 @@ retry: out_free_pages: for (i = 0; i < bp->b_page_count; i++) __free_page(bp->b_pages[i]); + bp->b_flags &= ~_XBF_PAGES; return error; }