From patchwork Fri Sep 29 16:48:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 23234 Received: (qmail 64363 invoked by alias); 29 Sep 2017 16:48:16 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 64222 invoked by uid 89); 29 Sep 2017 16:48:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1919 X-HELO: EUR02-VE1-obe.outbound.protection.outlook.com From: Wilco Dijkstra To: "libc-alpha@sourceware.org" , "dj@redhat.com" CC: nd Subject: [PATCH][malloc] Improve malloc initialization sequence Date: Fri, 29 Sep 2017 16:48:02 +0000 Message-ID: x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB6PR0801MB2054; 6:KjM+SWGmVTW/LNBPg1gSvtPgTfQEuzrgRkZWQS5cmh3cCLPQSVR1Vh0kn1sPSo5M2HQ+vjGPqUJpmiHAZ/1dotkx7R+rNrrkb6pm1asELfTmFiXPfAMMm9L+C89vGPw7ejTQaKLmPwsI32xFpGQs1hklTZ7guF2ag+EHjz9XxU69nCeUEfjdYg2FZ7XecCR0js5f28e+FW4aWDNw8w4IeKfmbwm9eMGyNRYugSoCKTzDX92hOBPkzmJTOqpGG2aAouOP6BL4G2DMPNtHIZnyckm+wMWNIwmYU2fvYgmhgRd8/n1d0q5fWfRSoYIBSzM0Cp+odWy42ALqGGK4mJSiSQ==; 5:NOjyvnyaQ+o+f34WhF/fAMyXCxL22katsyQmXeehsmB4x613OsbHHkokyzo2Rjyg9jwR+lwJZ9AKS+gc5ubm6WOfToONhN/l7xHhi9x8K3KLlm5sBwAY/6FU+ejcZsUW2wfPtYpVqldwu6wDeHHnjg==; 24:Tqa0MshSK5wxQyFPJmUWsvgr3PIR7Fc/LCNOCl61qy16GMiUwznOFBoHfSbF5F3VMU1oqLisYdX3uifrqoR8bki3zWFG+6UdFVSN53WusT0=; 7:rnmqDBMZY5po8Ph+9ffEZFxArOEhwVrfeGyxYNwNK9cIjIPQm78OtbvBU3M0eWTlBXf2wwKbZPhwMQ/+ygdyRlNMBoGlhGX68bOPQDGaV37XFTdpyYu9JEwDO83NDnGSMRrTqdJJoaDSpW5clABm1gmNn/pnVYf8evpLVV1iDj5hiLqAQ9wRPuCXhLHs6r5jHmpWyl7qFiB3YsS2TzIaBL0e1ngQunqBSD8yLQdwalw= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 37adf142-7ae5-4032-6f3b-08d50759d98e x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:DB6PR0801MB2054; x-ms-traffictypediagnostic: DB6PR0801MB2054: nodisclaimer: True x-exchange-antispam-report-test: UriScan:(180628864354917); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(3002001)(10201501046)(100000703101)(100105400095)(93006095)(93001095)(6055026)(6041248)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123555025)(20161123562025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB6PR0801MB2054; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB6PR0801MB2054; x-forefront-prvs: 0445A82F82 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(346002)(376002)(54534003)(377424004)(199003)(189002)(6436002)(86362001)(478600001)(6116002)(72206003)(5250100002)(66066001)(25786009)(4326008)(102836003)(3846002)(105586002)(33656002)(9686003)(106356001)(99286003)(55016002)(68736007)(6506006)(110136005)(8676002)(53936002)(2906002)(3280700002)(81156014)(101416001)(7696004)(8936002)(14454004)(2501003)(2900100001)(3660700001)(81166006)(5660300001)(54356999)(50986999)(305945005)(316002)(74316002)(97736004)(189998001)(7736002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0801MB2054; H:DB6PR0801MB2053.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Sep 2017 16:48:02.5486 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB2054 The current malloc initialization is quite convoluted. Instead of sometimes calling malloc_consolidate from ptmalloc_init, call malloc_init_state so that the main_arena is always initialized. The special initialization can now be removed from malloc_consolidate. GLIBC builds and tests pass, OK for commit? ChangeLog: 2017-09-29 Wilco Dijkstra * malloc/arena.c (ptmalloc_init): Call malloc_init_state. * malloc/malloc.c (malloc_consolidate): Remove initialization. diff --git a/malloc/arena.c b/malloc/arena.c index 9e5a62d260bf2f5e6d76da4ccaf7b7dcb388c296..628652c2d89ea092f7656d2ec4f3c405a39de886 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -312,7 +312,7 @@ ptmalloc_init (void) thread attempting to use the arena in parallel waits on us till we finish. */ __libc_lock_lock (main_arena.mutex); - malloc_consolidate (&main_arena); + malloc_init_state (&main_arena); TUNABLE_GET (check, int32_t, TUNABLE_CALLBACK (set_mallopt_check)); TUNABLE_GET (top_pad, size_t, TUNABLE_CALLBACK (set_top_pad)); @@ -392,6 +392,7 @@ ptmalloc_init (void) } } } + malloc_init_state (&main_arena); if (s && s[0] != '\0' && s[0] != '0') __malloc_check_init (); #endif diff --git a/malloc/malloc.c b/malloc/malloc.c index 88cfd25766eba6787faeb7195d95b73d7a4637ab..162e423e7bd18a07e4e97dc618be406d8bc9c529 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -4410,12 +4410,7 @@ static void malloc_consolidate(mstate av) mchunkptr bck; mchunkptr fwd; - /* - If max_fast is 0, we know that av hasn't - yet been initialized, in which case do so below - */ - - if (get_max_fast () != 0) { + { atomic_store_relaxed (&av->have_fastchunks, false); unsorted_bin = unsorted_chunks(av); @@ -4484,10 +4479,6 @@ static void malloc_consolidate(mstate av) } } while (fb++ != maxfb); } - else { - malloc_init_state(av); - check_malloc_state(av); - } } /*