From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753196AbdATUCE (ORCPT ); Fri, 20 Jan 2017 15:02:04 -0500 Received: from prod-mail-xrelay07.akamai.com ([23.79.238.175]:30008 "EHLO prod-mail-xrelay07.akamai.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752727AbdATUCD (ORCPT ); Fri, 20 Jan 2017 15:02:03 -0500 Subject: Re: [PATCH v2] jump_label: reduce the size of struct static_key To: Ingo Molnar References: <1483555303-13493-1-git-send-email-jbaron@akamai.com> <20170120071914.GA17003@gmail.com> Cc: peterz@infradead.org, rostedt@goodmis.org, linux-kernel@vger.kernel.org, Thomas Gleixner From: Jason Baron Message-ID: <3a319fba-f655-1025-5663-16d9d185e12f@akamai.com> Date: Fri, 20 Jan 2017 15:02:01 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <20170120071914.GA17003@gmail.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/20/2017 02:19 AM, Ingo Molnar wrote: > > * Jason Baron wrote: > >> struct static_key { >> atomic_t enabled; >> +/* >> + * bit 0 => 1 if key is initially true >> + * 0 if initially false >> + * bit 1 => 1 if points to struct static_key_mod >> + * 0 if points to struct jump_entry >> + */ >> + union { >> + unsigned long type; >> + struct jump_entry *entries; >> + struct static_key_mod *next; >> + }; > > >> + key->type = (unsigned long)jlm2 | static_key_type(key); > >> + key->type = (unsigned long)jlm | static_key_type(key); > >> + *prev = (struct static_key_mod *)((unsigned long)jlm->next | >> + ((unsigned long)*prev & JUMP_TYPE_MASK)); > >> + key->type = (unsigned long)jlm->entries | >> + static_key_type(key); > > I really hate these very ugly type conversions. Is there no cleaner way? > > For example the last line could sure be written as: > > key->entries = jlm->entries; > key->type |= static_key_type(key); > > right? Hi, So that is going to over-write the static_key_type(key) in the first assignment. If the order is reversed we can't just |= in the pointer type. How about: static void jump_key_set_entries(struct static_key *key, struct jump_entry *entries) { unsigned long type; type = static_key_type(key); key->entries = entries; key->type |= type; } and then we can also add: void jump_key_set_mod(struct static_key *key, struct static_key_mod *mod) doing basically the same thing. That will avoid the casts that you called out. better? Thanks, -Jason