From patchwork Fri May 15 07:27:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangxu X-Patchwork-Id: 1290917 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Ng4y3tvDz9sTC for ; Fri, 15 May 2020 17:28:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EF39D39730A9; Fri, 15 May 2020 07:28:47 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from huawei.com (szxga06-in.huawei.com [45.249.212.32]) by sourceware.org (Postfix) with ESMTPS id D72703973056 for ; Fri, 15 May 2020 07:28:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D72703973056 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=wangxu72@huawei.com Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 7CBAB1E5658054C76DCA; Fri, 15 May 2020 15:28:19 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.188.167) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Fri, 15 May 2020 15:28:11 +0800 From: wangxu To: , , Subject: [PATCH] malloc: perturb mchunk returned from tcache like fast, small, large bin Date: Fri, 15 May 2020 15:27:57 +0800 Message-ID: <1589527677-38586-1-git-send-email-wangxu72@huawei.com> X-Mailer: git-send-email 1.8.5.6 MIME-Version: 1.0 X-Originating-IP: [10.67.188.167] X-CFilter-Loop: Reflected X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nixiaoming@huawei.com, wangle6@huawei.com, fw@deneb.enyo.de, libc-alpha@sourceware.org, cg.chen@huawei.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" From: Wang Xu mchunk returned from tcache donot have the chance to be perturbed like what from fastbin, smallbin and largebin. This patch perturbs the mchunk returned from tcache. Thanks Carlos O'Donell for comment. --- malloc/malloc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index e8abb4e..057e5ad 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -3108,7 +3108,9 @@ __libc_malloc (size_t bytes) && tcache && tcache->counts[tc_idx] > 0) { - return tcache_get (tc_idx); + void *p = tcache_get (tc_idx); + alloc_perturb (p, bytes); + return p; } DIAG_POP_NEEDS_COMMENT; #endif @@ -3963,7 +3965,9 @@ _int_malloc (mstate av, size_t bytes) && mp_.tcache_unsorted_limit > 0 && tcache_unsorted_count > mp_.tcache_unsorted_limit) { - return tcache_get (tc_idx); + void *p = tcache_get (tc_idx); + alloc_perturb (p, bytes); + return p; } #endif @@ -3976,7 +3980,9 @@ _int_malloc (mstate av, size_t bytes) /* If all the small chunks we found ended up cached, return one now. */ if (return_cached) { - return tcache_get (tc_idx); + void *p = tcache_get (tc_idx); + alloc_perturb (p, bytes); + return p; } #endif