From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18A48C4360F for ; Fri, 22 Mar 2019 13:11:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE52B2183E for ; Fri, 22 Mar 2019 13:11:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553260280; bh=+30MAuQ7nltHmuicCYJBWvPkZme67F0dnfzcFFudATo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=wxhOnD9PG9fK0DCG3w9YRLpK08os+2RC2VFqplfZB/XJ5YrB9AnM39onzSSJhjWqx pgM3FVoAAHlpgjl+sg0OA1XoOHPjhDxPPC3CdSbZM0WNomOeAa5EHaUUXxiP5qqzs3 N289gk8r+gqYK3IWI70Jr/KAPO9xIoqWMU1aNOnQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728951AbfCVLdD (ORCPT ); Fri, 22 Mar 2019 07:33:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:33320 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729850AbfCVLc5 (ORCPT ); Fri, 22 Mar 2019 07:32:57 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4AC3D21916; Fri, 22 Mar 2019 11:32:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553254376; bh=+30MAuQ7nltHmuicCYJBWvPkZme67F0dnfzcFFudATo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ob1ACvUaT9fQrHMFjqDMSUx28cD0sfQ6SR05V6FMsIZYdyq2J1ude978TRWlhyMkK 9PbKTesobLvPFvVG5xtrDXYEdz7TVy6b8aM38d8n29/wUlUFxi4ob1vzpaM0cm820U yOmdsgN0pH+WSsvJdNYTMqwrepGgyUshygXAgUNg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , Michal Hocko , Andrew Morton , Al Viro , Linus Torvalds , Sasha Levin Subject: [PATCH 4.4 102/230] fs/drop_caches.c: avoid softlockups in drop_pagecache_sb() Date: Fri, 22 Mar 2019 12:14:00 +0100 Message-Id: <20190322111243.754326698@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111236.796964179@linuxfoundation.org> References: <20190322111236.796964179@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit c27d82f52f75fc9d8d9d40d120d2a96fdeeada5e ] When superblock has lots of inodes without any pagecache (like is the case for /proc), drop_pagecache_sb() will iterate through all of them without dropping sb->s_inode_list_lock which can lead to softlockups (one of our customers hit this). Fix the problem by going to the slow path and doing cond_resched() in case the process needs rescheduling. Link: http://lkml.kernel.org/r/20190114085343.15011-1-jack@suse.cz Signed-off-by: Jan Kara Acked-by: Michal Hocko Reviewed-by: Andrew Morton Cc: Al Viro Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/drop_caches.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/drop_caches.c b/fs/drop_caches.c index d72d52b90433..280460fef066 100644 --- a/fs/drop_caches.c +++ b/fs/drop_caches.c @@ -20,8 +20,13 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused) spin_lock(&sb->s_inode_list_lock); list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { spin_lock(&inode->i_lock); + /* + * We must skip inodes in unusual state. We may also skip + * inodes without pages but we deliberately won't in case + * we need to reschedule to avoid softlockups. + */ if ((inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) || - (inode->i_mapping->nrpages == 0)) { + (inode->i_mapping->nrpages == 0 && !need_resched())) { spin_unlock(&inode->i_lock); continue; } @@ -29,6 +34,7 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused) spin_unlock(&inode->i_lock); spin_unlock(&sb->s_inode_list_lock); + cond_resched(); invalidate_mapping_pages(inode->i_mapping, 0, -1); iput(toput_inode); toput_inode = inode; -- 2.19.1