Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2659047ybb; Sat, 30 Mar 2019 10:21:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwr10plUUU95m/3zeR3zo3dbGKtiTVekAzZzbHGMmg+6E0ZXP0+3ZUmujIJsCp2Gi75LpPX X-Received: by 2002:a65:610a:: with SMTP id z10mr20884789pgu.23.1553966467967; Sat, 30 Mar 2019 10:21:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553966467; cv=none; d=google.com; s=arc-20160816; b=flIjcSithYNSEimF0noB1/HOQce9dIIN+QmrSdxR2rAxx5Y3kZG+tvpjlfzJ+i08lp RMG2LNMvDd7y2wkJdbdRbXWmgCyGO4x27LLr0onSacdONguwPsRdpOsGUJRIlTGh8y+C ib/SvS4g2KKzcnubCgTw1D2MT6lOMk/E+XicBoVpXLiUGnRnHUetY1GeUnZjlTVagRSV NHB38yV9KxeoOJBf9DxIi7p3M/Ji3lXU7zLcY2P1ozhzggNGKWnA4+aGr3Ky+dVnTeZ+ FIVtYJexVT+AgbYAJAS9kPW0tIT9tN4uet7EbMBCLNkA1UgsCiYK2YKnVnqmaiVm0wXo UZxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:cc:subject:to :message-id:from:date; bh=Nkf5hzeM0VJmq6YQc1TwGw33hhvN5NUHnjfmiKSJtfY=; b=c0xJotQed5ytY4DgCxi/05WBcyzQBx4vMjlqIStyJylOVYuPT4DnQVkqX2otHZl8OU dlayspDL7UsFEf0hAFiK5kCmRhda/71uWEog4cX90w9WbrixQtTsXQnOSyl+VAy9VBHE 2PQqGuC/zMiGvwajQlN34g1+HNe55EnCAaAs3Y88vqlsJOu4bGEaMq6HKKukbbwtiRHa r4RfmJMFlveOS6DhUS8ihXq1LbgmBHDhL8bFGsaqC0HOZxeRQbLOjj2dIKG+STMkO5Et 1J9rwDojIJgscGrDsMnwnRBtBoey2tjUBU7Uf8anu+xhT/8gHXdNYyOeVnXLPvCEpsp/ TjFQ== 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 k20si4487597pfk.55.2019.03.30.10.20.52; Sat, 30 Mar 2019 10:21:07 -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 S1730788AbfC3RTh (ORCPT + 99 others); Sat, 30 Mar 2019 13:19:37 -0400 Received: from mx.sdf.org ([205.166.94.20]:59852 "EHLO mx.sdf.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730215AbfC3RTg (ORCPT ); Sat, 30 Mar 2019 13:19:36 -0400 Received: from sdf.org (IDENT:lkml@sdf.lonestar.org [205.166.94.16]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id x2UHG5GI011346 (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits) verified NO); Sat, 30 Mar 2019 17:16:06 GMT Received: (from lkml@localhost) by sdf.org (8.15.2/8.12.8/Submit) id x2UHG23t020732; Sat, 30 Mar 2019 17:16:02 GMT Date: Sat, 30 Mar 2019 17:16:02 GMT From: George Spelvin Message-Id: <201903301716.x2UHG23t020732@sdf.org> To: adrian.hunter@intel.com, ard.biesheuvel@linaro.org, benh@kernel.crashing.org, bp@alien8.de, darrick.wong@oracle.com, dchinner@redhat.com, dedekind1@gmail.com, gregkh@linuxfoundation.org, hpa@zytor.com, jlbec@evilplan.org, jpoimboe@redhat.com, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-snps-arc@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, lkml@sdf.org, mark@fasheh.com, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.vnet.ibm.com, ocfs2-devel@oss.oracle.com, paulus@samba.org, richard@nod.at, sfr@canb.auug.org.au, st5pub@yandex.ru, tglx@linutronix.de, vgupta@synopsys.com, x86@kernel.org Subject: Re: [PATCH 0/5] simple sort swap function usage improvements Cc: akpm@linux-foundation.org, amir73il@gmail.com, andriy.shevchenko@linux.intel.com, ashish.samant@oracle.com, ge.changwei@h3c.com, gustavo@embeddedor.com, jannh@google.com, jiang.biao2@zte.com.cn, jiangyiwen@huawei.com, jslaby@suse.cz, kamalesh@linux.vnet.ibm.com, keescook@chromium.org, lchen@suse.com, linux@rasmusvillemoes.dk, malat@debian.org, mhocko@suse.com, npiggin@gmail.com, peterz@infradead.org, piaojun@huawei.com, rppt@linux.ibm.com, yamada.masahiro@socionext.com, yuehaibing@huawei.com In-Reply-To: <18626931553963861@sas1-b3ec53dbc12b.qloud-c.yandex.net> References: <18626931553963861@sas1-b3ec53dbc12b.qloud-c.yandex.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Great work; that is indeed a logical follow-on. Reviewed by: George Spelvin I you feel even more ambitious, you could try impementing Rasmus Villemoes' idea of having generic *compare* functions. (It's on my to-do list, but I haven't made meaningful progress yet, and I'm happy to pawn it off.) A significant fraction of the time, the sort key is a 4- or 8-byte integer field in a structure at a small offset from the base or list_head. A function pointer < 4096 could be interpreted as encoding: - Key size (1 bit) - Key signedness (1 bit) - Sort direction (1 bit) - Offset (9 bits; +/-256 words = +/-1024 bytes, or 0..511 words from start) With the correct level of preprocessor hackery, SIMPLE_CMP_ASCENDING(struct type, key_field) SIMPLE_LIST_CMP_ASCENDING(struct type, list_field, key_field) SIMPLE_CMP_DESCENDING(struct type, key_field) SIMPLE_LIST_CMP_DESCENDING(struct type, list_field, key_field) could encode all that and cause a compile-time error if the key is the wrong type or the offset is out of range.