Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp385516imm; Thu, 26 Jul 2018 05:29:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcr1ckabMdyJcAVOdsEI7I89rN4W4XnXXR9hEVIrkNIJEABK3aRsbbgAF3pHnOKK8jWtd44 X-Received: by 2002:a17:902:7c12:: with SMTP id x18-v6mr1791791pll.23.1532608164075; Thu, 26 Jul 2018 05:29:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532608164; cv=none; d=google.com; s=arc-20160816; b=WWogdkqyf/K8Kgd99WlwagtnUNPnZOgHjmQwSBq3fyUsQClVk5UcBStP+e7quX/9p0 kLmjL0pT4v9qSwEjPgJJugrzxwYCfXQp4Pl6TNM8bIqV96bBYKxiVamsyW95H/H2u5pu rnjHSL96AvYeOV5JBrdCeqLnwiZXVm2KzkGHJuRQO+UGfIvpMj/8WeluZ7uIR6ahaaxU u04WRh9VDt7WtlBEbmhpnGbq8jvWHz4V7C+lqiNRPTJaiJC7jl2eweDFWn2EOiK+uDjq wGRV/CdS70F9DZC0WDZNp22+Log4Rl14fYVHhcIRgKQFrLBlLvS6bXrPYaYU43DLLupg t/PA== 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:arc-authentication-results; bh=p6vMOOIEGajW/zQgBDOSHqApfA7uHZDas0RAweeRkyc=; b=bvKs3KxQBZ+O7vBM5UU6LOscrAt+pCEBHwHUTX2fAQjwIg2Cb5gRYOEDpYyzgCk8qf clkKJ0Y3vgzNzKq9yGj5tFF7E6KYMs7fx8B6vEE9UNNZknjTJudxcXvcZaxwufjm4r9X CshAcuce4DBKTd8z/jwE0TEeoNes1t0MH/+41Q+ulk4L1IN5eQCNmkYBT0LOgnYUXlMj +x7McUvTGPvQVV/FEiz9+I/ohrC5r8AEA2vphQJG8/qYEMfsNytcpL/lhEdzCeJDFCCo /LgdfAs19pXWhrbVp7vRG7O3dQ/iumSoYGUMo93ZNl/HW1yAZ2E6z5Pwh8Nxp0ud5Gz6 LDtQ== 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 e96-v6si1175040plb.447.2018.07.26.05.29.09; Thu, 26 Jul 2018 05:29:24 -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 S1731316AbeGZNni (ORCPT + 99 others); Thu, 26 Jul 2018 09:43:38 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:10133 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729514AbeGZNnh (ORCPT ); Thu, 26 Jul 2018 09:43:37 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 888577E414CEE; Thu, 26 Jul 2018 20:26:56 +0800 (CST) Received: from szvp000100637.huawei.com (10.162.55.131) by smtp.huawei.com (10.3.19.208) with Microsoft SMTP Server (TLS) id 14.3.382.0; Thu, 26 Jul 2018 20:26:48 +0800 From: Gao Xiang To: Greg Kroah-Hartman , CC: , , , , , , , , Gao Xiang Subject: [PATCH 16/25] staging: erofs: add erofs_allocpage Date: Thu, 26 Jul 2018 20:21:59 +0800 Message-ID: <1532607728-103372-17-git-send-email-gaoxiang25@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1532607728-103372-1-git-send-email-gaoxiang25@huawei.com> References: <1527764767-22190-1-git-send-email-gaoxiang25@huawei.com> <1532607728-103372-1-git-send-email-gaoxiang25@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.162.55.131] 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 --- drivers/staging/erofs/Makefile | 2 +- drivers/staging/erofs/internal.h | 7 +++++++ drivers/staging/erofs/utils.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/erofs/utils.c diff --git a/drivers/staging/erofs/Makefile b/drivers/staging/erofs/Makefile index 8558c76..490fa6c 100644 --- a/drivers/staging/erofs/Makefile +++ b/drivers/staging/erofs/Makefile @@ -7,7 +7,7 @@ ccflags-y += -Wall -DEROFS_VERSION=\"$(EROFS_VERSION)\" obj-$(CONFIG_EROFS_FS) += erofs.o # staging requirement: to be self-contained in its own directory ccflags-y += -I$(src)/include -erofs-objs := super.o inode.o data.o namei.o dir.o +erofs-objs := super.o inode.o data.o namei.o dir.o utils.o erofs-$(CONFIG_EROFS_FS_XATTR) += xattr.o erofs-$(CONFIG_EROFS_FS_ZIP) += unzip_vle.o diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h index bea5ec4..210ab6c 100644 --- a/drivers/staging/erofs/internal.h +++ b/drivers/staging/erofs/internal.h @@ -369,5 +369,12 @@ static inline void erofs_vunmap(const void *mem, unsigned int count) #endif } +/* utils.c */ +extern struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp); + +#ifndef lru_to_page +#define lru_to_page(head) (list_entry((head)->prev, struct page, lru)) +#endif + #endif diff --git a/drivers/staging/erofs/utils.c b/drivers/staging/erofs/utils.c new file mode 100644 index 0000000..3dec4f8 --- /dev/null +++ b/drivers/staging/erofs/utils.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * linux/drivers/staging/erofs/utils.c + * + * Copyright (C) 2018 HUAWEI, Inc. + * http://www.huawei.com/ + * Created by Gao Xiang + * + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file COPYING in the main directory of the Linux + * distribution for more details. + */ + +#include "internal.h" + +struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp) +{ + struct page *page; + + if (!list_empty(pool)) { + page = lru_to_page(pool); + list_del(&page->lru); + } else { + page = alloc_pages(gfp | __GFP_NOFAIL, 0); + + BUG_ON(page == NULL); + BUG_ON(page->mapping != NULL); + } + return page; +} + -- 1.9.1