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=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 1B377C433E1 for ; Tue, 2 Jun 2020 04:47:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D163520734 for ; Tue, 2 Jun 2020 04:47:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="l9xdCR3v" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D163520734 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6EBEA8001C; Tue, 2 Jun 2020 00:47:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C18F80019; Tue, 2 Jun 2020 00:47:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5892C8001C; Tue, 2 Jun 2020 00:47:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0049.hostedemail.com [216.40.44.49]) by kanga.kvack.org (Postfix) with ESMTP id 3F81D80019 for ; Tue, 2 Jun 2020 00:47:01 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0001A180AD804 for ; Tue, 2 Jun 2020 04:47:00 +0000 (UTC) X-FDA: 76883037000.28.wind71_201ad0dde1a2f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id D5E4C6D7F for ; Tue, 2 Jun 2020 04:47:00 +0000 (UTC) X-HE-Tag: wind71_201ad0dde1a2f X-Filterd-Recvd-Size: 4246 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Tue, 2 Jun 2020 04:47:00 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (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 23E67207DA; Tue, 2 Jun 2020 04:46:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591073219; bh=v608GgkT5y9JzOeoivP7FuUBw9nRXaopVp+2VPIeyHI=; h=Date:From:To:Subject:In-Reply-To:From; b=l9xdCR3vvxv613BvtEdlAmWJMGUcE/loEKpjdYm6ZMag4V2ZBS2tKsIsU1UwIzupG LEryq0SCsWzO2vZot2vVzouZt4QASSw23Rg6QA7IFIcfgKn2h/hI+VDub4CPwudv+0 9u2NA6cH32WSy3uYfktKOJt3z0olpomr2ElMCGAk= Date: Mon, 01 Jun 2020 21:46:58 -0700 From: Andrew Morton To: akpm@linux-foundation.org, darrick.wong@oracle.com, dchinner@redhat.com, ebiggers@google.com, gaoxiang25@huawei.com, hch@lst.de, jaegeuk@kernel.org, jhubbard@nvidia.com, johannes.thumshirn@wdc.com, joseph.qi@linux.alibaba.com, junxiao.bi@oracle.com, linux-mm@kvack.org, mhocko@suse.com, mm-commits@vger.kernel.org, mszeredi@redhat.com, torvalds@linux-foundation.org, william.kucharski@oracle.com, willy@infradead.org, xiyou.wangcong@gmail.com, yuchao0@huawei.com, ziy@nvidia.com Subject: [patch 028/128] mm: use memalloc_nofs_save in readahead path Message-ID: <20200602044658.DKJ9Mr8Be%akpm@linux-foundation.org> In-Reply-To: <20200601214457.919c35648e96a2b46b573fe1@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: D5E4C6D7F X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: "Matthew Wilcox (Oracle)" Subject: mm: use memalloc_nofs_save in readahead path Ensure that memory allocations in the readahead path do not attempt to reclaim file-backed pages, which could lead to a deadlock. It is possible, though unlikely this is the root cause of a problem observed by Cong Wang. Link: http://lkml.kernel.org/r/20200414150233.24495-16-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) Reported-by: Cong Wang Suggested-by: Michal Hocko Reviewed-by: William Kucharski Cc: Chao Yu Cc: Christoph Hellwig Cc: Darrick J. Wong Cc: Dave Chinner Cc: Eric Biggers Cc: Gao Xiang Cc: Jaegeuk Kim Cc: John Hubbard Cc: Joseph Qi Cc: Junxiao Bi Cc: Zi Yan Cc: Johannes Thumshirn Cc: Miklos Szeredi Signed-off-by: Andrew Morton --- mm/readahead.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) --- a/mm/readahead.c~mm-use-memalloc_nofs_save-in-readahead-path +++ a/mm/readahead.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "internal.h" @@ -186,6 +187,18 @@ void page_cache_readahead_unbounded(stru unsigned long i; /* + * Partway through the readahead operation, we will have added + * locked pages to the page cache, but will not yet have submitted + * them for I/O. Adding another page may need to allocate memory, + * which can trigger memory reclaim. Telling the VM we're in + * the middle of a filesystem operation will cause it to not + * touch file-backed pages, preventing a deadlock. Most (all?) + * filesystems already specify __GFP_NOFS in their mapping's + * gfp_mask, but let's be explicit here. + */ + unsigned int nofs = memalloc_nofs_save(); + + /* * Preallocate as many pages as we will need. */ for (i = 0; i < nr_to_read; i++) { @@ -229,6 +242,7 @@ void page_cache_readahead_unbounded(stru * will then handle the error. */ read_pages(&rac, &page_pool, false); + memalloc_nofs_restore(nofs); } EXPORT_SYMBOL_GPL(page_cache_readahead_unbounded); _