From patchwork Tue Dec 4 02:08:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 10711055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FD8F14E2 for ; Tue, 4 Dec 2018 02:06:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 931822AF49 for ; Tue, 4 Dec 2018 02:06:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86E392AF4D; Tue, 4 Dec 2018 02:06:16 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75DB92AF49 for ; Tue, 4 Dec 2018 02:06:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E79D6B6C40; Mon, 3 Dec 2018 21:06:14 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 397206B6C41; Mon, 3 Dec 2018 21:06:14 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 285C06B6C42; Mon, 3 Dec 2018 21:06:14 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by kanga.kvack.org (Postfix) with ESMTP id EFFA06B6C40 for ; Mon, 3 Dec 2018 21:06:13 -0500 (EST) Received: by mail-oi1-f198.google.com with SMTP id p131so2168576oig.10 for ; Mon, 03 Dec 2018 18:06:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:mime-version; bh=HeUGHEkJDFxg+o1MzYDka6+sl+WrrpWYLApr2db5h4Y=; b=SxXThOVH05/f9jgqaBN52PMdJwafRQqRMAu0IP473Iq0KkpFhxFsiPAooYqZ5hyl0g Tb5E/T7AIDRxydu46tDXv5uzNU1lV2U8Krbm1iIoAn2w/X3pn+3etX6T6TgtDA437ZyJ ldFm097HX+MQaA5l8eKxuCeNmqx3fOwppf61EPEa4elcHedy7dY6p5HK6hThg+cGuMoB T6hrCyYFIQfLhdDlLkkIn7ATFM8ILrwolIHS56jsRLHuRM9qtcOMu0laQHeRO9dHsuiu R7GO3xWFh7xQEr9leZp9lh2dOnpsJ2I9tOKYxsbrjWlYWS+xCq3j9JwWOkkJzY4gorrw 8ynQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of houtao1@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=houtao1@huawei.com X-Gm-Message-State: AA+aEWa9ep1Y+XlPiU4j1k+uAj+Nd9IeVCL5s5GAaKRKOSrRIh3Ny9fM JlBNfd/ZQhUafjHbT2KfBT7CsgJjMcoy4ygVQvlD/oaF/f9gP6QVEqBzWLWS8l9HkVzaQ/gdFTv iqfaV8fmjlk7uP+eMQVYQv0FyGhN/2xTyE10FNvZsMWIlj+f1eBV7vw9JRIHFZ/OCEA== X-Received: by 2002:aca:2ec5:: with SMTP id u188mr11933781oiu.291.1543889173588; Mon, 03 Dec 2018 18:06:13 -0800 (PST) X-Google-Smtp-Source: AFSGD/VSa51IN5b9ARoiYkVeshzkcyUR+Vps5HmRFql/FO0jZrf6GgXxFSzoLzipUzBZ4paZwofw X-Received: by 2002:aca:2ec5:: with SMTP id u188mr11933755oiu.291.1543889172800; Mon, 03 Dec 2018 18:06:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543889172; cv=none; d=google.com; s=arc-20160816; b=I8piFQVPpmNq/tB1tFbf7pk6c5ODhP13eyaaIKhHNt9HWeTfHqspdxtyMpyLbLQCY2 KFDA6XlNb/0lJDSE7F1rGSful7rz9Q93duDu+ds9CKYJuQ7j+j/FzxcQKsa9+pC4AWXn wugqtRtMfu7MhnGbZtk8FGpsj4RDcjL2NPxTKLkirl5xTnFDfMwoDtQfkXSK0jhyC2n0 HzSbtgRfG4CrsZLw1r06YOlifOBh6UrwFMFjvCyhjP8trjGZClAA41lRrgqjEEJ0D/mM GyCKeDouBDMhoQLdXwkESFb+QzVjt3nFEIunnuLSWTNVTt4DF+bmBtu1pVGjpXZQqwry 5PBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:message-id:date:subject:cc:to:from; bh=HeUGHEkJDFxg+o1MzYDka6+sl+WrrpWYLApr2db5h4Y=; b=fyQIR9VCxbZmYjPsCq8qcKJRwqrsVuT4m59GfCxQSHFRtutjExRdLBMf2U3XHGEOqD c74zsy/rd2m6nm1fKhBh219VMv4frV2aOgnxOhCNu+bYE2OBHOC2C+6j7Bmdxb/oiRxH 9n75sWRRUW13mbp+6/FXN7weCyxMCMrNAWZAn44Y7xckMi3S7IwXEwnmYYEdBB3h3DYO c3HoPM0MqN8kCdy1xwaVOCC3awcxhJFVUmfLV3xneak6hRv5MihUbXeMPiENFN8QcFJ1 5rqRU3BeJm+BwjbmkDmtmGRhWrxZWOIPOjDi2Ht78/jlCrf8Ry81lPIIDU21lbDp4TsA aKJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of houtao1@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=houtao1@huawei.com Received: from huawei.com (szxga04-in.huawei.com. [45.249.212.190]) by mx.google.com with ESMTPS id b8si6571641oia.213.2018.12.03.18.06.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 18:06:12 -0800 (PST) Received-SPF: pass (google.com: domain of houtao1@huawei.com designates 45.249.212.190 as permitted sender) client-ip=45.249.212.190; Authentication-Results: mx.google.com; spf=pass (google.com: domain of houtao1@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=houtao1@huawei.com Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 08819696980F0; Tue, 4 Dec 2018 10:05:38 +0800 (CST) Received: from huawei.com (10.90.53.225) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.408.0; Tue, 4 Dec 2018 10:05:33 +0800 From: Hou Tao To: CC: , , Subject: [PATCH] squashfs: enable __GFP_FS in ->readpage to prevent hang in mem alloc Date: Tue, 4 Dec 2018 10:08:40 +0800 Message-ID: <20181204020840.49576-1-houtao1@huawei.com> X-Mailer: git-send-email 2.16.2.dirty MIME-Version: 1.0 X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected 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: X-Virus-Scanned: ClamAV using ClamSMTP There is no need to disable __GFP_FS in ->readpage: * It's a read-only fs, so there will be no dirty/writeback page and there will be no deadlock against the caller's locked page * It just allocates one page, so compaction will not be invoked * It doesn't take any inode lock, so the reclamation of inode will be fine And no __GFP_FS may lead to hang in __alloc_pages_slowpath() if a squashfs page fault occurs in the context of a memory hogger, because the hogger will not be killed due to the logic in __alloc_pages_may_oom(). Signed-off-by: Hou Tao --- fs/squashfs/file.c | 3 ++- fs/squashfs/file_direct.c | 4 +++- fs/squashfs/squashfs_fs_f.h | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 fs/squashfs/squashfs_fs_f.h diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index f1c1430ae721..8603dda4a719 100644 --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c @@ -51,6 +51,7 @@ #include "squashfs_fs.h" #include "squashfs_fs_sb.h" #include "squashfs_fs_i.h" +#include "squashfs_fs_f.h" #include "squashfs.h" /* @@ -414,7 +415,7 @@ void squashfs_copy_cache(struct page *page, struct squashfs_cache_entry *buffer, TRACE("bytes %d, i %d, available_bytes %d\n", bytes, i, avail); push_page = (i == page->index) ? page : - grab_cache_page_nowait(page->mapping, i); + squashfs_grab_cache_page_nowait(page->mapping, i); if (!push_page) continue; diff --git a/fs/squashfs/file_direct.c b/fs/squashfs/file_direct.c index 80db1b86a27c..a0fdd6215348 100644 --- a/fs/squashfs/file_direct.c +++ b/fs/squashfs/file_direct.c @@ -17,6 +17,7 @@ #include "squashfs_fs.h" #include "squashfs_fs_sb.h" #include "squashfs_fs_i.h" +#include "squashfs_fs_f.h" #include "squashfs.h" #include "page_actor.h" @@ -60,7 +61,8 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize, /* Try to grab all the pages covered by the Squashfs block */ for (missing_pages = 0, i = 0, n = start_index; i < pages; i++, n++) { page[i] = (n == target_page->index) ? target_page : - grab_cache_page_nowait(target_page->mapping, n); + squashfs_grab_cache_page_nowait( + target_page->mapping, n); if (page[i] == NULL) { missing_pages++; diff --git a/fs/squashfs/squashfs_fs_f.h b/fs/squashfs/squashfs_fs_f.h new file mode 100644 index 000000000000..fc5fb7aeb27d --- /dev/null +++ b/fs/squashfs/squashfs_fs_f.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef SQUASHFS_FS_F +#define SQUASHFS_FS_F + +/* + * No need to use FGP_NOFS here: + * 1. It's a read-only fs, so there will be no dirty/writeback page and + * there will be no deadlock against the caller's locked page. + * 2. It just allocates one page, so compaction will not be invoked. + * 3. It doesn't take any inode lock, so the reclamation of inode + * will be fine. + * + * And GFP_NOFS may lead to infinite loop in __alloc_pages_slowpath() if a + * squashfs page fault occurs in the context of a memory hogger, because + * the hogger will not be killed due to the logic in __alloc_pages_may_oom(). + */ +static inline struct page * +squashfs_grab_cache_page_nowait(struct address_space *mapping, pgoff_t index) +{ + return pagecache_get_page(mapping, index, + FGP_LOCK|FGP_CREAT|FGP_NOWAIT, + mapping_gfp_mask(mapping)); +} +#endif +