From patchwork Mon Mar 18 09:15:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongsheng Yang X-Patchwork-Id: 10857005 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 CA5706C2 for ; Mon, 18 Mar 2019 09:23:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFDAE2922F for ; Mon, 18 Mar 2019 09:23:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2AAB29296; Mon, 18 Mar 2019 09:23:00 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B8F72922F for ; Mon, 18 Mar 2019 09:23:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727217AbfCRJW7 (ORCPT ); Mon, 18 Mar 2019 05:22:59 -0400 Received: from m97134.mail.qiye.163.com ([220.181.97.134]:50216 "EHLO m97134.mail.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726922AbfCRJW6 (ORCPT ); Mon, 18 Mar 2019 05:22:58 -0400 Received: from atest-guest.localdomain (unknown [218.94.118.90]) by smtp5 (Coremail) with SMTP id huCowABHr4m4YY9cO8zEAg--.331S3; Mon, 18 Mar 2019 17:15:37 +0800 (CST) From: Dongsheng Yang To: idryomov@gmail.com, jdillama@redhat.com, sage@redhat.com, elder@kernel.org Cc: ceph-devel@vger.kernel.org, Dongsheng Yang Subject: [PATCH v2 01/16] libceph: introduce ceph_extract_encoded_string_kvmalloc Date: Mon, 18 Mar 2019 05:15:19 -0400 Message-Id: <1552900534-29026-2-git-send-email-dongsheng.yang@easystack.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1552900534-29026-1-git-send-email-dongsheng.yang@easystack.cn> References: <1552900534-29026-1-git-send-email-dongsheng.yang@easystack.cn> X-CM-TRANSID: huCowABHr4m4YY9cO8zEAg--.331S3 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjfUpzuAUUUUU X-Originating-IP: [218.94.118.90] X-CM-SenderInfo: 5grqw2pkhqwhp1dqwq5hdv52pwdfyhdfq/1tbiHBl7elpchMQOTAAAsA Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When we are going to extract the encoded string, there would be a large string encoded. Especially in the journaling case, if we use the default journal object size, 16M, there could be a 16M string encoded in this object. Signed-off-by: Dongsheng Yang --- include/linux/ceph/decode.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/include/linux/ceph/decode.h b/include/linux/ceph/decode.h index a6c2a48..05dae1b 100644 --- a/include/linux/ceph/decode.h +++ b/include/linux/ceph/decode.h @@ -104,8 +104,11 @@ static inline bool ceph_has_room(void **p, void *end, size_t n) * beyond the "end" pointer provided (-ERANGE) * - memory could not be allocated for the result (-ENOMEM) */ -static inline char *ceph_extract_encoded_string(void **p, void *end, - size_t *lenp, gfp_t gfp) +typedef void * (mem_alloc_t)(size_t size, gfp_t flags); +extern void *ceph_kvmalloc(size_t size, gfp_t flags); +static inline char *extract_encoded_string(void **p, void *end, + mem_alloc_t alloc_fn, + size_t *lenp, gfp_t gfp) { u32 len; void *sp = *p; @@ -115,7 +118,7 @@ static inline char *ceph_extract_encoded_string(void **p, void *end, if (!ceph_has_room(&sp, end, len)) goto bad; - buf = kmalloc(len + 1, gfp); + buf = alloc_fn(len + 1, gfp); if (!buf) return ERR_PTR(-ENOMEM); @@ -133,6 +136,18 @@ static inline char *ceph_extract_encoded_string(void **p, void *end, return ERR_PTR(-ERANGE); } +static inline char *ceph_extract_encoded_string(void **p, void *end, + size_t *lenp, gfp_t gfp) +{ + return extract_encoded_string(p, end, kmalloc, lenp, gfp); +} + +static inline char *ceph_extract_encoded_string_kvmalloc(void **p, void *end, + size_t *lenp, gfp_t gfp) +{ + return extract_encoded_string(p, end, ceph_kvmalloc, lenp, gfp); +} + /* * skip helpers */