Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6529387ybi; Sun, 21 Jul 2019 20:16:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxQvZeYPHDQfDD4dM7UecG9wbL9eWcW1NSWi5Gat9Ab6IJ8cfL6F1e+sID23P/AXyuUYsBO X-Received: by 2002:a65:684c:: with SMTP id q12mr27709741pgt.405.1563765370339; Sun, 21 Jul 2019 20:16:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563765370; cv=none; d=google.com; s=arc-20160816; b=LRIJ2nnWtJ9WzrvK+uYVSRyP2Io9+BxgP+z9pI1xBtantQFt/1NS6HOLYkEbJBUx2C DtBimIjGzVnJxY+xtI+65q3oRfjt3tXFoDTtOfRg9vw0k2e3E1zN/kWRd3y7U146gjIR h4ATCpFhQtCxxRJuCou0GXYvzTcQPdSzPJ1YkhbvOpXeqPcM+IcIzix/PvgYNmqowdLK tq18XsJFtt/OPltymlD0DFyUBBx60LFDoZC+nEKmgz3hhxGde7gapWbclxOITZugH+wb yDTu0p4y/H+EuXoDyYfjwphX9qncKvD3V7AK1hviuCdp+YAT0lIY5FVF4VKsKkQfHs4D 5JKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=JlKaNBSihcWc8CJzAXugJLwia7xJ0/Jdbe2j9Myb9To=; b=0PqZLgopjqZ5CTb5GdJMqhDsfPA85jGPrnywEZ59fHyulMSLIE37Ti43vjG7AzxDEv zpHd1p+YtX+FlpwWb4kWRCynSigFHIaG7xssRZxXLsf/vCDmPIyDORGpv6XkQJaQ14dX 0mZ/Go2YNUZDCH84Xh4JWbyOlzwq0OaNK5WmGLatudd1+Do9eYyKNFHiROqoV0ky/OoY 2iqqqlZlppN1cuuuIon0zClcV0DGvJBwP5ryJoCl8iFAkThwpPu7Ve6khAD8YaUHhT13 ImlCbO1AAoX+80KL1gBljTBJm+eXN+QoyQTCqQAZX8SzyMmQXQm4LmDVuw4Pz1/BIpDN bO9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8si9023314plp.179.2019.07.21.20.15.54; Sun, 21 Jul 2019 20:16:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728941AbfGVCvg (ORCPT + 99 others); Sun, 21 Jul 2019 22:51:36 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:39106 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728886AbfGVCv1 (ORCPT ); Sun, 21 Jul 2019 22:51:27 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id EEA9D1EB6F46BBC47F4D; Mon, 22 Jul 2019 10:51:23 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.203) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 22 Jul 2019 10:51:16 +0800 From: Gao Xiang To: Alexander Viro , Greg Kroah-Hartman , Andrew Morton , Stephen Rothwell , Theodore Ts'o , "Linus Torvalds" CC: , , LKML , , Chao Yu , Miao Xie , Li Guifu , Fang Wei , Gao Xiang Subject: [PATCH v3 19/24] erofs: add erofs_allocpage() Date: Mon, 22 Jul 2019 10:50:38 +0800 Message-ID: <20190722025043.166344-20-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190722025043.166344-1-gaoxiang25@huawei.com> References: <20190722025043.166344-1-gaoxiang25@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces an temporary _on-stack_ page pool to reuse the freed page directly as much as it can for better performance and release all pages at a time, it also slightly reduces the possibility of the potential memory allocation failure. Signed-off-by: Gao Xiang --- fs/erofs/internal.h | 2 ++ fs/erofs/utils.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index dc5c6c5e4885..506a68efe507 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -495,6 +495,8 @@ int erofs_namei(struct inode *dir, struct qstr *name, extern const struct file_operations erofs_dir_fops; /* utils.c */ +struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp, bool nofail); + #if (EROFS_PCPUBUF_NR_PAGES > 0) void *erofs_get_pcpubuf(unsigned int pagenr); #define erofs_put_pcpubuf(buf) do { \ diff --git a/fs/erofs/utils.c b/fs/erofs/utils.c index c430790a02e0..53ee6daa3f70 100644 --- a/fs/erofs/utils.c +++ b/fs/erofs/utils.c @@ -9,6 +9,20 @@ #include "internal.h" #include +struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp, bool nofail) +{ + struct page *page; + + if (!list_empty(pool)) { + page = lru_to_page(pool); + DBG_BUGON(page_ref_count(page) != 1); + list_del(&page->lru); + } else { + page = alloc_pages(gfp | (nofail ? __GFP_NOFAIL : 0), 0); + } + return page; +} + #if (EROFS_PCPUBUF_NR_PAGES > 0) static struct { u8 data[PAGE_SIZE * EROFS_PCPUBUF_NR_PAGES]; -- 2.17.1