Received: by 10.223.185.116 with SMTP id b49csp1594417wrg; Wed, 21 Feb 2018 23:08:36 -0800 (PST) X-Google-Smtp-Source: AH8x225qmld1+1BmUkWL2C6tYRFudz+4+Wksio3nCNW9LM5W0CgeU8R61T0kH+NCaR4xEna4XE8e X-Received: by 10.98.100.131 with SMTP id y125mr5936913pfb.117.1519283316759; Wed, 21 Feb 2018 23:08:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519283316; cv=none; d=google.com; s=arc-20160816; b=Cis/oi9ZwbrpaNRHFoxhPisUI64CNZwcTYTr1zACoLijHLCaZjSQK+v1CIqopweiRz ygUQzD57GZIKHQEt1z5j/Htha/UlmdbD7lfkVVQbKig0JOimoTGC3o6eW2GjLdsk5sy1 Cbg/1giK/5kCFgbRSqsxy3nQ4wwm1CeuC9Z7cZL6U8sGhBFpMV07qUsPEhkn8yn0vqyq CsP5+Ly6iP1NwGiZp+Me6hhVprWRRMyR67U845l/4ey7yyDDslOSZ7LMSlZkqLNxBubU tZHGHQ2n4XAocbV48iDJwJJUrsytd4cEcWPhmJZXyz/N18NR58BQ8b5R0/873w+/+bGn 9LRA== 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:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=M887nSKhOiDvj0ASkuD0C5oVhXRDA2YP2fzp1OW16as=; b=NiGSfOJnx3gDcChfqZ3cTckDug9azn9bvH3b7TZDTDPNvSbgAFL+TokC/86bTiXJYg mW3T6LmZntYYMfAFg6aT2hnhBoBJC0pnsJyiWgXqTc4M2qdJl0Nl6ibucQ5MQ3BoSyV+ o30AlfhYEFfOE9/4pqdvB6w3rZpvttt4BC+PfGlUjRhky6cmKvUwzIT2QK2KUvBH67pA ekAgxGwY+72g6CHfdBpPUy/rtjb0NoUgOYLwYB8LfrNBvfy/XMLAzQmSVL+HqFyzEdMm 12SVodMENODxVoWwy5RpEkjRwWt5k6eln+XIXj2GpINlXZ+j7/QSY1SgVKYGudQ3Pz6N KFJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Z28PGCal; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k33-v6si2860806pld.303.2018.02.21.23.08.22; Wed, 21 Feb 2018 23:08:36 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Z28PGCal; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752805AbeBVHG5 (ORCPT + 99 others); Thu, 22 Feb 2018 02:06:57 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34999 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752728AbeBVHGy (ORCPT ); Thu, 22 Feb 2018 02:06:54 -0500 Received: by mail-wm0-f68.google.com with SMTP id x21so1715034wmh.0 for ; Wed, 21 Feb 2018 23:06:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=M887nSKhOiDvj0ASkuD0C5oVhXRDA2YP2fzp1OW16as=; b=Z28PGCalSqbUcW71b8ZTCUtqnMCGb51ONnWKU6MwaYHRpRt1WdNV4z+SqPUYEySUmx byueU+MZLKsNznAShWxbP3Ikl5TUDf/QIgmSsd+E6lT/aElMEGNB8eINUgMUSD9W78UF FIXtnvwaB+/NE7kGS+mkLqa2oqAmwch4IJTPHRgn/EHb12O+bu3/7bKvaLpc3qNXI+q1 6/7kbyUeX6S/hIgqy5pACohxMO3A2tD/FGeC3oS5flBkSBXIRNfMcAq5GPpQMZBhnP6D 2pcxvBSJ0tCkXEnbMa3qu/CePQTsvKIw3K155ihN0aEMqhcsgZhQKakPyw0rP2qk4Gaz 63uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=M887nSKhOiDvj0ASkuD0C5oVhXRDA2YP2fzp1OW16as=; b=VpU3Vp/pzQwuKLW0xVaNF7xbqEAJzBE8zw2kGx1AHC4Utxmmcu9E04T/sR5iNe5i5I PwDvRL4CbwjQVV8p06KPUAUhdH264o0Uem3iCQ7xSX651Dd15JlQ9vOLV3wWYCvhujxu GDZJYnXsLi2SLI+s+88isRn5XgIwOInw+qcKaYD0n7P5OF67jvJkMIunTYaCj14H4kDj V5AAKsmhZU4ENPtmtn3A+wtBYQI7Q7qg52wpOW7F/ViWpUnJnXsN5aeeO+wPhcvcBAMM FkeNzpB5yv//okcEcug3qa03zVDC+1nE/b51UP4QxiZdEvuFxZ8RLk8dfBJy/fyigNCc FokA== X-Gm-Message-State: APf1xPBLF80DAY4vElho6EGIbjVML8DxN5+SPu86DWYRmde73TSvos+n IVTEinoIglVlc0yafhnVCrE= X-Received: by 10.80.181.112 with SMTP id z45mr8047703edd.223.1519283213200; Wed, 21 Feb 2018 23:06:53 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id t19sm5575447edh.22.2018.02.21.23.06.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 23:06:52 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id E454C20505; Thu, 22 Feb 2018 02:06:50 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Thu, 22 Feb 2018 02:06:50 -0500 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id 664787E371; Thu, 22 Feb 2018 02:06:50 -0500 (EST) From: Boqun Feng To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Ingo Molnar , Andrea Parri , Boqun Feng Subject: [RFC tip/locking/lockdep v5 15/17] lockdep: Reduce the size of lock_list Date: Thu, 22 Feb 2018 15:09:02 +0800 Message-Id: <20180222070904.548-16-boqun.feng@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180222070904.548-1-boqun.feng@gmail.com> References: <20180222070904.548-1-boqun.feng@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We actually only need 4 bits for lock_list::dep and 1 bit for lock_list::is_rr, besides lock_list::distance should always be no greater than MAX_LOCKDEP_DEPTH(which is 48 right now), so a u16 will fit, this patch then reduces the sizes of those fields to save space for lock_list structure, as a result we can reduce the size increment introduced by recursive read lock detection and keep the lock_list the same size as before. Suggested-by: Peter Zijlstra Signed-off-by: Boqun Feng --- include/linux/lockdep.h | 6 +++--- kernel/locking/lockdep.c | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index a1f91f8680bd..3fce8dbf5091 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -186,11 +186,11 @@ struct lock_list { struct list_head entry; struct lock_class *class; struct stack_trace trace; - int distance; + u16 distance; /* bitmap of different dependencies from head to this */ - u16 dep; + u8 dep; /* used by BFS to record whether this is picked as a recursive read */ - u16 is_rr; + bool is_rr; /* * The parent field is used to implement breadth-first search, and the diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 1b981dc4c061..e8b83b36669c 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -874,7 +874,7 @@ static struct lock_list *alloc_list_entry(void) * Add a new dependency to the head of the list: */ static int add_lock_to_list(struct lock_class *this, struct list_head *head, - unsigned long ip, int distance, unsigned int dep, + unsigned long ip, u16 distance, unsigned int dep, struct stack_trace *trace) { struct lock_list *entry; @@ -1063,7 +1063,7 @@ static inline unsigned int calc_dep(int prev, int next) * N: non-recursive lock * R: recursive read lock */ -static inline int pick_dep(u16 is_rr, u16 cap_dep) +static inline int pick_dep(bool is_rr, u8 cap_dep) { if (is_rr) { /* could only pick -(N*)-> */ if (cap_dep & DEP_NN_MASK) @@ -1148,7 +1148,8 @@ static enum bfs_result __bfs(struct lock_list *source_entry, struct list_head *head; struct circular_queue *cq = &lock_cq; enum bfs_result ret = BFS_RNOMATCH; - int is_rr, next_is_rr; + bool is_rr; + int next_is_rr; if (match(source_entry, data)) { *target_entry = source_entry; @@ -1204,7 +1205,7 @@ static enum bfs_result __bfs(struct lock_list *source_entry, next_is_rr = pick_dep(is_rr, entry->dep); if (next_is_rr < 0) continue; - entry->is_rr = next_is_rr; + entry->is_rr = !!next_is_rr; visit_lock_entry(entry, lock); if (match(entry, data)) { @@ -2153,7 +2154,7 @@ check_prevs_add(struct task_struct *curr, struct held_lock *next) goto out_bug; for (;;) { - int distance = curr->lockdep_depth - depth + 1; + u16 distance = curr->lockdep_depth - depth + 1; hlock = curr->held_locks + depth - 1; if (hlock->check) { -- 2.16.1